interact is awesome

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-03-04 02:10:32 +00:00
parent d1195b991f
commit 4ad5cba821
5 changed files with 63 additions and 31 deletions

View File

@ -331,6 +331,9 @@ class Application(object):
else: else:
blist.set_slot(i, active_slot.window.buffer) blist.set_slot(i, active_slot.window.buffer)
assert blist.slots[i].window is not None assert blist.slots[i].window is not None
def close_buffer_by_name(self, name):
if self.has_buffer_name(name):
self.close_buffer(self.get_buffer_by_name(name))
def open_path(self, path, binary=False, cipher=None, password=None): def open_path(self, path, binary=False, cipher=None, password=None):
path = os.path.abspath(os.path.realpath(util.expand_tilde(path))) path = os.path.abspath(os.path.realpath(util.expand_tilde(path)))

View File

@ -1,4 +1,4 @@
import fcntl, os, select, pty, threading import fcntl, os, select, pty, threading, time
from buffer import Buffer, ACT_NORM, ACT_NONE from buffer import Buffer, ACT_NORM, ACT_NONE
from term import XTerm from term import XTerm
@ -18,7 +18,7 @@ class XTermBuffer(Buffer, XTerm):
self._pid, self._pty = pty.fork() self._pid, self._pty = pty.fork()
if self._pid == 0: if self._pid == 0:
# child process # child process
os.execve(cmd, [cmd] + args, {'TERM': self.termtype}) os.execvpe(cmd, [cmd] + args, {'TERM': self.termtype})
self._lock = threading.Lock() self._lock = threading.Lock()
self._towrite = '' self._towrite = ''
@ -28,7 +28,6 @@ class XTermBuffer(Buffer, XTerm):
self._thread.setDaemon(True) self._thread.setDaemon(True)
self._thread.start() self._thread.start()
def _w(self): def _w(self):
return self.windows[0] return self.windows[0]
def _get_height(self): def _get_height(self):
@ -109,6 +108,12 @@ class XTermBuffer(Buffer, XTerm):
def pipe_read(self): def pipe_read(self):
fd = self._pty fd = self._pty
# wait until we are hooked up and ready to go
while not self.windows:
time.sleep(0.1)
# ok, so start reading stuff!
try: try:
while not self._done: while not self._done:
if self._towrite: if self._towrite:

View File

@ -134,3 +134,21 @@ class Sed(Pipe):
args = [Argument('expression', datatype="str", prompt="Expression: ")] args = [Argument('expression', datatype="str", prompt="Expression: ")]
def _parse(self, w, **vargs): def _parse(self, w, **vargs):
return ('grep', ('sed', '-r', '-e', vargs['expression']), False) return ('grep', ('sed', '-r', '-e', vargs['expression']), False)
class Interact(Method):
'''Interact with a program via a PTY'''
args = [Argument('bname', datatype="str", prompt="Buffer Name: ",
default=default.build_constant('*Interact*')),
Argument('cmd', datatype="str", prompt="Command: ",
default=default.build_constant('bash'))]
def _execute(self, w, **vargs):
bname = vargs['bname']
cmd = vargs['cmd']
a = w.application
a.close_buffer_by_name(bname)
b = buffer.emul.XTermBuffer(a, cmd, [], name=bname)
a.add_buffer(b)
window.Window(b, a)
if a.window().buffer is not b:
a.switch_buffer(b)

View File

@ -1,5 +1,7 @@
import commands, os.path, string, sys, traceback import commands, os.path, string, sys, traceback
import color, completer, default, mode, method, regex, tab import color, completer, default, mode, method, regex, tab
import buffer.emul
import window
from point import Point from point import Point
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule
@ -39,6 +41,23 @@ class HaskellGrammar(Grammar):
PatternRule(r'operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|##|\^|/|\*|-|\+|='), PatternRule(r'operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|##|\^|/|\*|-|\+|='),
] ]
#class HaskellOpenHugs(method.Method):
# '''Evaluate haskell expressions'''
# bname = '*Hugs*'
# def _execute(self, w, **vargs):
# a = w.application
# if not a.has_buffer_name(self.bname):
# b = buffer.emul.XTermBuffer(a, '/usr/bin/hugs', [], name=self.bname)
# a.add_buffer(b)
# window.Window(b, a)
# b = a.bufferlist.get_buffer_by_name(self.bname)
# if a.window().buffer is not b:
# a.switch_buffer(b)
class HaskellOpenHugs(method.shell.Interact):
args = []
def _execute(self, w, **vargs):
method.shell.Interact._execute(self, w, bname='*Hugs', cmd='hugs')
class HaskellTabber(tab.Tabber): class HaskellTabber(tab.Tabber):
pass pass
@ -62,10 +81,12 @@ class Haskell(mode.Fundamental):
'string.gap.null': ('red', 'default', 'bold'), 'string.gap.null': ('red', 'default', 'bold'),
'string.gap.end': ('red', 'default', 'bold'), 'string.gap.end': ('red', 'default', 'bold'),
} }
def __init__(self, w): _bindings = {
mode.Fundamental.__init__(self, w) 'close-paren': (')',),
self.add_bindings('close-paren', (')',)) 'close-brace': ('}',),
self.add_bindings('close-brace', ('}',)) 'close-bracket': (']',),
self.add_bindings('close-bracket', (']',)) }
actions = [HaskellOpenHugs]
install = Haskell.install install = Haskell.install

View File

@ -117,32 +117,17 @@ class ShellGotoBeginning(ShellBaseMethod):
class ShellGotoEnd(ShellBaseMethod): class ShellGotoEnd(ShellBaseMethod):
subcls = method.move.GotoEnd subcls = method.move.GotoEnd
class OpenShell(Method): class OpenShellRaw(method.shell.Interact):
'''Evaluate sh expressions''' '''Evaluate sh expressions'''
def execute(self, w, **vargs): args = []
a = w.application def _execute(self, w, **vargs):
if not a.has_buffer_name('*Shell*'): method.shell.Interact._execute(self, w, bname='*Shell*', cmd='bash')
#b = buffer.pipe.PipeBuffer('/bin/bash', [], name="*Shell*", term='xterm') class OpenShell(OpenShellRaw):
b = buffer.emul.XTermBuffer(a, '/bin/bash', [], name="*Shell*") '''Evaluate sh expressions'''
a.add_buffer(b) def _execute(self, w, **vargs):
window.Window(b, a) OpenShellRaw._execute(self, w)
b = a.bufferlist.get_buffer_by_name('*Shell*')
if a.window().buffer is not b:
a.switch_buffer(b)
f = lambda x: None f = lambda x: None
w.application.open_mini_buffer('>>> ', f, self, None, 'shellmini') w.application.open_mini_buffer('>>> ', f, self, None, 'shellmini')
class OpenShellRaw(Method):
'''Evaluate sh expressions'''
def execute(self, w, **vargs):
a = w.application
if not a.has_buffer_name('*Shell*'):
#b = buffer.pipe.PipeBuffer('/bin/bash', [], name="*Shell*", term='xterm')
b = buffer.emul.XTermBuffer(a, '/bin/bash', [], name="*Shell*")
a.add_buffer(b)
window.Window(b, a)
b = a.bufferlist.get_buffer_by_name('*Shell*')
if a.window().buffer is not b:
a.switch_buffer(b)
class ShellMini(mode.Fundamental): class ShellMini(mode.Fundamental):
modename = 'ShellMini' modename = 'ShellMini'