parent
38d88eecbb
commit
e9077cae64
15
buffer.py
15
buffer.py
|
@ -903,18 +903,19 @@ class AboutBuffer(ColorDataBuffer):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ColorDataBuffer.__init__(self, '*About*', ABOUT_DATA)
|
ColorDataBuffer.__init__(self, '*About*', ABOUT_DATA)
|
||||||
|
|
||||||
class ShellBuffer(ColorDataBuffer):
|
class ShellBuffer(Buffer):
|
||||||
btype = 'shell'
|
btype = 'shell'
|
||||||
intro = '[red:default:bold]Welcome to Hell[default:default]\n'
|
modename = 'shell'
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ColorDataBuffer.__init__(self, '*XYZ*', self.intro)
|
Buffer.__init__(self)
|
||||||
|
self.clear()
|
||||||
def clear(self):
|
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):
|
def name(self):
|
||||||
return '*Shell*'
|
return '*Shell*'
|
||||||
def changed(self):
|
def changed(self):
|
||||||
return False
|
return False
|
||||||
def close(self):
|
|
||||||
pass
|
|
||||||
def readonly(self):
|
def readonly(self):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -4,15 +4,15 @@ from mode.sh import ShGrammar
|
||||||
|
|
||||||
class ShellGrammar(Grammar):
|
class ShellGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
#RegionRule(r'shell_input', r'^(?:sh$|sh>)', ShGrammar, '\n$'),
|
PatternRule(r'shell_input', r'^>>>.*$'),
|
||||||
#PatternRule(r'shell_mesg', r'^[A-Za-z].*$'),
|
PatternRule(r'shell_mesg', r'^===.*$'),
|
||||||
]
|
]
|
||||||
class Shell(mode.Fundamental):
|
class Shell(mode.Fundamental):
|
||||||
modename = 'Shell'
|
modename = 'Shell'
|
||||||
#grammar = ShellGrammar()
|
grammar = ShellGrammar()
|
||||||
colors = {
|
colors = {
|
||||||
#'shell_mesg': ('red', 'default', 'bold'),
|
'shell_mesg': ('green', 'default', 'bold'),
|
||||||
#'shell_input.start': ('red', 'default', 'bold'),
|
'shell_input': ('cyan', 'default', 'bold'),
|
||||||
}
|
}
|
||||||
|
|
||||||
install = Shell.install
|
install = Shell.install
|
||||||
|
|
|
@ -12,11 +12,14 @@ LIMIT = 79
|
||||||
|
|
||||||
class ShellExec(Method):
|
class ShellExec(Method):
|
||||||
sequences = {
|
sequences = {
|
||||||
|
'\x1b[01;30m': "[green:default]",
|
||||||
|
'\x1b[01;31m': "[green:default]",
|
||||||
'\x1b[01;32m': "[green:default]",
|
'\x1b[01;32m': "[green:default]",
|
||||||
'\x1b[01;34m': "[blue:default]",
|
'\x1b[01;34m': "[blue:default]",
|
||||||
'\x1b[01;36m': "[cyan:default]",
|
'\x1b[01;36m': "[cyan:default]",
|
||||||
'\x1b[0m': "[default:default]",
|
'\x1b[0m': "[default:default]",
|
||||||
}
|
}
|
||||||
|
sequences = {}
|
||||||
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():
|
||||||
|
@ -36,7 +39,7 @@ class ShellExec(Method):
|
||||||
p = a.get_mini_buffer_prompt()
|
p = a.get_mini_buffer_prompt()
|
||||||
b.insert_string(b.get_buffer_end(), p + s + '\n', force=True)
|
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
|
ok = True
|
||||||
|
|
||||||
args = ['sh', '-c', s]
|
args = ['sh', '-c', s]
|
||||||
|
@ -54,7 +57,7 @@ class ShellExec(Method):
|
||||||
seq = ''.join(escaped)
|
seq = ''.join(escaped)
|
||||||
if seq in self.sequences:
|
if seq in self.sequences:
|
||||||
#output2.append(self.sequences[seq])
|
#output2.append(self.sequences[seq])
|
||||||
output2.append('{foo:bar}')
|
pass
|
||||||
escaped = []
|
escaped = []
|
||||||
elif c == '\x1b':
|
elif c == '\x1b':
|
||||||
escaped.append(c)
|
escaped.append(c)
|
||||||
|
@ -103,11 +106,8 @@ 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
|
|
||||||
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)
|
||||||
|
|
||||||
|
@ -140,87 +140,45 @@ class ShellHistoryNext(Method):
|
||||||
w.mode.hindex += 1
|
w.mode.hindex += 1
|
||||||
w.buffer.set_data(w.mode.history[w.mode.hindex])
|
w.buffer.set_data(w.mode.history[w.mode.hindex])
|
||||||
|
|
||||||
#class ShellTab(Method):
|
class ShellTab(Method):
|
||||||
# def execute(self, w, **vargs):
|
def execute(self, w, **vargs):
|
||||||
# a = w.application
|
a = w.application
|
||||||
# s = w.buffer.make_string()
|
s = w.buffer.make_string()
|
||||||
#
|
|
||||||
# x = w.logical_cursor().x
|
x = w.logical_cursor().x
|
||||||
# if not s or s[:x].isspace():
|
if not s or s[:x].isspace():
|
||||||
# w.insert_string_at_cursor(' ' * w.mode.tabwidth)
|
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
|
||||||
# return
|
return
|
||||||
#
|
|
||||||
# l = lex.Lexer(w.mode, ShGrammar)
|
l = lex.Lexer(w.mode, ShGrammar)
|
||||||
# tokens = list(l.lex([s]))
|
tokens = list(l.lex([s]))
|
||||||
#
|
|
||||||
# curr_t = None
|
curr_t = None
|
||||||
# curr_i = None
|
curr_i = None
|
||||||
# for i in range(0, len(tokens)):
|
for i in range(0, len(tokens)):
|
||||||
# t = tokens[i]
|
t = tokens[i]
|
||||||
# if t.x < x and t.end_x() >= x:
|
if t.x < x and t.end_x() >= x:
|
||||||
# curr_i = i
|
curr_i = i
|
||||||
# curr_t = t
|
curr_t = t
|
||||||
# if curr_t is None:
|
if curr_t is None:
|
||||||
# return
|
return
|
||||||
#
|
|
||||||
# first_t = curr_t
|
w.set_error(repr(curr_t))
|
||||||
# j = curr_i
|
return
|
||||||
#
|
|
||||||
# name_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')
|
if i == len(names) - 1:
|
||||||
# if name_re.match(curr_t.string):
|
if obj is not None:
|
||||||
# names = [curr_t.string]
|
newnames = dir(obj)
|
||||||
# elif curr_t.string == '.':
|
else:
|
||||||
# names = ['']
|
newnames = set()
|
||||||
# else:
|
newnames.update(__builtins__)
|
||||||
# names = []
|
newnames.update(w.mode.locals)
|
||||||
#
|
newnames.update(w.mode.globals)
|
||||||
# while j >= 1:
|
candidates = [x for x in newnames if x.startswith(name)]
|
||||||
# j -= 1
|
|
||||||
# t = tokens[j]
|
s = completer.find_common_string(candidates)[len(name):]
|
||||||
# if name_re.match(t.string):
|
w.insert_string_at_cursor(s)
|
||||||
# names.insert(0, t.string)
|
mode.mini.use_completion_window(a, name, candidates)
|
||||||
# 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 ShellBaseMethod(Method):
|
class ShellBaseMethod(Method):
|
||||||
subcls = Method
|
subcls = Method
|
||||||
|
@ -256,13 +214,13 @@ class OpenShell(Method):
|
||||||
if a.window().buffer is not b:
|
if a.window().buffer is not b:
|
||||||
a.switch_buffer(b)
|
a.switch_buffer(b)
|
||||||
f = lambda x: None
|
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):
|
class ShellMini(mode.Fundamental):
|
||||||
modename = 'ShellMini'
|
modename = 'ShellMini'
|
||||||
grammar = ShGrammar
|
grammar = ShGrammar
|
||||||
actions = [ShellExec, ShellClear, ShellCancel, ShellHistoryPrev,
|
actions = [ShellExec, ShellClear, ShellCancel, ShellHistoryPrev,
|
||||||
ShellHistoryNext, #ShellTab,
|
ShellHistoryNext, ShellTab,
|
||||||
ShellPageUp, ShellPageDown, ShellGotoBeginning, ShellGotoEnd,
|
ShellPageUp, ShellPageDown, ShellGotoBeginning, ShellGotoEnd,
|
||||||
OpenShell]
|
OpenShell]
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
|
@ -277,7 +235,7 @@ class ShellMini(mode.Fundamental):
|
||||||
self.add_bindings('shell-cancel', ('C-]', 'C-g'))
|
self.add_bindings('shell-cancel', ('C-]', 'C-g'))
|
||||||
self.add_bindings('shell-history-prev', ('C-p', 'UP'))
|
self.add_bindings('shell-history-prev', ('C-p', 'UP'))
|
||||||
self.add_bindings('shell-history-next', ('C-n', 'DOWN'))
|
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-up', ('M-v',))
|
||||||
self.add_bindings('shell-page-down', ('C-v',))
|
self.add_bindings('shell-page-down', ('C-v',))
|
||||||
self.add_bindings('shell-goto-beginning', ('M-<',))
|
self.add_bindings('shell-goto-beginning', ('M-<',))
|
||||||
|
|
Loading…
Reference in New Issue