dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

history.py (1778B)


      1 from talon import imgui, Module, speech_system, actions, app
      2 
      3 # We keep command_history_size lines of history, but by default display only
      4 # command_history_display of them.
      5 mod = Module()
      6 setting_command_history_size = mod.setting("command_history_size", int, default=50)
      7 setting_command_history_display = mod.setting(
      8     "command_history_display", int, default=10
      9 )
     10 
     11 hist_more = False
     12 history = []
     13 
     14 
     15 def parse_phrase(word_list):
     16     return " ".join(word.split("\\")[0] for word in word_list)
     17 
     18 
     19 def on_phrase(j):
     20     global history
     21 
     22     try:
     23         val = parse_phrase(getattr(j["parsed"], "_unmapped", j["phrase"]))
     24     except:
     25         val = parse_phrase(j["phrase"])
     26 
     27     if val != "":
     28         history.append(val)
     29         history = history[-setting_command_history_size.get() :]
     30 
     31 
     32 # todo: dynamic rect?
     33 @imgui.open(y=0)
     34 def gui(gui: imgui.GUI):
     35     global history
     36     gui.text("Command History")
     37     gui.line()
     38     text = (
     39         history[:] if hist_more else history[-setting_command_history_display.get() :]
     40     )
     41     for line in text:
     42         gui.text(line)
     43 
     44 
     45 speech_system.register("phrase", on_phrase)
     46 
     47 
     48 @mod.action_class
     49 class Actions:
     50     def history_toggle():
     51         """Toggles viewing the history"""
     52         if gui.showing:
     53             gui.hide()
     54         else:
     55             gui.show()
     56 
     57     def history_enable():
     58         """Enables the history"""
     59         gui.show()
     60 
     61     def history_disable():
     62         """Disables the history"""
     63         gui.hide()
     64 
     65     def history_clear():
     66         """Clear the history"""
     67         global history
     68         history = []
     69 
     70     def history_more():
     71         """Show more history"""
     72         global hist_more
     73         hist_more = True
     74 
     75     def history_less():
     76         """Show less history"""
     77         global hist_more
     78         hist_more = False