@@ -69,8 +69,18 @@ def prompt_bool(name, default=False, yes_choices=None, no_choices=None):
6969    yes_choices  =  yes_choices  or  ('y' , 'yes' , '1' , 'on' , 'true' , 't' )
7070    no_choices  =  no_choices  or  ('n' , 'no' , '0' , 'off' , 'false' , 'f' )
7171
72+     if  default  is  None :
73+         prompt_choice  =  'y/n' 
74+     elif  default  is  True :
75+         prompt_choice  =  'Y/n' 
76+     else :
77+         prompt_choice  =  'y/N' 
78+ 
79+     prompt  =  name  +  ' [%s]'  %  prompt_choice 
80+     prompt  +=  name .endswith ('?' ) and  ' '  or  ': ' 
81+ 
7282    while  True :
73-         rv  =  prompt ( name ,  default   and   yes_choices [ 0 ]  or   no_choices [ 0 ] )
83+         rv  =  input ( prompt )
7484        if  not  rv :
7585            return  default 
7686        if  rv .lower () in  yes_choices :
@@ -80,11 +90,7 @@ def prompt_bool(name, default=False, yes_choices=None, no_choices=None):
8090
8191
8292def  prompt_yes_no (name , default = True ):
83-     return  prompt_bool (name ,
84-                        default = default ,
85-                        yes_choices = ['Y' , 'y' ],
86-                        no_choices = ['n' ]
87-                        )
93+     return  prompt_bool (name , default = default )
8894
8995def  prompt_choices (name , choices , default = None , resolve = ascii_lowercase ,
9096                   no_choice = ('none' ,)):
@@ -236,15 +242,15 @@ def load_workspace(config_file, args):
236242        builder .build ()
237243
238244        if  'TMUX'  in  os .environ :
239-             if  prompt_yes_no ('Already inside TMUX, load session?' ,  default = 'Y' ):
245+             if  prompt_yes_no ('Already inside TMUX, load session?' ):
240246                del  os .environ ['TMUX' ]
241247                os .execl (tmux_bin , 'tmux' , 'switch-client' , '-t' , sconfig [
242248                         'session_name' ])
243249
244250        os .execl (tmux_bin , 'tmux' , 'attach-session' , '-t' , sconfig [
245251                 'session_name' ])
246252    except  exc .TmuxSessionExists  as  e :
247-         attach_session  =  prompt_yes_no (e .message  +  ' Attach?' ,  default = 'Y' )
253+         attach_session  =  prompt_yes_no (e .message  +  ' Attach?' )
248254
249255        if  'TMUX'  in  os .environ :
250256            del  os .environ ['TMUX' ]
@@ -408,26 +414,26 @@ def command_convert(args):
408414        return 
409415
410416    if  'json'  in  ext :
411-         if  prompt_yes_no ('convert to <%s> to yaml?'  %  (fullfile ),  default = 'Y' ):
417+         if  prompt_yes_no ('convert to <%s> to yaml?'  %  (fullfile )):
412418            configparser  =  kaptan .Kaptan ()
413419            configparser .import_config (configfile )
414420            newfile  =  fullfile .replace (ext , '.yaml' )
415421            newconfig  =  configparser .export (
416422                'yaml' , indent = 2 , default_flow_style = False 
417423            )
418-             if  prompt_yes_no ('write config to %s?'  %  (newfile ),  default = 'Y' ):
424+             if  prompt_yes_no ('write config to %s?'  %  (newfile )):
419425                buf  =  open (newfile , 'w' )
420426                buf .write (newconfig )
421427                buf .close ()
422428                print ('written new config to %s'  %  (newfile ))
423429    elif  'yaml'  in  ext :
424-         if  prompt_yes_no ('convert to <%s> to json?'  %  (fullfile ),  default = 'Y' ):
430+         if  prompt_yes_no ('convert to <%s> to json?'  %  (fullfile )):
425431            configparser  =  kaptan .Kaptan ()
426432            configparser .import_config (configfile )
427433            newfile  =  fullfile .replace (ext , '.json' )
428434            newconfig  =  configparser .export ('json' , indent = 2 )
429435            print (newconfig )
430-             if  prompt_yes_no ('write config to <%s>?'  %  (newfile ),  default = 'Y' ):
436+             if  prompt_yes_no ('write config to <%s>?'  %  (newfile )):
431437                buf  =  open (newfile , 'w' )
432438                buf .write (newconfig )
433439                buf .close ()
0 commit comments