-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63fea32
commit 7c0a44e
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# hex2int | ||
sublime text plugin | ||
hex2int | ||
================ | ||
|
||
## Summary | ||
This plugin show int value of hex in statusbar (just put cursor on hex value) | ||
|
||
## Screenshot | ||
![ScreenShot](https://raw.github.com/unknownuser88/hex2int/master/screenshot.png) | ||
|
||
## Install | ||
|
||
#### Git Clone | ||
Clone this repository in to the Sublime Text "Packages" directory, which is located where ever the | ||
"Preferences" -> "Browse Packages" option in sublime takes you. | ||
|
||
|
||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sublime, sublime_plugin, re | ||
|
||
class HtointCommand(sublime_plugin.EventListener): | ||
def on_new(self, view): | ||
self.view = view | ||
self.run() | ||
|
||
def on_close(self, view): | ||
self.view.erase_status('Hexcode') | ||
|
||
def on_selection_modified(self, view): | ||
self.view = view | ||
self.run() | ||
|
||
def on_activated(self, view): | ||
self.view = view | ||
self.run() | ||
|
||
def run(self): | ||
statusline = [] | ||
for region in self.view.sel(): | ||
if region.begin() == region.end(): | ||
word = self.view.word(region) | ||
else: | ||
word = region | ||
if not word.empty(): | ||
keyword = self.view.substr(word) | ||
isHex = re.findall(r'0x[0-9a-fA-F]+', keyword) | ||
# print(isHex) | ||
if isHex: | ||
statusline.append('{} -> {}'.format(isHex[0], self.str_to_int(isHex[0]))) | ||
else: | ||
self.view.erase_status('Hexcode') | ||
else: | ||
self.view.erase_status('Hexcode') | ||
# print(", ".join(statusline)) | ||
self.view.set_status('Hexcode', '{}'.format(", ".join(statusline))) | ||
|
||
def str_to_int(self, s): | ||
i = int(s, 16) | ||
if i >= 2**23: | ||
i -= 2**24 | ||
return i | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.