Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownuser88 committed Feb 3, 2017
1 parent 63fea32 commit 7c0a44e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
20 changes: 18 additions & 2 deletions README.md
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.



---
45 changes: 45 additions & 0 deletions htoint.py
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


Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7c0a44e

Please sign in to comment.