commit
c64d639dee
|
@ -1222,9 +1222,8 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# ok, now run our app
|
# ok, now run our app
|
||||||
try:
|
try:
|
||||||
d = {'jump_to_line': opts.goto, 'init_mode': opts.mode,
|
curses.wrapper(run_app, buffers, jump_to_line=opts.goto,
|
||||||
'init_cmds': opts.cmds}
|
init_mode=opts.mode, init_cmds=opts.cmds)
|
||||||
curses.wrapper(run_app, buffers, **d)
|
|
||||||
err = 0
|
err = 0
|
||||||
except:
|
except:
|
||||||
# restore terminal state before printing an error
|
# restore terminal state before printing an error
|
||||||
|
|
|
@ -3,7 +3,9 @@ import re
|
||||||
import StringIO
|
import StringIO
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import completer
|
import completer
|
||||||
|
import util
|
||||||
from method import Method
|
from method import Method
|
||||||
import method.move
|
import method.move
|
||||||
import mode.mini
|
import mode.mini
|
||||||
|
@ -66,23 +68,12 @@ class ConsoleExec(Method):
|
||||||
limit = min([w.width for w in b.windows]) - len(PAD)
|
limit = min([w.width for w in b.windows]) - len(PAD)
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
newlines = []
|
lines = []
|
||||||
for line in output.split('\n'):
|
for line in output.split('\n'):
|
||||||
i = 0
|
lines.extend([PAD + l for l in util.wrap_lines(line, limit)])
|
||||||
while i + limit < len(line):
|
if lines[-1] == PAD:
|
||||||
j = limit
|
lines[-1] = ''
|
||||||
while j > 0 and line[i + j] != ' ':
|
b.insert_lines(b.get_buffer_end(), lines, force=True)
|
||||||
j -= 1
|
|
||||||
if j == 0:
|
|
||||||
newlines.append(PAD + line[i:i + limit])
|
|
||||||
i += limit
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
for w2 in b.windows:
|
for w2 in b.windows:
|
||||||
w2.goto_end(force=True)
|
w2.goto_end(force=True)
|
||||||
|
|
||||||
|
|
16
util.py
16
util.py
|
@ -152,3 +152,19 @@ def communicate(cmd, stdin=None, stderr=False, shell=True):
|
||||||
out, err = pipe.communicate(input=stdin)
|
out, err = pipe.communicate(input=stdin)
|
||||||
result = pipe.wait()
|
result = pipe.wait()
|
||||||
return result, decode(out or ''), decode(err or '')
|
return result, decode(out or ''), decode(err or '')
|
||||||
|
|
||||||
|
def wrap_lines(s, limit):
|
||||||
|
'''given a string, return an iterator of wrapped lines'''
|
||||||
|
i = 0
|
||||||
|
while i + limit < len(s):
|
||||||
|
j = limit
|
||||||
|
while j > 0 and s[i + j] != ' ':
|
||||||
|
j -= 1
|
||||||
|
if j == 0:
|
||||||
|
yield s[i:i + limit]
|
||||||
|
i += limit
|
||||||
|
else:
|
||||||
|
yield s[i:i + j]
|
||||||
|
i += j + 1
|
||||||
|
if s[i:]:
|
||||||
|
yield s[i:]
|
||||||
|
|
Loading…
Reference in New Issue