@@ -29,12 +29,11 @@ def __init__(self):
2929 super ().__init__ (use_ipython = True )
3030 self ._set_prompt ()
3131 self .intro = 'Happy 𝛑 Day. Note the full Unicode support: 😇 💩'
32- self .self_in_py = True
3332
3433 def _set_prompt (self ):
3534 """Set prompt so it displays the current working directory."""
3635 self .cwd = os .getcwd ()
37- self .prompt = ansi .style ('{!r } $ '. format ( self . cwd ) , fg = 'cyan' )
36+ self .prompt = ansi .style (f' { self . cwd } $ ' , fg = 'cyan' )
3837
3938 def postcmd (self , stop : bool , line : str ) -> bool :
4039 """Hook method executed just after a command dispatch is finished.
@@ -57,33 +56,31 @@ def do_cd(self, arglist):
5756 if not arglist or len (arglist ) != 1 :
5857 self .perror ("cd requires exactly 1 argument:" )
5958 self .do_help ('cd' )
60- self .last_result = cmd2 . CommandResult ( '' , ' Bad arguments')
59+ self .last_result = ' Bad arguments'
6160 return
6261
6362 # Convert relative paths to absolute paths
6463 path = os .path .abspath (os .path .expanduser (arglist [0 ]))
6564
6665 # Make sure the directory exists, is a directory, and we have read access
67- out = ''
6866 err = None
6967 data = None
7068 if not os .path .isdir (path ):
71- err = '{!r } is not a directory'. format ( path )
69+ err = f' { path } is not a directory'
7270 elif not os .access (path , os .R_OK ):
73- err = 'You do not have read access to {!r}' . format ( path )
71+ err = f 'You do not have read access to { path } '
7472 else :
7573 try :
7674 os .chdir (path )
7775 except Exception as ex :
78- err = '{}' . format ( ex )
76+ err = f' { ex } '
7977 else :
80- out = 'Successfully changed directory to {!r}\n ' .format (path )
81- self .stdout .write (out )
78+ self .poutput (f'Successfully changed directory to { path } ' )
8279 data = path
8380
8481 if err :
8582 self .perror (err )
86- self .last_result = cmd2 . CommandResult ( out , err , data )
83+ self .last_result = data
8784
8885 # Enable tab completion for cd command
8986 def complete_cd (self , text , line , begidx , endidx ):
@@ -100,20 +97,17 @@ def do_dir(self, args, unknown):
10097 if unknown :
10198 self .perror ("dir does not take any positional arguments:" )
10299 self .do_help ('dir' )
103- self .last_result = cmd2 . CommandResult ( '' , ' Bad arguments')
100+ self .last_result = ' Bad arguments'
104101 return
105102
106103 # Get the contents as a list
107104 contents = os .listdir (self .cwd )
108105
109- fmt = '{} '
110- if args .long :
111- fmt = '{}\n '
112106 for f in contents :
113- self .stdout . write ( fmt . format ( f ) )
114- self .stdout . write ( ' \n ' )
107+ self .poutput ( f' { f } ' )
108+ self .poutput ( ' ' )
115109
116- self .last_result = cmd2 . CommandResult ( data = contents )
110+ self .last_result = contents
117111
118112
119113if __name__ == '__main__' :
0 commit comments