cli: add history and SIGINT mgmt

parent 18f5c601
......@@ -3,6 +3,7 @@
import cmd
import readline
import os.path
import pdb
from ctypes import *
......@@ -25,6 +26,7 @@ class OauTest(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
self.solib = './liboasis-usb-att.so'
self.history = os.path.expanduser('~/.oau_history')
self.api = CDLL(self.solib)
self.lun = None
self.fd = None
......@@ -100,6 +102,26 @@ class OauTest(cmd.Cmd):
def do_EOF(self, arg):
return True
def my_preloop(self):
try:
readline.read_history_file(self.history)
except FileNotFoundError:
readline.write_history_file(self.history)
def my_postloop(self):
readline.write_history_file(self.history)
# catch Ctrl-C and drop me back into cli
def cmdloop_intr(self, intro=None):
self.my_preloop()
while True:
try:
self.cmdloop()
break
except KeyboardInterrupt as e:
self.intro = None
print('^C')
self.my_postloop()
do_q = do_EOF
do_h = cmd.Cmd.do_help
......@@ -107,7 +129,7 @@ class OauTest(cmd.Cmd):
if __name__ == '__main__':
cli = OauTest()
cli.cmdloop()
cli.cmdloop_intr()
if False:
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment