X Tutup
Skip to content

Commit eb56d06

Browse files
fix args parsing
--HG-- branch : scroll-frontend
1 parent 68cf03b commit eb56d06

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

bpython/scroll.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
import sys
2+
from optparse import Option
23

34
from fmtstr.terminal import Terminal
45
from fmtstr.terminalcontrol import TerminalController
56

67
from bpython.scrollfrontend.repl import Repl
7-
import bpython.args
8-
9-
if '-v' in sys.argv:
10-
import logging
11-
logging.basicConfig(filename='scroll.log', level=logging.DEBUG)
12-
sys.argv.remove('-v')
13-
14-
def cli():
15-
config, options, exec_args = bpython.args.parse(args=None)
16-
return main(config=config, options=options, exec_args=exec_args)
17-
18-
def main(locals_=None, config=None, exec_args=None, options=None):
19-
#TODO this is gross - passing in args and options means you can't
20-
# easily have that functionality without running it frmo the command line,
21-
# but it makes reusing bpython code easier
8+
from bpython import args as bpargs
9+
from bpython.translations import _
10+
11+
def main(args=None, locals_=None, banner=None):
12+
config, options, exec_args = bpargs.parse(args, (
13+
'scroll options', None, [
14+
Option('--log', '-L', action='store_true',
15+
help=_("log debug messages to scroll.log")),
16+
]))
17+
if options.log:
18+
import logging
19+
logging.basicConfig(filename='scroll.log', level=logging.DEBUG)
2220

2321
with TerminalController() as tc:
2422
with Terminal(tc, keep_last_line=True, hide_cursor=False) as term:
25-
with Repl(config=config, locals_=locals_, stuff_a_refresh_request=tc.stuff_a_refresh_request) as repl:
23+
with Repl(config=config, locals_=locals_, stuff_a_refresh_request=tc.stuff_a_refresh_request, banner=banner) as repl:
2624
rows, columns = tc.get_screen_size()
2725
repl.width = columns
2826
repl.height = rows
@@ -32,9 +30,9 @@ def main(locals_=None, config=None, exec_args=None, options=None):
3230
assert options, "don't pass in exec_args without options"
3331
try:
3432
#TODO replace this so that stdout is properly harvested for display!
35-
bpython.args.exec_code(repl.interp, exec_args)
36-
except SystemExit:
37-
pass
33+
bpargs.exec_code(repl.interp, exec_args)
34+
except SystemExit, e:
35+
exit_value = e.args
3836
if not options.interactive:
3937
#TODO treat this properly: no prompt should ever display, but stdout should!
4038
array, cursor_pos = repl.paint(about_to_exit=True)
@@ -54,4 +52,4 @@ def main(locals_=None, config=None, exec_args=None, options=None):
5452
repl.scroll_offset += scrolled
5553

5654
if __name__ == '__main__':
57-
sys.exit(cli())
55+
sys.exit(main())

bpython/scrollfrontend/repl.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
#TODO use events instead of length-one queues for interthread communication
4444

4545
#TODO raw_input should be bytes in python2
46-
#TODO ctlr-c handling at all times
47-
#TODO nicer passing of control between threads
46+
4847

4948
from bpython.keys import cli_key_dispatch as key_dispatch
5049

@@ -105,20 +104,23 @@ class Repl(BpythonRepl):
105104
"""
106105

107106
## initialization, cleanup
108-
def __init__(self, locals_=None, config=None, stuff_a_refresh_request=lambda: None):
107+
def __init__(self, locals_=None, config=None, stuff_a_refresh_request=lambda: None, banner=None):
109108
logging.debug("starting init")
110109
interp = code.InteractiveInterpreter(locals=locals_)
111110

112111
if config is None:
113112
config = Struct()
114113
loadini(config, default_config_path())
115114

115+
if banner is None:
116+
banner = _('welcome to bpython')
117+
116118
config.autocomplete_mode = SIMPLE # only one implemented currently
117119

118120
if config.cli_suggestion_width <= 0 or config.cli_suggestion_width > 1:
119121
config.cli_suggestion_width = 1
120122

121-
self.status_bar = StatusBar(_('welcome to bpython'), _(
123+
self.status_bar = StatusBar(banner, _(
122124
" <%s> Rewind <%s> Save <%s> Pastebin <%s> Editor"
123125
) % (config.undo_key, config.save_key, config.pastebin_key, config.external_editor_key))
124126
self.rl_char_sequences = get_updated_char_sequences(key_dispatch, config)
@@ -304,10 +306,10 @@ def send_to_stdout(self, output):
304306
logging.debug('display_lines: %r', self.display_lines)
305307

306308
def send_to_stderr(self, error):
307-
self.send_to_stdout(error)
308-
#self.display_lines.extend([func_for_letter(self.config.color_scheme['error'])(line)
309-
# for line in sum([paint.display_linize(line, self.width)
310-
# for line in error.split('\n')], [])])
309+
#self.send_to_stdout(error)
310+
self.display_lines.extend([func_for_letter(self.config.color_scheme['error'])(line)
311+
for line in sum([paint.display_linize(line, self.width)
312+
for line in error.split('\n')], [])])
311313

312314
def send_to_stdin(self, line):
313315
if line.endswith('\n'):

data/bpython-scroll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

33
import sys
4-
from bpython.scroll import cli
4+
from bpython.scroll import main
55

6-
sys.exit(cli())
6+
sys.exit(main())

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def initialize_options(self):
167167
'console_scripts': [
168168
'bpython = bpython.cli:main',
169169
'bpython-urwid = bpython.urwid:main',
170-
'bpython-scroll = bpython.scroll:cli [scroll]',
170+
'bpython-scroll = bpython.scroll:main [scroll]',
171171
],
172172
'gui_scripts': [
173173
'bpython-gtk = bpython.gtk_:main'

0 commit comments

Comments
 (0)
X Tutup