diff --git a/buffer.py b/buffer.py index e0fa0b2..76a6b68 100644 --- a/buffer.py +++ b/buffer.py @@ -903,18 +903,19 @@ 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' +class ShellBuffer(Buffer): + btype = 'shell' + modename = 'shell' def __init__(self): - ColorDataBuffer.__init__(self, '*XYZ*', self.intro) + Buffer.__init__(self) + self.clear() def clear(self): - self.set_data(self.intro, force=True) + lines = ['=== Shell Console\n', + "=== Bash your brains out!\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 diff --git a/mode/shell.py b/mode/shell.py index 95d1262..2ac6535 100644 --- a/mode/shell.py +++ b/mode/shell.py @@ -4,15 +4,15 @@ from mode.sh import ShGrammar class ShellGrammar(Grammar): rules = [ - #RegionRule(r'shell_input', r'^(?:sh$|sh>)', ShGrammar, '\n$'), - #PatternRule(r'shell_mesg', r'^[A-Za-z].*$'), + PatternRule(r'shell_input', r'^>>>.*$'), + PatternRule(r'shell_mesg', r'^===.*$'), ] class Shell(mode.Fundamental): modename = 'Shell' - #grammar = ShellGrammar() + grammar = ShellGrammar() colors = { - #'shell_mesg': ('red', 'default', 'bold'), - #'shell_input.start': ('red', 'default', 'bold'), + 'shell_mesg': ('green', 'default', 'bold'), + 'shell_input': ('cyan', 'default', 'bold'), } install = Shell.install diff --git a/mode/shellmini.py b/mode/shellmini.py index dafeac5..f8cc336 100644 --- a/mode/shellmini.py +++ b/mode/shellmini.py @@ -12,11 +12,14 @@ LIMIT = 79 class ShellExec(Method): sequences = { + '\x1b[01;30m': "[green:default]", + '\x1b[01;31m': "[green:default]", '\x1b[01;32m': "[green:default]", '\x1b[01;34m': "[blue:default]", '\x1b[01;36m': "[cyan:default]", '\x1b[0m': "[default:default]", } + sequences = {} def _execute(self, w, **vargs): a = w.application if a.completion_window_is_open(): @@ -36,7 +39,7 @@ class ShellExec(Method): p = a.get_mini_buffer_prompt() b.insert_string(b.get_buffer_end(), p + s + '\n', force=True) - a.set_mini_buffer_prompt('sh$ ') + a.set_mini_buffer_prompt('>>> ') ok = True args = ['sh', '-c', s] @@ -54,7 +57,7 @@ class ShellExec(Method): seq = ''.join(escaped) if seq in self.sequences: #output2.append(self.sequences[seq]) - output2.append('{foo:bar}') + pass escaped = [] elif c == '\x1b': escaped.append(c) @@ -103,11 +106,8 @@ class ShellExec(Method): newlines.append(PAD + line[i:i + j]) i += j + 1 newlines.append(PAD + line[i:]) - #assert newlines[-1] == PAD newlines[-1] = '' - #b.insert_lines(b.get_buffer_end(), newlines, force=True) - #b.set_lines(newlines, force=True) - b.set_data("\n".join(newlines)) + b.insert_lines(b.get_buffer_end(), newlines, force=True) for w2 in b.windows: w2.goto_end(force=True) @@ -140,87 +140,45 @@ class ShellHistoryNext(Method): w.mode.hindex += 1 w.buffer.set_data(w.mode.history[w.mode.hindex]) -#class ShellTab(Method): -# def execute(self, w, **vargs): -# a = w.application -# s = w.buffer.make_string() -# -# x = w.logical_cursor().x -# if not s or s[:x].isspace(): -# w.insert_string_at_cursor(' ' * w.mode.tabwidth) -# return -# -# l = lex.Lexer(w.mode, ShGrammar) -# tokens = list(l.lex([s])) -# -# curr_t = None -# curr_i = None -# for i in range(0, len(tokens)): -# t = tokens[i] -# if t.x < x and t.end_x() >= x: -# curr_i = i -# curr_t = t -# if curr_t is None: -# return -# -# first_t = curr_t -# j = curr_i -# -# name_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') -# if name_re.match(curr_t.string): -# names = [curr_t.string] -# elif curr_t.string == '.': -# names = [''] -# else: -# names = [] -# -# while j >= 1: -# j -= 1 -# t = tokens[j] -# if name_re.match(t.string): -# names.insert(0, t.string) -# elif t.string == '.': -# pass -# else: -# break -# -# if not names: -# return -# -# obj = None -# g = globals() -# i = 0 -# name = names[0] -# if len(names) > 1: -# while i < len(names): -# name = names[i] -# if obj is None: -# if name in w.mode.locals: -# obj = w.mode.locals[name] -# elif name in w.mode.globals: -# obj = w.mode.globals[name] -# else: -# break -# else: -# if hasattr(obj, name): -# obj = getattr(obj, name) -# else: -# break -# i += 1 -# -# if i == len(names) - 1: -# if obj is not None: -# newnames = dir(obj) -# else: -# newnames = set() -# newnames.update(__builtins__) -# newnames.update(w.mode.locals) -# newnames.update(w.mode.globals) -# candidates = [x for x in newnames if x.startswith(name)] -# -# s = completer.find_common_string(candidates)[len(name):] -# w.insert_string_at_cursor(s) -# mode.mini.use_completion_window(a, name, candidates) +class ShellTab(Method): + def execute(self, w, **vargs): + a = w.application + s = w.buffer.make_string() + + x = w.logical_cursor().x + if not s or s[:x].isspace(): + w.insert_string_at_cursor(' ' * w.mode.tabwidth) + return + + l = lex.Lexer(w.mode, ShGrammar) + tokens = list(l.lex([s])) + + curr_t = None + curr_i = None + for i in range(0, len(tokens)): + t = tokens[i] + if t.x < x and t.end_x() >= x: + curr_i = i + curr_t = t + if curr_t is None: + return + + w.set_error(repr(curr_t)) + return + + if i == len(names) - 1: + if obj is not None: + newnames = dir(obj) + else: + newnames = set() + newnames.update(__builtins__) + newnames.update(w.mode.locals) + newnames.update(w.mode.globals) + candidates = [x for x in newnames if x.startswith(name)] + + s = completer.find_common_string(candidates)[len(name):] + w.insert_string_at_cursor(s) + mode.mini.use_completion_window(a, name, candidates) class ShellBaseMethod(Method): subcls = Method @@ -256,13 +214,13 @@ class OpenShell(Method): if a.window().buffer is not b: a.switch_buffer(b) f = lambda x: None - w.application.open_mini_buffer('sh$ ', f, self, None, 'shellmini') + w.application.open_mini_buffer('>>> ', f, self, None, 'shellmini') class ShellMini(mode.Fundamental): modename = 'ShellMini' grammar = ShGrammar actions = [ShellExec, ShellClear, ShellCancel, ShellHistoryPrev, - ShellHistoryNext, #ShellTab, + ShellHistoryNext, ShellTab, ShellPageUp, ShellPageDown, ShellGotoBeginning, ShellGotoEnd, OpenShell] def __init__(self, w): @@ -277,7 +235,7 @@ class ShellMini(mode.Fundamental): self.add_bindings('shell-cancel', ('C-]', 'C-g')) self.add_bindings('shell-history-prev', ('C-p', 'UP')) self.add_bindings('shell-history-next', ('C-n', 'DOWN')) - #self.add_bindings('shell-tab', ('TAB',)) + self.add_bindings('shell-tab', ('TAB',)) self.add_bindings('shell-page-up', ('M-v',)) self.add_bindings('shell-page-down', ('C-v',)) self.add_bindings('shell-goto-beginning', ('M-<',))