X Tutup
Skip to content

Commit 9a4a71a

Browse files
add external editor key, fill_terminal, list_above to config
--HG-- branch : scroll-frontend
1 parent 3fce108 commit 9a4a71a

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

bpython/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def loadini(struct, configfile):
8282
'delete': 'C-d',
8383
'down_one_line': 'C-n',
8484
'exit': '',
85+
'external_editor': 'F7',
8586
'last_output': 'F9',
8687
'pastebin': 'F8',
8788
'save': 'C-s',
@@ -95,6 +96,10 @@ def loadini(struct, configfile):
9596
'suggestion_width': 0.8,
9697
'trim_prompts': False,
9798
},
99+
'scroll': {
100+
'list_above' : False,
101+
'fill_terminal' : False,
102+
},
98103
'gtk': {
99104
'font': 'monospace 10',
100105
'color_scheme': 'default'}})
@@ -135,6 +140,7 @@ def loadini(struct, configfile):
135140
struct.delete_key = config.get('keyboard', 'delete')
136141
struct.exit_key = config.get('keyboard', 'exit')
137142
struct.last_output_key = config.get('keyboard', 'last_output')
143+
struct.external_editor_key = config.get('keyboard', 'external_editor')
138144

139145
struct.pastebin_confirm = config.getboolean('general', 'pastebin_confirm')
140146
struct.pastebin_private = config.getboolean('general', 'pastebin_private')
@@ -157,6 +163,9 @@ def loadini(struct, configfile):
157163

158164
struct.gtk_font = config.get('gtk', 'font')
159165

166+
struct.scroll_list_above = config.getboolean('scroll', 'list_above')
167+
struct.scroll_fill_terminal = config.getboolean('scroll', 'fill_terminal')
168+
160169
color_scheme_name = config.get('general', 'color_scheme')
161170
color_gtk_scheme_name = config.get('gtk', 'color_scheme')
162171

bpython/scrollfrontend/interaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def process_event(self, e):
6161
else:
6262
self.response_queue.put(False)
6363
self.escape()
64-
elif e == ['\x1b', '\t']:
64+
elif e in ['\x1b', '\t', '\x1b\t', '\x1b\x1b']:
6565
self.response_queue.put(False)
6666
self.escape()
6767
else: # add normal character
@@ -110,7 +110,7 @@ def confirm(self, q):
110110
return self.response_queue.get()
111111
def file_prompt(self, s):
112112
"""Expected to return a file name, given """
113-
self.prompt = s
113+
self.prompt = s.replace('Esc', 'Tab')
114114
self.in_prompt = True
115115
self.request_or_notify_queue.put(s)
116116
r = self.response_queue.get()

bpython/scrollfrontend/repl.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
import fmtstr.events as events
3636
from bpython.scrollfrontend.friendly import NotImplementedError
3737

38-
INFOBOX_ONLY_BELOW = True #TODO make this a config option if it isn't already
39-
EDITOR_KEY = 'F7' #TODO put this in config if it gets to stay in
40-
4138
#TODO implement paste mode and figure out what the deal with config.paste_time is
4239
#TODO figure out how config.auto_display_list=False behaves and implement it
4340
#TODO figure out how config.list_win_visible behaves and implement it
@@ -152,7 +149,7 @@ def __init__(self, locals_=None, config=None):
152149

153150
self.status_bar = StatusBar(_('welcome to bpython'), _(
154151
" <%s> Rewind <%s> Save <%s> Pastebin <%s> Editor"
155-
) % (config.undo_key, config.save_key, config.pastebin_key, EDITOR_KEY))
152+
) % (config.undo_key, config.save_key, config.pastebin_key, config.external_editor_key))
156153
self.rl_char_sequences = get_updated_char_sequences(key_dispatch, config)
157154
logging.debug("starting parent init")
158155
super(Repl, self).__init__(interp, config)
@@ -297,7 +294,7 @@ def process_event(self, e):
297294
logging.debug('starting pastebin thread')
298295
t.start()
299296
self.interact.wait_for_request_or_notify()
300-
elif e in key_dispatch[EDITOR_KEY]:
297+
elif e in key_dispatch[self.config.external_editor_key]:
301298
self.send_to_external_editor()
302299
#TODO add PAD keys hack as in bpython.cli
303300
else:
@@ -557,7 +554,7 @@ def paint(self, about_to_exit=False):
557554
self.clean_up_current_line_for_exit() # exception to not changing state!
558555

