branch : pmacs2
This commit is contained in:
moculus 2008-09-12 14:43:15 +00:00
parent 57b5f38c80
commit 38f02bb20b
4 changed files with 64 additions and 30 deletions

View File

@ -395,24 +395,6 @@ class ConsoleBuffer(Buffer):
def readonly(self): def readonly(self):
return True 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): class InterpreterPipeError(Exception):
pass pass
@ -846,10 +828,17 @@ class ColorHighlighter(highlight.Highlighter):
t = lex.Token('color_data', None, y, x, s2, color) t = lex.Token('color_data', None, y, x, s2, color)
self.tokens[y].append(t) self.tokens[y].append(t)
return len(s) - len(s2) 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): def highlight(self, lines):
if self.tokens: if self.tokens:
return return
self.tokens = [None] * len(lines) self.tokens = [[] for l in lines]
#self.tokens = [None] * len(lines)
for y in range(0, len(lines)): for y in range(0, len(lines)):
self.tokens[y] = [] self.tokens[y] = []
line = lines[y] line = lines[y]
@ -874,18 +863,22 @@ class ColorDataBuffer(DataBuffer):
btype = 'colordata' btype = 'colordata'
modename = 'colortext' modename = 'colortext'
color_re = re.compile(r'\[([a-z:]+)\]') color_re = re.compile(r'\[([a-z:]+)\]')
def __init__(self, name, data): def _highlight(self, data):
data2 = ColorHighlighter.color_re.sub('', data) data2 = ColorHighlighter.color_re.sub('', data)
data2 = data2.replace('\\[', '[') data2 = data2.replace('\\[', '[')
data2 = data2.replace('\\]', ']') 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) lines = data.split(self.nl)
self.highlights = { self.highlights = {'Colortext': ColorHighlighter()}
'Colortext': ColorHighlighter(),
}
self.highlights['Colortext'].highlight(lines) 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 = ''' ABOUT_DATA = '''
[r:d:*]=============================================================================== [r:d:*]===============================================================================
@ -909,3 +902,19 @@ ABOUT_DATA = '''
class AboutBuffer(ColorDataBuffer): class AboutBuffer(ColorDataBuffer):
def __init__(self): def __init__(self):
ColorDataBuffer.__init__(self, '*About*', ABOUT_DATA) 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

View File

@ -84,7 +84,7 @@ class Highlighter(object):
y += 1 y += 1
def highlight(self, lines): def highlight(self, lines):
self.tokens = [[] for l in lines] self.tokens = [[] for l in lines]
for token in self.lexer.lex(lines, y=0, x=0): for token in self.lexer.lex(lines, y=0, x=0):
self.tokens[token.y].append(token) self.tokens[token.y].append(token)

View File

@ -324,6 +324,7 @@ class Fundamental(Handler):
self.window.set_error(err) self.window.set_error(err)
def region_added(self, p, newlines): def region_added(self, p, newlines):
mname = self.name()
if self.lexer is not None: if self.lexer is not None:
ydelta = len(newlines) - 1 ydelta = len(newlines) - 1
xdelta = len(newlines[-1]) xdelta = len(newlines[-1])

View File

@ -1,5 +1,5 @@
import code, os, re, string, StringIO, sys, traceback 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 lex import Grammar, PatternRule
from mode.sh import ShGrammar from mode.sh import ShGrammar
from point import Point from point import Point
@ -11,6 +11,12 @@ PAD = ''
LIMIT = 79 LIMIT = 79
class ShellExec(Method): 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): def _execute(self, w, **vargs):
a = w.application a = w.application
if a.completion_window_is_open(): if a.completion_window_is_open():
@ -40,8 +46,19 @@ class ShellExec(Method):
output = p.stdout.read() output = p.stdout.read()
output2 = [] output2 = []
i = 0 i = 0
escaped = []
for c in output: 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) output2.append(c)
i = 0 i = 0
elif c == '\t': elif c == '\t':
@ -69,6 +86,11 @@ class ShellExec(Method):
if output: if output:
newlines = [] newlines = []
for line in output.split('\n'): 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 i = 0
while i + limit < len(line): while i + limit < len(line):
j = limit j = limit
@ -81,9 +103,11 @@ class ShellExec(Method):
newlines.append(PAD + line[i:i + j]) newlines.append(PAD + line[i:i + j])
i += j + 1 i += j + 1
newlines.append(PAD + line[i:]) newlines.append(PAD + line[i:])
assert newlines[-1] == PAD #assert newlines[-1] == PAD
newlines[-1] = '' 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: for w2 in b.windows:
w2.goto_end(force=True) w2.goto_end(force=True)