Consider this minimal program that uses the cmd
module:
import cmd
class Shell(cmd.Cmd):
def do_input(self, _arg):
'''Ask the user to input a string.'''
s = input('String: ')
print(s)
if __name__ == '__main__':
Shell().cmdloop()
Here's a sample interaction with this program:
(Cmd) input
String: Hello!
Hello!
(Cmd)
Now the problem is that upon pressing the up keyboard button, the last history item is from the user input (i.e. Hello!
) rather than from the shell's prompt (i.e. input
).
The question is: How can I get only the history of commands entered at the shell prompt (without the history of inputs entered using input()
)?