From 427011f50c0f7e0caa472feafb9718f0eb5a72a9 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Thu, 1 Oct 2009 20:06:17 -0400 Subject: [PATCH 1/2] small refactor --HG-- branch : pmacs2 --- application.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/application.py b/application.py index 873820d..519bd8c 100755 --- a/application.py +++ b/application.py @@ -1221,9 +1221,8 @@ if __name__ == "__main__": # ok, now run our app try: - d = {'jump_to_line': opts.goto, 'init_mode': opts.mode, - 'init_cmds': opts.cmds} - curses.wrapper(run_app, buffers, **d) + curses.wrapper(run_app, buffers, jump_to_line=opts.goto, + init_mode=opts.mode, init_cmds=opts.cmds) err = 0 except: # restore terminal state before printing an error From f2ccce518d23193381d1305b97df8f55c73840c0 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Thu, 1 Oct 2009 20:06:40 -0400 Subject: [PATCH 2/2] put wrapping code in util.py --HG-- branch : pmacs2 --- mode/consolemini.py | 23 +++++++---------------- util.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/mode/consolemini.py b/mode/consolemini.py index 2707411..fb71204 100644 --- a/mode/consolemini.py +++ b/mode/consolemini.py @@ -3,7 +3,9 @@ import re import StringIO import sys import traceback + import completer +import util from method import Method import method.move import mode.mini @@ -66,23 +68,12 @@ class ConsoleExec(Method): limit = min([w.width for w in b.windows]) - len(PAD) if output: - newlines = [] + lines = [] for line in output.split('\n'): - i = 0 - while i + limit < len(line): - j = limit - while j > 0 and line[i + j] != ' ': - 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) + lines.extend([PAD + l for l in util.wrap_lines(line, limit)]) + if lines[-1] == PAD: + lines[-1] = '' + b.insert_lines(b.get_buffer_end(), lines, force=True) for w2 in b.windows: w2.goto_end(force=True) diff --git a/util.py b/util.py index 5e0101c..26a0ffb 100644 --- a/util.py +++ b/util.py @@ -152,3 +152,19 @@ def communicate(cmd, stdin=None, stderr=False, shell=True): out, err = pipe.communicate(input=stdin) result = pipe.wait() 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:]