kete: persistent history
We write down the history immediatelly after receiving a new command, just in case something bad happens. Fixes #54
This commit is contained in:
parent
cc08607025
commit
752a283e00
|
@ -24,6 +24,10 @@ import readline
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import svgwrite
|
import svgwrite
|
||||||
|
import xdg.BaseDirectory
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_PATH = os.path.join(xdg.BaseDirectory.xdg_data_home, 'tuhi-kete')
|
||||||
|
|
||||||
|
|
||||||
class ColorFormatter(logging.Formatter):
|
class ColorFormatter(logging.Formatter):
|
||||||
|
@ -562,6 +566,20 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
# patching get_names to hide some functions we do not want in the help
|
# patching get_names to hide some functions we do not want in the help
|
||||||
self.get_names = self._filtered_get_names
|
self.get_names = self._filtered_get_names
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir(CONFIG_PATH)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
self._history_file = os.path.join(CONFIG_PATH, 'history')
|
||||||
|
|
||||||
|
try:
|
||||||
|
readline.read_history_file(self._history_file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
readline.write_history_file(self._history_file)
|
||||||
|
|
||||||
|
readline.set_history_length(100)
|
||||||
|
|
||||||
Gio.bus_watch_name(Gio.BusType.SESSION,
|
Gio.bus_watch_name(Gio.BusType.SESSION,
|
||||||
TUHI_DBUS_NAME,
|
TUHI_DBUS_NAME,
|
||||||
Gio.BusNameWatcherFlags.NONE,
|
Gio.BusNameWatcherFlags.NONE,
|
||||||
|
@ -622,6 +640,8 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
if self._manager is None and line not in ['EOF', 'exit', 'help']:
|
if self._manager is None and line not in ['EOF', 'exit', 'help']:
|
||||||
print('Not connected to the Tuhi daemon')
|
print('Not connected to the Tuhi daemon')
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
readline.write_history_file(self._history_file)
|
||||||
return line
|
return line
|
||||||
|
|
||||||
def postcmd(self, stop, line):
|
def postcmd(self, stop, line):
|
||||||
|
|
Loading…
Reference in New Issue