1313from  prompt_toolkit .layout .margins  import  Margin 
1414from  prompt_toolkit .layout .menus  import  CompletionsMenu , MultiColumnCompletionsMenu 
1515from  prompt_toolkit .layout .highlighters  import  SearchHighlighter , SelectionHighlighter , MatchingBracketHighlighter , ConditionalHighlighter 
16- from  prompt_toolkit .layout .processors  import  HighlightMatchingBracketProcessor ,  ConditionalProcessor , AppendAutoSuggestion 
16+ from  prompt_toolkit .layout .processors  import  ConditionalProcessor , AppendAutoSuggestion 
1717from  prompt_toolkit .layout .screen  import  Char 
1818from  prompt_toolkit .layout .toolbars  import  CompletionsToolbar , ArgToolbar , SearchToolbar , ValidationToolbar , SystemToolbar , TokenListToolbar 
1919from  prompt_toolkit .layout .utils  import  token_list_width 
20- from  prompt_toolkit .mouse_events  import  MouseEventTypes 
2120from  prompt_toolkit .reactive  import  Integer 
2221from  prompt_toolkit .selection  import  SelectionType 
2322from  prompt_toolkit .utils  import  get_cwidth 
2423
25- from  ptpython .filters  import  HasSignature , ShowSidebar , ShowSignature , ShowDocstring 
24+ from  .filters  import  HasSignature , ShowSidebar , ShowSignature , ShowDocstring 
25+ from  .utils  import  if_mousedown 
2626
2727from  pygments .lexers  import  PythonLexer 
2828from  pygments .token  import  Token 
@@ -71,18 +71,31 @@ def append_category(category):
7171                (T , '\n ' ),
7272            ])
7373
74-         def  append (selected , label , status ):
74+         def  append (index , label , status ):
75+             selected  =  index  ==  python_input .selected_option_index 
76+ 
77+             @if_mousedown  
78+             def  select_item (cli , mouse_event ):
79+                 python_input .selected_option_index  =  index 
80+ 
81+             @if_mousedown  
82+             def  goto_next (cli , mouse_event ):
83+                 " Select item and go to next value. " 
84+                 python_input .selected_option_index  =  index 
85+                 option  =  python_input .selected_option 
86+                 option .activate_next ()
87+ 
7588            token  =  T .Selected  if  selected  else  T 
7689
7790            tokens .append ((T , ' >'  if  selected  else  '  ' ))
78-             tokens .append ((token .Label , '%-24s'  %  label ))
79-             tokens .append ((token .Status , ' ' ))
80-             tokens .append ((token .Status , '%s'  %  status ))
91+             tokens .append ((token .Label , '%-24s'  %  label ,  select_item ))
92+             tokens .append ((token .Status , ' ' ,  select_item ))
93+             tokens .append ((token .Status , '%s'  %  status ,  goto_next ))
8194
8295            if  selected :
8396                tokens .append ((Token .SetCursorPosition , '' ))
8497
85-             tokens .append ((token .Status , ' '  *  (14  -  len (status ))))
98+             tokens .append ((token .Status , ' '  *  (14  -  len (status )),  goto_next ))
8699            tokens .append ((T , '<'  if  selected  else  '' ))
87100            tokens .append ((T , '\n ' ))
88101
@@ -91,8 +104,7 @@ def append(selected, label, status):
91104            append_category (category )
92105
93106            for  option  in  category .options :
94-                 append (i  ==  python_input .selected_option_index ,
95-                        option .title , '%s'  %  option .get_current_value ())
107+                 append (i , option .title , '%s'  %  option .get_current_value ())
96108                i  +=  1 
97109
98110        tokens .pop ()  # Remove last newline. 
@@ -282,11 +294,13 @@ def status_bar(key_bindings_manager, python_input):
282294    """ 
283295    TB  =  Token .Toolbar .Status 
284296
297+     @if_mousedown  
285298    def  toggle_paste_mode (cli , mouse_event ):
286-         if  mouse_event .event_type  ==  MouseEventTypes .MOUSE_DOWN :
287-             python_input .paste_mode  =  not  python_input .paste_mode 
288-         else :
289-             return  NotImplemented 
299+         python_input .paste_mode  =  not  python_input .paste_mode 
300+ 
301+     @if_mousedown  
302+     def  enter_history (cli , mouse_event ):
303+         python_input .enter_history (cli )
290304
291305    def  get_tokens (cli ):
292306        python_buffer  =  cli .buffers [DEFAULT_BUFFER ]
@@ -310,8 +324,8 @@ def get_tokens(cli):
310324            append ((TB , '[Ctrl-W] Cut [Meta-W] Copy [Ctrl-Y] Paste [Ctrl-G] Cancel' ))
311325        else :
312326            result .extend ([
313-                 (TB .Key , '[F3]' ),
314-                 (TB , ' History ' ),
327+                 (TB .Key , '[F3]' ,  enter_history ),
328+                 (TB , ' History ' ,  enter_history ),
315329                (TB .Key , '[F6]' , toggle_paste_mode ),
316330                (TB , ' ' , toggle_paste_mode ),
317331            ])
@@ -338,11 +352,9 @@ def get_inputmode_tokens(cli, python_input):
338352
339353    :param cli: `CommandLineInterface` instance. 
340354    """ 
355+     @if_mousedown  
341356    def  toggle_vi_mode (cli , mouse_event ):
342-         if  mouse_event .event_type  ==  MouseEventTypes .MOUSE_DOWN :
343-             python_input .vi_mode  =  not  python_input .vi_mode 
344-         else :
345-             return  NotImplemented 
357+         python_input .vi_mode  =  not  python_input .vi_mode 
346358
347359    token  =  Token .Toolbar .Status 
348360
@@ -381,12 +393,10 @@ def show_sidebar_button_info(python_input):
381393    Create `Layout` for the information in the right-bottom corner. 
382394    (The right part of the status bar.) 
383395    """ 
396+     @if_mousedown  
384397    def  toggle_sidebar (cli , mouse_event ):
385398        " Click handler for the menu. " 
386-         if  mouse_event .event_type  ==  MouseEventTypes .MOUSE_DOWN :
387-             python_input .show_sidebar  =  not  python_input .show_sidebar 
388-         else :
389-             return  NotImplemented 
399+         python_input .show_sidebar  =  not  python_input .show_sidebar 
390400
391401    token  =  Token .Toolbar .Status 
392402
0 commit comments