1212from prompt_toolkit .document import Document
1313from prompt_toolkit .enums import DEFAULT_BUFFER
1414from prompt_toolkit .filters import Condition , has_focus
15+ from prompt_toolkit .formatted_text .utils import fragment_list_to_text
1516from 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
1718from prompt_toolkit .layout .controls import BufferControl , FormattedTextControl
1819from prompt_toolkit .layout .dimension import Dimension as D
1920from prompt_toolkit .layout .layout import Layout
20- from prompt_toolkit .layout .lexers import PygmentsLexer
2121from 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
2626from pygments .lexers import RstLexer
2727
2828from .utils import if_mousedown
@@ -110,34 +110,29 @@ class HistoryLayout(object):
110110 application.
111111 """
112112 def __init__ (self , history ):
113- default_processors = [
114- HighlightSearchProcessor (preview_search = True ),
115- HighlightSelectionProcessor ()
116- ]
113+ search_toolbar = SearchToolbar ()
117114
118115 self .help_buffer_control = BufferControl (
119116 buffer = history .help_buffer ,
120- lexer = PygmentsLexer (RstLexer ),
121- input_processor = merge_processors (default_processors ))
117+ lexer = PygmentsLexer (RstLexer ))
122118
123119 help_window = _create_popup_window (
124120 title = 'History Help' ,
125121 body = Window (
126122 content = self .help_buffer_control ,
127123 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 )))
130125
131126 self .default_buffer_control = BufferControl (
132127 buffer = history .default_buffer ,
133- input_processor = merge_processors (
134- default_processors + [GrayExistingText (history .history_mapping )]),
128+ input_processors = [GrayExistingText (history .history_mapping )],
135129 lexer = PygmentsLexer (PythonLexer ))
136130
137131 self .history_buffer_control = BufferControl (
138132 buffer = history .history_buffer ,
139133 lexer = PygmentsLexer (PythonLexer ),
140- input_processor = merge_processors (default_processors ))
134+ search_buffer_control = search_toolbar .control ,
135+ preview_search = True )
141136
142137 history_window = Window (
143138 content = self .history_buffer_control ,
@@ -149,7 +144,7 @@ def __init__(self, history):
149144 # Top title bar.
150145 Window (
151146 content = FormattedTextControl (_get_top_toolbar_fragments ),
152- align = Align .CENTER ,
147+ align = WindowAlign .CENTER ,
153148 style = 'class:status-toolbar' ),
154149 FloatContainer (
155150 content = VSplit ([
@@ -170,16 +165,12 @@ def __init__(self, history):
170165 # Help text as a float.
171166 Float (width = 60 , top = 3 , bottom = 2 ,
172167 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 ))),
178169 ]
179170 ),
180171 # Bottom toolbars.
181172 ArgToolbar (),
182- # SearchToolbar(), # XXX
173+ search_toolbar ,
183174 Window (
184175 content = FormattedTextControl (
185176 partial (_get_bottom_toolbar_fragments , history = history )),
@@ -338,15 +329,16 @@ def __init__(self, history, python_history, original_document):
338329 self .selected_lines = set ()
339330
340331 # Process history.
332+ history_strings = python_history .get_strings ()
341333 history_lines = []
342334
343- for entry_nr , entry in list (enumerate (python_history ))[- HISTORY_COUNT :]:
335+ for entry_nr , entry in list (enumerate (history_strings ))[- HISTORY_COUNT :]:
344336 self .lines_starting_new_entries .add (len (history_lines ))
345337
346338 for line in entry .splitlines ():
347339 history_lines .append (line )
348340
349- if len (python_history ) > HISTORY_COUNT :
341+ if len (history_strings ) > HISTORY_COUNT :
350342 history_lines [0 ] = '# *** History has been truncated to %s lines ***' % HISTORY_COUNT
351343
352344 self .history_lines = history_lines
@@ -501,12 +493,12 @@ def _(event):
501493 @handle ('c-g' , filter = main_buffer_focussed )
502494 def _ (event ):
503495 " Cancel and go back. "
504- event .app .set_return_value ( None )
496+ event .app .exit ( result = None )
505497
506498 @handle ('enter' , filter = main_buffer_focussed )
507499 def _ (event ):
508500 " Accept input. "
509- event .app .set_return_value ( history .default_buffer .text )
501+ event .app .exit ( result = history .default_buffer .text )
510502
511503 enable_system_bindings = Condition (lambda : python_input .enable_system_bindings )
512504
@@ -540,7 +532,7 @@ def __init__(self, python_input, original_document):
540532 document = document ,
541533 on_cursor_position_changed = self ._history_buffer_pos_changed ,
542534 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 )),
544536 read_only = True )
545537
546538 self .default_buffer = Buffer (
0 commit comments