MCPcopy
hub / github.com/ycm-core/YouCompleteMe / PresentDialog

Function PresentDialog

python/ycm/vimsupport.py:767–798  ·  view source on GitHub ↗

Presents the user with a dialog where a choice can be made. This will be a dialog for gvim users or a question in the message buffer for vim users or if `set guioptions+=c` was used. choices is list of alternatives. default_choice_index is the 0-based index of the default element that wil

( message, choices, default_choice_index = 0 )

Source from the content-addressed store, hash-verified

765
766
767def PresentDialog( message, choices, default_choice_index = 0 ):
768 """Presents the user with a dialog where a choice can be made.
769 This will be a dialog for gvim users or a question in the message buffer
770 for vim users or if `set guioptions+=c` was used.
771
772 choices is list of alternatives.
773 default_choice_index is the 0-based index of the default element
774 that will get choosen if the user hits <CR>. Use -1 for no default.
775
776 PresentDialog will return a 0-based index into the list
777 or -1 if the dialog was dismissed by using <Esc>, Ctrl-C, etc.
778
779 If you are presenting a list of options for the user to choose from, such as
780 a list of imports, or lines to insert (etc.), SelectFromList is a better
781 option.
782
783 See also:
784 :help confirm() in vim (Note that vim uses 1-based indexes)
785
786 Example call:
787 PresentDialog("Is this a nice example?", ["Yes", "No", "May&be"])
788 Is this a nice example?
789 [Y]es, (N)o, May(b)e:"""
790 message = EscapeForVim( ToUnicode( message ) )
791 choices = EscapeForVim( ToUnicode( '\n'.join( choices ) ) )
792 to_eval = ( f"confirm( '{ message }', "
793 f"'{ choices }', "
794 f"{ default_choice_index + 1 } )" )
795 try:
796 return GetIntValue( to_eval ) - 1
797 except KeyboardInterrupt:
798 return -1
799
800
801def Confirm( message ):

Callers 1

ConfirmFunction · 0.85

Calls 2

EscapeForVimFunction · 0.85
GetIntValueFunction · 0.85

Tested by

no test coverage detected