559556
width, min_height = self.width, self.height
560-
show_status_bar = bool(self.status_bar.current_line)
557+
show_status_bar = bool(self.status_bar.current_line) and (self.config.scroll_fill_terminal or self.status_bar.has_focus)
561558
if show_status_bar:
562559
min_height -= 1
563560

@@ -604,37 +601,44 @@ def paint(self, about_to_exit=False):
604601
#infobox not properly expanding window! try reduce( docs about halfway down a 80x24 terminal
605602
#TODO what's the desired behavior here? Currently uses only the space already on screen,
606603
# scrolling down only if there would have been more space above the current line, but being forced to put below
604+
#TODO above description is not accurate - sometimes screen scrolls for docstring message
607605
logging.debug('infobox display code running')
608606
visible_space_above = history.height
609607
visible_space_below = min_height - cursor_row - 1
610608

611609
info_max_rows = max(visible_space_above, visible_space_below)
612610
infobox = paint.paint_infobox(info_max_rows, int(width * self.config.cli_suggestion_width), self.matches, self.argspec, self.current_word, self.docstring, self.config)
613611

614-
if visible_space_above >= infobox.height and not INFOBOX_ONLY_BELOW:
612+
if visible_space_above >= infobox.height and self.config.scroll_list_above:
615613
arr[current_line_start_row - infobox.height:current_line_start_row, 0:infobox.width] = infobox
616614
else:
617615
arr[cursor_row + 1:cursor_row + 1 + infobox.height, 0:infobox.width] = infobox
618616
logging.debug('slamming infobox of shape %r into arr of shape %r', infobox.shape, arr.shape)
619617

620618
logging.debug('about to exit: %r', about_to_exit)
621619
if show_status_bar:
622-
if about_to_exit:
623-
arr[max(arr.height, min_height), :] = FSArray(1, width)
620+
if self.config.scroll_fill_terminal:
621+
if about_to_exit:
622+
arr[max(arr.height, min_height), :] = FSArray(1, width)
623+
else:
624+
arr[max(arr.height, min_height), :] = paint.paint_statusbar(1, width, self.status_bar.current_line, self.config)
625+
626+
if self.presentation_mode:
627+
rows = arr.height
628+
columns = arr.width
629+
last_key_box = paint.paint_last_events(rows, columns, [pp_event(x) for x in self.last_events if x])
630+
arr[arr.height-last_key_box.height:arr.height, arr.width-last_key_box.width:arr.width] = last_key_box
624631
else:
625-
arr[max(arr.height, min_height), :] = paint.paint_statusbar(1, width, self.status_bar.current_line, self.config)
626-
627-
if self.presentation_mode:
628-
rows = arr.height
629-
columns = arr.width
630-
last_key_box = paint.paint_last_events(rows, columns, [pp_event(x) for x in self.last_events if x])
631-
arr[arr.height-last_key_box.height:arr.height, arr.width-last_key_box.width:arr.width] = last_key_box
632-
#logging.debug(last_key_box[:])
633-
#logging.debug(arr[:])
632+
statusbar_row = min_height + 1 if arr.height == min_height else arr.height
633+
if about_to_exit:
634+
arr[statusbar_row, :] = FSArray(1, width)
635+
else:
636+
arr[statusbar_row, :] = paint.paint_statusbar(1, width, self.status_bar.current_line, self.config)
634637

635638
if self.config.color_scheme['background'] not in ('d', 'D'):
636639
for r in range(arr.height):
637640
arr[r] = fmtstr(arr[r], bg=color_for_letter(self.config.color_scheme['background']))
641+
logging.debug('returning arr of size %r', arr.shape)
638642
return arr, (cursor_row, cursor_column)
639643

640644
## Debugging shims

doc/sphinx/source/configuration-options.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,20 @@ Default: Monospace 10
259259

260260
The font to be used by the GTK version.
261261

262+
scroll
263+
------
264+
This refers to the ``[scroll]`` section in your config file.
265+
266+
.. versionadded:: 0.13
267+
268+
fill_terminal
269+
^^^^^^^^^^^^^
270+
Default: True
271+
272+
Whether bpython should take up the whole terminal, and always display a status bar at the bottom.
273+
274+
list_above
275+
^^^^^^^^^^
276+
Default: False
277+
278+
When there is space above the current line, whether the suggestions list will be displayed there instead of below the current line.

0 commit comments

Comments
 (0)
X Tutup