parent
710937cc47
commit
7eb60039eb
|
@ -619,6 +619,10 @@ class Application(object):
|
|||
self.draw()
|
||||
self.need_draw = False
|
||||
|
||||
# gjeiwgjeiw
|
||||
for b in self.bufferlist.buffers:
|
||||
b.close()
|
||||
|
||||
# clear the error line; it might look confusing to the user
|
||||
try:
|
||||
self.win.addstr(self.y-1, 0, ' ' * self.x)
|
||||
|
|
|
@ -13,12 +13,14 @@ class XTermBuffer(Buffer, XTerm):
|
|||
def __init__(self, app, cmd, args, name=None):
|
||||
XTerm.__init__(self)
|
||||
Buffer.__init__(self)
|
||||
#self.debug = True
|
||||
self.application = app
|
||||
self._name = name or '*XTerm*'
|
||||
self._pid, self._pty = pty.fork()
|
||||
if self._pid == 0:
|
||||
# child process
|
||||
os.execvpe(cmd, [cmd] + args, {'TERM': self.termtype})
|
||||
env = {'TERM': self.termtype, 'PATH': os.getenv('PATH')}
|
||||
os.execvpe(cmd, [cmd] + args, env)
|
||||
|
||||
self._lock = threading.Lock()
|
||||
self._towrite = ''
|
||||
|
@ -39,24 +41,29 @@ class XTermBuffer(Buffer, XTerm):
|
|||
w = self._w()
|
||||
p = w.logical_cursor()
|
||||
if p.x == len(self.lines[p.y]):
|
||||
w.buffer.insert_string(p, s, act=ACT_NONE, force=True)
|
||||
self.insert_string(p, s, act=ACT_NONE, force=True)
|
||||
else:
|
||||
w.buffer.overwrite_char(p, s, act=ACT_NONE, force=True)
|
||||
self.overwrite_char(p, s, act=ACT_NONE, force=True)
|
||||
def term_do_clear(self):
|
||||
self.set_lines([''], force=True)
|
||||
self._meta = []
|
||||
def term_do_home(self):
|
||||
w = self._w()
|
||||
w.cursor = w.first
|
||||
def term_do_clear_bol(self):
|
||||
w = self._w()
|
||||
p1, p2 = w.get_line_left()
|
||||
p2 = w.logical_cursor()
|
||||
p1 = Point(0, p2.y)
|
||||
self.delete(p1, p2, force=True)
|
||||
self._meta = []
|
||||
def term_do_clear_eol(self):
|
||||
w = self._w()
|
||||
p1, p2 = w.get_line_right()
|
||||
p1 = w.logical_cursor()
|
||||
p2 = Point(len(self.lines[p1.y]), p1.y)
|
||||
self.delete(p1, p2, force=True)
|
||||
self._meta = []
|
||||
def term_do_clear_eos(self):
|
||||
self._meta = []
|
||||
w = self._w()
|
||||
p1 = w.logical_cursor()
|
||||
p2 = self.get_buffer_end()
|
||||
self.delete(p1, p2, force=True)
|
||||
|
||||
def term_do_backspace(self):
|
||||
self._w().backward()
|
||||
|
@ -70,7 +77,7 @@ class XTermBuffer(Buffer, XTerm):
|
|||
w.next_line()
|
||||
else:
|
||||
w.end_of_line()
|
||||
w.buffer.insert_string(w.logical_cursor(), "\n", act=ACT_NONE, force=True)
|
||||
self.insert_string(w.logical_cursor(), "\n", act=ACT_NONE, force=True)
|
||||
def term_do_creturn(self):
|
||||
self._w().start_of_line()
|
||||
def term_do_delete(self):
|
||||
|
@ -109,17 +116,25 @@ class XTermBuffer(Buffer, XTerm):
|
|||
def pipe_read(self):
|
||||
fd = self._pty
|
||||
|
||||
pid, status = os.waitpid(self._pid, os.WNOHANG)
|
||||
if pid:
|
||||
return
|
||||
|
||||
# wait until we are hooked up and ready to go
|
||||
while not self.windows:
|
||||
time.sleep(0.1)
|
||||
self.application.need_draw = True
|
||||
|
||||
# ok, so start reading stuff!
|
||||
try:
|
||||
while not self._done:
|
||||
pid, status = os.waitpid(self._pid, os.WNOHANG)
|
||||
if pid:
|
||||
break
|
||||
if self._towrite:
|
||||
ifd, ofd, efd = select.select([fd], [fd], [fd], 0.1)
|
||||
ifd, ofd, efd = select.select([fd], [fd], [fd], 0.01)
|
||||
else:
|
||||
ifd, ofd, efd = select.select([fd], [], [fd], 0.1)
|
||||
ifd, ofd, efd = select.select([fd], [], [fd], 0.01)
|
||||
if ifd:
|
||||
data = os.read(ifd[0], 1024)
|
||||
self.term_receive(data)
|
||||
|
@ -131,8 +146,17 @@ class XTermBuffer(Buffer, XTerm):
|
|||
self._lock.release()
|
||||
if efd:
|
||||
raise Exception, "exception is ready: %s" % repr(efd)
|
||||
except (OSError, TypeError, AttributeError):
|
||||
except OSError:
|
||||
pass
|
||||
except TypeError:
|
||||
raise
|
||||
except AttributeError:
|
||||
raise
|
||||
if not pid:
|
||||
pid, status = os.waitpid(self._pid, os.WNOHANG)
|
||||
s = '\nprocess %d exited (%d)\n' % (pid, status >> 8)
|
||||
self._term_insert(s)
|
||||
self.application.need_draw = True
|
||||
os.close(fd)
|
||||
|
||||
def pipe_write(self, s):
|
||||
|
@ -146,3 +170,6 @@ class XTermBuffer(Buffer, XTerm):
|
|||
def undo(self, move, act): raise Exception, "invalid"
|
||||
def redo(self, move, act): raise Exception, "invalid"
|
||||
def reload(self): raise Exception, "invalid"
|
||||
def close(self):
|
||||
self._done = True
|
||||
self._thread.join()
|
||||
|
|
34
term.py
34
term.py
|
@ -30,6 +30,10 @@ class Dumb:
|
|||
del self.outc[self.i:]
|
||||
def term_do_clear_eos(self):
|
||||
pass
|
||||
def term_do_home(self):
|
||||
self.outs = ''
|
||||
self.i = 0
|
||||
self.outc = []
|
||||
|
||||
def term_do_backspace(self):
|
||||
self.i = max(0, self.i - 1)
|
||||
|
@ -105,25 +109,34 @@ class XTerm(Dumb):
|
|||
|
||||
callbacks = {
|
||||
'clear': 'term_do_clear',
|
||||
'home': 'term_do_creturn',
|
||||
'home': 'term_do_home',
|
||||
'rmm': 'term_nop',
|
||||
'smm': 'term_nop',
|
||||
'op': 'term_nop', #original color-pair
|
||||
|
||||
'smacs': 'term_nop', #orig charset
|
||||
'rmacs': 'term_nop',
|
||||
'smso': 'term_nop', #enter standout mode
|
||||
'rmso': 'term_nop',
|
||||
'cup': 'term_nop',
|
||||
|
||||
#'ed': 'term_nop',
|
||||
'cnorm': 'term_nop', #make cursor normal
|
||||
'civis': 'term_nop', #make cursor inviz
|
||||
'cvvis': 'term_nop', #make cursor bold
|
||||
|
||||
'smacs': 'term_nop', #orig charset
|
||||
'rmacs': 'term_nop', #
|
||||
'smso': 'term_nop', #enter standout
|
||||
'rmso': 'term_nop', #leave standout
|
||||
'smul': 'term_nop', #enter underline
|
||||
'rmul': 'term_nop', #leave underline
|
||||
'smkx': 'term_nop', #enter keypad junk
|
||||
'rmkx': 'term_nop', #leave keypad junk
|
||||
|
||||
'ed': 'term_do_clear_eos',
|
||||
'el': 'term_do_clear_eol',
|
||||
#'el1': 'term_nop',
|
||||
|
||||
}
|
||||
def __init__(self):
|
||||
self.debug = False
|
||||
self._meta = []
|
||||
f = os.popen('infocmp %s' % self.termtype, 'r')
|
||||
#f = open('%s.terminfo' % self.termtype)
|
||||
self.sequences = {}
|
||||
for line in f:
|
||||
if self.comment_re.match(line) or self.header_re.match(line):
|
||||
|
@ -155,7 +168,9 @@ class XTerm(Dumb):
|
|||
|
||||
if s in self.sequences:
|
||||
name = self.sequences[s]
|
||||
if name in self.callbacks:
|
||||
if self.debug:
|
||||
self._term_insert('<%s>' % name)
|
||||
elif name in self.callbacks:
|
||||
f = getattr(self, self.callbacks[name])
|
||||
f()
|
||||
else:
|
||||
|
@ -177,7 +192,6 @@ class XTerm(Dumb):
|
|||
else:
|
||||
Dumb.term_handle(self, c)
|
||||
|
||||
|
||||
# terminfo junk
|
||||
boolean_settings = [
|
||||
['cpi_changes_res', 'cpix'],
|
||||
|
|
Loading…
Reference in New Issue