better hex

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-04-10 15:20:57 +00:00
parent cc050512c8
commit b2a8497c7b
2 changed files with 34 additions and 15 deletions

View File

@ -523,10 +523,37 @@ class Binary32Buffer(FileBuffer):
def __init__(self, path, nl='\n', name=None):
'''fb = FileBuffer(path)'''
FileBuffer.__init__(self, path, nl, name)
def cursorx_to_datax(self, cx):
if cx >= 0 and cx < 8:
return cx // 2
elif cx >= 9 and cx < 17:
return (cx - 1) // 2
elif cx >= 18 and cx < 26:
return (cx - 2) // 2
elif cx >= 27 and cx < 35:
return (cx - 3) // 2
else:
return None
def datax_to_cursorx(self, ix):
if ix >= 0 and ix < 4:
return ix * 2
elif ix >= 4 and ix < 8:
return ix * 2 + 1
elif ix >= 8 and ix < 12:
return ix * 2 + 2
elif ix >= 12 and ix < 16:
return ix * 2 + 3
else:
return None
def overwrite_char(self, p, c, act=ACT_NORM, force=False):
ix = self.cursorx_to_datax(p.x)
if ix is None:
return
Buffer.overwrite_char(self, p, c, act, force)
cx = self.datax_to_cursorx(ix)
c = chr(int(self.lines[p.y][cx:cx + 2], 16))
rawline = self.rawdata[p.y]
self.rawdata[p.y] = rawline[0:p.x] + c + rawline[p.x + 1:]
self.rawdata[p.y] = rawline[0:ix] + c + rawline[ix + 1:]
def read_filter(self, data):
self.rawdata = []
lines = []

View File

@ -50,21 +50,13 @@ class Hex(mode.Fundamental):
(cx, cy) = self.window.cursor.xy()
s = string.translate(self.window.buffer.rawdata[y], self.ctrans)
if cy == y:
i = None
if cx >= 0 and cx < 8:
i = cx // 2
elif cx >= 9 and cx < 17:
i = (cx - 1) // 2
elif cx >= 18 and cx < 26:
i = (cx - 2) // 2
elif cx >= 27 and cx < 35:
i = (cx - 3) // 2
if i is not None:
return ((0, s[0:i], color.build('green', 'default', 'bold')),
(0, s[i], color.build('green', 'default', 'bold', 'reverse')),
(0, s[i+1:], color.build('green', 'default', 'bold')))
else:
i = self.window.buffer.cursorx_to_datax(cx)
if i is None:
return ((0, s, color.build('green', 'default', 'bold')),)
else:
return ((0, s[0:i], color.build('green', 'default', 'bold')),
(i, s[i], color.build('default', 'default', 'bold', 'reverse')),
(i + 1, s[i+1:], color.build('green', 'default', 'bold')))
else:
return ((0, s, color.build('green', 'default', 'bold')),)