12
12
from prompt_toolkit .document import Document
13
13
from prompt_toolkit .enums import DEFAULT_BUFFER
14
14
from prompt_toolkit .filters import Condition , has_focus
15
+ from prompt_toolkit .formatted_text .utils import fragment_list_to_text
15
16
from prompt_toolkit .key_binding import KeyBindings
16
- from prompt_toolkit .layout .containers import HSplit , VSplit , Window , FloatContainer , Float , ConditionalContainer , Container , ScrollOffsets , Align
17
+ from prompt_toolkit .layout .containers import HSplit , VSplit , Window , FloatContainer , Float , ConditionalContainer , Container , ScrollOffsets , WindowAlign
17
18
from prompt_toolkit .layout .controls import BufferControl , FormattedTextControl
18
19
from prompt_toolkit .layout .dimension import Dimension as D
19
20
from prompt_toolkit .layout .layout import Layout
20
- from prompt_toolkit .layout .lexers import PygmentsLexer
21
21
from prompt_toolkit .layout .margins import Margin , ScrollbarMargin
22
- from prompt_toolkit .layout .processors import Processor , Transformation , HighlightSearchProcessor , HighlightSelectionProcessor , merge_processors
23
- from prompt_toolkit .layout . widgets . toolbars import ArgToolbar , SearchToolbar
24
- from prompt_toolkit .layout . utils import fragment_list_to_text
25
- from prompt_toolkit .layout . widgets import Frame
22
+ from prompt_toolkit .layout .processors import Processor , Transformation
23
+ from prompt_toolkit .lexers import PygmentsLexer
24
+ from prompt_toolkit .widgets import Frame
25
+ from prompt_toolkit .widgets . toolbars import ArgToolbar , SearchToolbar
26
26
from pygments .lexers import RstLexer
27
27
28
28
from .utils import if_mousedown
@@ -110,34 +110,29 @@ class HistoryLayout(object):
110
110
application.
111
111
"""
112
112
def __init__ (self , history ):
113
- default_processors = [
114
- HighlightSearchProcessor (preview_search = True ),
115
- HighlightSelectionProcessor ()
116
- ]
113
+ search_toolbar = SearchToolbar ()
117
114
118
115
self .help_buffer_control = BufferControl (
119
116
buffer = history .help_buffer ,
120
- lexer = PygmentsLexer (RstLexer ),
121
- input_processor = merge_processors (default_processors ))
117
+ lexer = PygmentsLexer (RstLexer ))
122
118
123
119
help_window = _create_popup_window (
124
120
title = 'History Help' ,
125
121
body = Window (
126
122
content = self .help_buffer_control ,
127
123
right_margins = [ScrollbarMargin (display_arrows = True )],
128
- scroll_offsets = ScrollOffsets (top = 2 , bottom = 2 ),
129
- transparent = False ))
124
+ scroll_offsets = ScrollOffsets (top = 2 , bottom = 2 )))
130
125
131
126
self .default_buffer_control = BufferControl (
132
127
buffer = history .default_buffer ,
133
- input_processor = merge_processors (
134
- default_processors + [GrayExistingText (history .history_mapping )]),
128
+ input_processors = [GrayExistingText (history .history_mapping )],
135
129
lexer = PygmentsLexer (PythonLexer ))
136
130
137
131
self .history_buffer_control = BufferControl (
138
132
buffer = history .history_buffer ,
139
133
lexer = PygmentsLexer (PythonLexer ),
140
- input_processor = merge_processors (default_processors ))
134
+ search_buffer_control = search_toolbar .control ,
135
+ preview_search = True )
141
136
142
137
history_window = Window (
143
138
content = self .history_buffer_control ,
@@ -149,7 +144,7 @@ def __init__(self, history):
149
144
# Top title bar.
150
145
Window (
151
146
content = FormattedTextControl (_get_top_toolbar_fragments ),
152
- align = Align .CENTER ,
147
+ align = WindowAlign .CENTER ,
153
148
style = 'class:status-toolbar' ),
154
149
FloatContainer (
155
150
content = VSplit ([
@@ -170,16 +165,12 @@ def __init__(self, history):
170
165
# Help text as a float.
171
166
Float (width = 60 , top = 3 , bottom = 2 ,
172
167
content = ConditionalContainer (
173
- # XXXX XXX
174
- # (We use InFocusStack, because it's possible to search
175
- # through the help text as well, and at that point the search
176
- # buffer has the focus.)
177
- content = help_window , filter = has_focus (history .help_buffer ))), # XXX
168
+ content = help_window , filter = has_focus (history .help_buffer ))),
178
169
]
179
170
),
180
171
# Bottom toolbars.
181
172
ArgToolbar (),
182
- # SearchToolbar(), # XXX
173
+ search_toolbar ,
183
174
Window (
184
175
content = FormattedTextControl (
185
176
partial (_get_bottom_toolbar_fragments , history = history )),
@@ -338,15 +329,16 @@ def __init__(self, history, python_history, original_document):
338
329
self .selected_lines = set ()
339
330
340
331
# Process history.
332
+ history_strings = python_history .get_strings ()
341
333
history_lines = []
342
334
343
- for entry_nr , entry in list (enumerate (python_history ))[- HISTORY_COUNT :]:
335
+ for entry_nr , entry in list (enumerate (history_strings ))[- HISTORY_COUNT :]:
344
336
self .lines_starting_new_entries .add (len (history_lines ))
345
337
346
338
for line in entry .splitlines ():
347
339
history_lines .append (line )
348
340
349
- if len (python_history ) > HISTORY_COUNT :
341
+ if len (history_strings ) > HISTORY_COUNT :
350
342
history_lines [0 ] = '# *** History has been truncated to %s lines ***' % HISTORY_COUNT
351
343
352
344
self .history_lines = history_lines
@@ -501,12 +493,12 @@ def _(event):
501
493
@handle ('c-g' , filter = main_buffer_focussed )
502
494
def _ (event ):
503
495
" Cancel and go back. "
504
- event .app .set_return_value ( None )
496
+ event .app .exit ( result = None )
505
497
506
498
@handle ('enter' , filter = main_buffer_focussed )
507
499
def _ (event ):
508
500
" Accept input. "
509
- event .app .set_return_value ( history .default_buffer .text )
501
+ event .app .exit ( result = history .default_buffer .text )
510
502
511
503
enable_system_bindings = Condition (lambda : python_input .enable_system_bindings )
512
504
@@ -540,7 +532,7 @@ def __init__(self, python_input, original_document):
540
532
document = document ,
541
533
on_cursor_position_changed = self ._history_buffer_pos_changed ,
542
534
accept_handler = (
543
- lambda buff : get_app ().set_return_value ( self .default_buffer .text )),
535
+ lambda buff : get_app ().exit ( result = self .default_buffer .text )),
544
536
read_only = True )
545
537
546
538
self .default_buffer = Buffer (
0 commit comments