parent
710937cc47
commit
7eb60039eb
|
@ -619,6 +619,10 @@ class Application(object):
|
||||||
self.draw()
|
self.draw()
|
||||||
self.need_draw = False
|
self.need_draw = False
|
||||||
|
|
||||||
|
# gjeiwgjeiw
|
||||||
|
for b in self.bufferlist.buffers:
|
||||||
|
b.close()
|
||||||
|
|
||||||
# clear the error line; it might look confusing to the user
|
# clear the error line; it might look confusing to the user
|
||||||
try:
|
try:
|
||||||
self.win.addstr(self.y-1, 0, ' ' * self.x)
|
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):
|
def __init__(self, app, cmd, args, name=None):
|
||||||
XTerm.__init__(self)
|
XTerm.__init__(self)
|
||||||
Buffer.__init__(self)
|
Buffer.__init__(self)
|
||||||
|
#self.debug = True
|
||||||
self.application = app
|
self.application = app
|
||||||
self._name = name or '*XTerm*'
|
self._name = name or '*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.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._lock = threading.Lock()
|
||||||
self._towrite = ''
|
self._towrite = ''
|
||||||
|
@ -39,24 +41,29 @@ class XTermBuffer(Buffer, XTerm):
|
||||||
w = self._w()
|
w = self._w()
|
||||||
p = w.logical_cursor()
|
p = w.logical_cursor()
|
||||||
if p.x == len(self.lines[p.y]):
|
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:
|
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):
|
def term_do_clear(self):
|
||||||
self.set_lines([''], force=True)
|
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):
|
def term_do_clear_bol(self):
|
||||||
w = self._w()
|
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.delete(p1, p2, force=True)
|
||||||
self._meta = []
|
|
||||||
def term_do_clear_eol(self):
|
def term_do_clear_eol(self):
|
||||||
w = self._w()
|
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.delete(p1, p2, force=True)
|
||||||
self._meta = []
|
|
||||||
def term_do_clear_eos(self):
|
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):
|
def term_do_backspace(self):
|
||||||
self._w().backward()
|
self._w().backward()
|
||||||
|
@ -70,7 +77,7 @@ class XTermBuffer(Buffer, XTerm):
|
||||||
w.next_line()
|
w.next_line()
|
||||||
else:
|
else:
|
||||||
w.end_of_line()
|
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):
|
def term_do_creturn(self):
|
||||||
self._w().start_of_line()
|
self._w().start_of_line()
|
||||||
def term_do_delete(self):
|
def term_do_delete(self):
|
||||||
|
@ -109,17 +116,25 @@ class XTermBuffer(Buffer, XTerm):
|
||||||
def pipe_read(self):
|
def pipe_read(self):
|
||||||
fd = self._pty
|
fd = self._pty
|
||||||
|
|
||||||
|
pid, status = os.waitpid(self._pid, os.WNOHANG)
|
||||||
|
if pid:
|
||||||
|
return
|
||||||
|
|
||||||
# wait until we are hooked up and ready to go
|
# wait until we are hooked up and ready to go
|
||||||
while not self.windows:
|
while not self.windows:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
self.application.need_draw = True
|
||||||
|
|
||||||
# ok, so start reading stuff!
|
# ok, so start reading stuff!
|
||||||
try:
|
try:
|
||||||
while not self._done:
|
while not self._done:
|
||||||
|
pid, status = os.waitpid(self._pid, os.WNOHANG)
|
||||||
|
if pid:
|
||||||
|
break
|
||||||
if self._towrite:
|
if self._towrite:
|
||||||
ifd, ofd, efd = select.select([fd], [fd], [fd], 0.1)
|
ifd, ofd, efd = select.select([fd], [fd], [fd], 0.01)
|
||||||
else:
|
else:
|
||||||
ifd, ofd, efd = select.select([fd], [], [fd], 0.1)
|
ifd, ofd, efd = select.select([fd], [], [fd], 0.01)
|
||||||
if ifd:
|
if ifd:
|
||||||
data = os.read(ifd[0], 1024)
|
data = os.read(ifd[0], 1024)
|
||||||
self.term_receive(data)
|
self.term_receive(data)
|
||||||
|
@ -131,8 +146,17 @@ class XTermBuffer(Buffer, XTerm):
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
if efd:
|
if efd:
|
||||||
raise Exception, "exception is ready: %s" % repr(efd)
|
raise Exception, "exception is ready: %s" % repr(efd)
|
||||||
except (OSError, TypeError, AttributeError):
|
except OSError:
|
||||||
pass
|
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)
|
os.close(fd)
|
||||||
|
|
||||||
def pipe_write(self, s):
|
def pipe_write(self, s):
|
||||||
|
@ -146,3 +170,6 @@ class XTermBuffer(Buffer, XTerm):
|
||||||
def undo(self, move, act): raise Exception, "invalid"
|
def undo(self, move, act): raise Exception, "invalid"
|
||||||
def redo(self, move, act): raise Exception, "invalid"
|
def redo(self, move, act): raise Exception, "invalid"
|
||||||
def reload(self): 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:]
|
del self.outc[self.i:]
|
||||||
def term_do_clear_eos(self):
|
def term_do_clear_eos(self):
|
||||||
pass
|
pass
|
||||||
|
def term_do_home(self):
|
||||||
|
self.outs = ''
|
||||||
|
self.i = 0
|
||||||
|
self.outc = []
|
||||||
|
|
||||||
def term_do_backspace(self):
|
def term_do_backspace(self):
|
||||||
self.i = max(0, self.i - 1)
|
self.i = max(0, self.i - 1)
|
||||||
|
@ -105,25 +109,34 @@ class XTerm(Dumb):
|
||||||
|
|
||||||
callbacks = {
|
callbacks = {
|
||||||
'clear': 'term_do_clear',
|
'clear': 'term_do_clear',
|
||||||
'home': 'term_do_creturn',
|
'home': 'term_do_home',
|
||||||
'rmm': 'term_nop',
|
'rmm': 'term_nop',
|
||||||
'smm': 'term_nop',
|
'smm': 'term_nop',
|
||||||
'op': 'term_nop', #original color-pair
|
'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',
|
'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',
|
'el': 'term_do_clear_eol',
|
||||||
#'el1': 'term_nop',
|
#'el1': 'term_nop',
|
||||||
|
|
||||||
}
|
}
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.debug = False
|
||||||
self._meta = []
|
self._meta = []
|
||||||
f = os.popen('infocmp %s' % self.termtype, 'r')
|
f = os.popen('infocmp %s' % self.termtype, 'r')
|
||||||
#f = open('%s.terminfo' % self.termtype)
|
|
||||||
self.sequences = {}
|
self.sequences = {}
|
||||||
for line in f:
|
for line in f:
|
||||||
if self.comment_re.match(line) or self.header_re.match(line):
|
if self.comment_re.match(line) or self.header_re.match(line):
|
||||||
|
@ -155,7 +168,9 @@ class XTerm(Dumb):
|
||||||
|
|
||||||
if s in self.sequences:
|
if s in self.sequences:
|
||||||
name = self.sequences[s]
|
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 = getattr(self, self.callbacks[name])
|
||||||
f()
|
f()
|
||||||
else:
|
else:
|
||||||
|
@ -177,7 +192,6 @@ class XTerm(Dumb):
|
||||||
else:
|
else:
|
||||||
Dumb.term_handle(self, c)
|
Dumb.term_handle(self, c)
|
||||||
|
|
||||||
|
|
||||||
# terminfo junk
|
# terminfo junk
|
||||||
boolean_settings = [
|
boolean_settings = [
|
||||||
['cpi_changes_res', 'cpix'],
|
['cpi_changes_res', 'cpix'],
|
||||||
|
|
Loading…
Reference in New Issue