parent
57b5f38c80
commit
38f02bb20b
57
buffer.py
57
buffer.py
|
@ -395,24 +395,6 @@ class ConsoleBuffer(Buffer):
|
|||
def readonly(self):
|
||||
return True
|
||||
|
||||
class ConsoleBuffer(Buffer):
|
||||
btype = 'shell'
|
||||
modename = 'shell'
|
||||
def __init__(self):
|
||||
Buffer.__init__(self)
|
||||
self.clear()
|
||||
def clear(self):
|
||||
lines = ['Shell\n']
|
||||
self.set_data(''.join(lines), force=True)
|
||||
def name(self):
|
||||
return '*Shell*'
|
||||
def changed(self):
|
||||
return False
|
||||
def close(self):
|
||||
pass
|
||||
def readonly(self):
|
||||
return True
|
||||
|
||||
class InterpreterPipeError(Exception):
|
||||
pass
|
||||
|
||||
|
@ -846,10 +828,17 @@ class ColorHighlighter(highlight.Highlighter):
|
|||
t = lex.Token('color_data', None, y, x, s2, color)
|
||||
self.tokens[y].append(t)
|
||||
return len(s) - len(s2)
|
||||
def delete_token(self, y, i):
|
||||
pass
|
||||
def relex(self, lines, y1, x1, y2, x2, token=None):
|
||||
pass
|
||||
def relex_del(self, lines, y1, x1, y2, x2):
|
||||
pass
|
||||
def highlight(self, lines):
|
||||
if self.tokens:
|
||||
return
|
||||
self.tokens = [None] * len(lines)
|
||||
self.tokens = [[] for l in lines]
|
||||
#self.tokens = [None] * len(lines)
|
||||
for y in range(0, len(lines)):
|
||||
self.tokens[y] = []
|
||||
line = lines[y]
|
||||
|
@ -874,17 +863,21 @@ class ColorDataBuffer(DataBuffer):
|
|||
btype = 'colordata'
|
||||
modename = 'colortext'
|
||||
color_re = re.compile(r'\[([a-z:]+)\]')
|
||||
def __init__(self, name, data):
|
||||
def _highlight(self, data):
|
||||
data2 = ColorHighlighter.color_re.sub('', data)
|
||||
data2 = data2.replace('\\[', '[')
|
||||
data2 = data2.replace('\\]', ']')
|
||||
data2 = data2.replace('\\\\', '\\')
|
||||
DataBuffer.__init__(self, name, data2)
|
||||
Buffer.set_data(self, data2, force=True)
|
||||
lines = data.split(self.nl)
|
||||
self.highlights = {
|
||||
'Colortext': ColorHighlighter(),
|
||||
}
|
||||
self.highlights = {'Colortext': ColorHighlighter()}
|
||||
self.highlights['Colortext'].highlight(lines)
|
||||
self.modified = False
|
||||
def __init__(self, name, data):
|
||||
DataBuffer.__init__(self, name, '')
|
||||
self._highlight(data)
|
||||
def set_data(self, data, force=True):
|
||||
self._highlight(data)
|
||||
|
||||
ABOUT_DATA = '''
|
||||
[r:d:*]===============================================================================
|
||||
|
@ -909,3 +902,19 @@ ABOUT_DATA = '''
|
|||
class AboutBuffer(ColorDataBuffer):
|
||||
def __init__(self):
|
||||
ColorDataBuffer.__init__(self, '*About*', ABOUT_DATA)
|
||||
|
||||
class ShellBuffer(ColorDataBuffer):
|
||||
btype = 'shell'
|
||||
intro = '[red:default:bold]Welcome to Hell[default:default]\n'
|
||||
def __init__(self):
|
||||
ColorDataBuffer.__init__(self, '*XYZ*', self.intro)
|
||||
def clear(self):
|
||||
self.set_data(self.intro, force=True)
|
||||
def name(self):
|
||||
return '*Shell*'
|
||||
def changed(self):
|
||||
return False
|
||||
def close(self):
|
||||
pass
|
||||
def readonly(self):
|
||||
return True
|
||||
|
|
|
@ -324,6 +324,7 @@ class Fundamental(Handler):
|
|||
self.window.set_error(err)
|
||||
|
||||
def region_added(self, p, newlines):
|
||||
mname = self.name()
|
||||
if self.lexer is not None:
|
||||
ydelta = len(newlines) - 1
|
||||
xdelta = len(newlines[-1])
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import code, os, re, string, StringIO, sys, traceback
|
||||
import color, completer, lex, method, mode
|
||||
import buffer, color, completer, lex, method, mode, window
|
||||
from lex import Grammar, PatternRule
|
||||
from mode.sh import ShGrammar
|
||||
from point import Point
|
||||
|
@ -11,6 +11,12 @@ PAD = ''
|
|||
LIMIT = 79
|
||||
|
||||
class ShellExec(Method):
|
||||
sequences = {
|
||||
'\x1b[01;32m': "[green:default]",
|
||||
'\x1b[01;34m': "[blue:default]",
|
||||
'\x1b[01;36m': "[cyan:default]",
|
||||
'\x1b[0m': "[default:default]",
|
||||
}
|
||||
def _execute(self, w, **vargs):
|
||||
a = w.application
|
||||
if a.completion_window_is_open():
|
||||
|
@ -40,8 +46,19 @@ class ShellExec(Method):
|
|||
output = p.stdout.read()
|
||||
output2 = []
|
||||
i = 0
|
||||
escaped = []
|
||||
for c in output:
|
||||
if c == '\n':
|
||||
if escaped:
|
||||
escaped.append(c)
|
||||
if c == 'm':
|
||||
seq = ''.join(escaped)
|
||||
if seq in self.sequences:
|
||||
#output2.append(self.sequences[seq])
|
||||
output2.append('{foo:bar}')
|
||||
escaped = []
|
||||
elif c == '\x1b':
|
||||
escaped.append(c)
|
||||
elif c == '\n':
|
||||
output2.append(c)
|
||||
i = 0
|
||||
elif c == '\t':
|
||||
|
@ -69,6 +86,11 @@ class ShellExec(Method):
|
|||
if output:
|
||||
newlines = []
|
||||
for line in output.split('\n'):
|
||||
line = line.replace('\x1b[01;32m', "[green:default]")
|
||||
line = line.replace('\x1b[01;34m', "[blue:default]")
|
||||
line = line.replace('\x1b[01;36m', "[cyan:default]")
|
||||
line = line.replace('\x1b[0m', "[default:default]")
|
||||
#line = repr(line)
|
||||
i = 0
|
||||
while i + limit < len(line):
|
||||
j = limit
|
||||
|
@ -81,9 +103,11 @@ class ShellExec(Method):
|
|||
newlines.append(PAD + line[i:i + j])
|
||||
i += j + 1
|
||||
newlines.append(PAD + line[i:])
|
||||
assert newlines[-1] == PAD
|
||||
#assert newlines[-1] == PAD
|
||||
newlines[-1] = ''
|
||||
b.insert_lines(b.get_buffer_end(), newlines, force=True)
|
||||
#b.insert_lines(b.get_buffer_end(), newlines, force=True)
|
||||
#b.set_lines(newlines, force=True)
|
||||
b.set_data("\n".join(newlines))
|
||||
for w2 in b.windows:
|
||||
w2.goto_end(force=True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue