Add macros, implement modestack for popupmessages within popups
This commit is contained in:
parent
3ea653fc6f
commit
0a82d58de7
@ -79,7 +79,7 @@ class Drawtool():
|
|||||||
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box, self.main_view.colors["error"])
|
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box, self.main_view.colors["error"])
|
||||||
else:
|
else:
|
||||||
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box)
|
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box)
|
||||||
elif self.main_view.mode == "popup":
|
elif self.main_view.mode in ["popup", "popupmessage"]:
|
||||||
_, question = self.main_view.popup
|
_, question = self.main_view.popup
|
||||||
self.stdscr.addstr(self.H - 1, 0, question)
|
self.stdscr.addstr(self.H - 1, 0, question)
|
||||||
elif self.main_view.mode == "vimmode":
|
elif self.main_view.mode == "vimmode":
|
||||||
|
58
mainview.py
58
mainview.py
@ -27,6 +27,10 @@ class MainView():
|
|||||||
# self.client.add_event_handler(self.on_read, events.MessageRead)
|
# self.client.add_event_handler(self.on_read, events.MessageRead)
|
||||||
self.text_emojis = True
|
self.text_emojis = True
|
||||||
|
|
||||||
|
self.macros = {}
|
||||||
|
self.macro_recording = None
|
||||||
|
self.macro_sequence = []
|
||||||
|
|
||||||
self.inputs = ""
|
self.inputs = ""
|
||||||
self.inputs_cursor = 0
|
self.inputs_cursor = 0
|
||||||
|
|
||||||
@ -52,6 +56,7 @@ class MainView():
|
|||||||
self.selected_message = None
|
self.selected_message = None
|
||||||
|
|
||||||
self.mode = "normal"
|
self.mode = "normal"
|
||||||
|
self.modestack = []
|
||||||
|
|
||||||
async def quit(self):
|
async def quit(self):
|
||||||
self.fin = True
|
self.fin = True
|
||||||
@ -301,21 +306,29 @@ class MainView():
|
|||||||
subprocess.Popen(["xdg-open", f"{path}"], stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
|
subprocess.Popen(["xdg-open", f"{path}"], stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
|
||||||
|
|
||||||
def popup_message(self, question):
|
def popup_message(self, question):
|
||||||
self.mode = "popup"
|
self.modestack.append(self.mode)
|
||||||
|
self.mode = "popupmessage"
|
||||||
async def action_handler(self, key):
|
async def action_handler(self, key):
|
||||||
self.mode = "normal"
|
pass
|
||||||
self.popup = (action_handler, question)
|
self.popup = (action_handler, question)
|
||||||
|
|
||||||
def spawn_popup(self, action_handler, question):
|
def spawn_popup(self, action_handler, question):
|
||||||
|
# on q press
|
||||||
|
self.modestack.append(self.mode)
|
||||||
self.mode = "popup"
|
self.mode = "popup"
|
||||||
self.popup = (action_handler, question)
|
self.popup = (action_handler, question)
|
||||||
|
|
||||||
async def handle_key(self, key):
|
async def handle_key(self, key, redraw = True):
|
||||||
|
if self.mode == "popupmessage":
|
||||||
|
self.mode = self.modestack.pop()
|
||||||
if not self.ready:
|
if not self.ready:
|
||||||
return
|
return
|
||||||
if key == "RESIZE":
|
if key == "RESIZE":
|
||||||
await self.drawtool.resize()
|
await self.drawtool.resize()
|
||||||
return
|
return
|
||||||
|
if self.macro_recording:
|
||||||
|
if key != "q":
|
||||||
|
self.macro_sequence.append(key)
|
||||||
if self.mode == "search":
|
if self.mode == "search":
|
||||||
if key == "ESCAPE" or key == "RETURN":
|
if key == "ESCAPE" or key == "RETURN":
|
||||||
self.mode = "normal"
|
self.mode = "normal"
|
||||||
@ -360,13 +373,33 @@ class MainView():
|
|||||||
elif key == "RETURN" or key == "y":
|
elif key == "RETURN" or key == "y":
|
||||||
await self.send_message()
|
await self.send_message()
|
||||||
elif key == "q":
|
elif key == "q":
|
||||||
await self.quit()
|
if self.macro_recording == None:
|
||||||
#elif key == "D":
|
# start macro recording
|
||||||
# for i in range(10):
|
async def record_macro(self, key):
|
||||||
# self.select_prev_chat()
|
if "a" < key.lower() < "z":
|
||||||
#elif key == "d":
|
self.macro_recording = key
|
||||||
# for i in range(10):
|
self.popup_message(f"recording into {key}")
|
||||||
# self.select_next_chat()
|
else:
|
||||||
|
self.popup_message(f"Register must be [a-zA-Z]")
|
||||||
|
|
||||||
|
self.spawn_popup(record_macro, "Record into which register?")
|
||||||
|
else:
|
||||||
|
# end macro recording
|
||||||
|
self.macros[self.macro_recording] = self.macro_sequence
|
||||||
|
self.macro_recording = None
|
||||||
|
self.macro_sequence = []
|
||||||
|
elif key == "@":
|
||||||
|
# execute macro
|
||||||
|
async def ask_macro(self, key):
|
||||||
|
if key in self.macros.keys():
|
||||||
|
macro = self.macros[key]
|
||||||
|
debug(macro)
|
||||||
|
for k in macro:
|
||||||
|
await self.handle_key(k, redraw = False)
|
||||||
|
else:
|
||||||
|
self.popup_message(f"No such macro @{key}")
|
||||||
|
|
||||||
|
self.spawn_popup(ask_macro, "Execute which macro?")
|
||||||
elif key == "C":
|
elif key == "C":
|
||||||
self.select_prev_chat()
|
self.select_prev_chat()
|
||||||
elif key == "c":
|
elif key == "c":
|
||||||
@ -436,6 +469,8 @@ class MainView():
|
|||||||
self.drawtool.show_indices ^= True
|
self.drawtool.show_indices ^= True
|
||||||
elif self.mode == "popup":
|
elif self.mode == "popup":
|
||||||
action, _ = self.popup
|
action, _ = self.popup
|
||||||
|
# I think this could break
|
||||||
|
self.mode = self.modestack.pop()
|
||||||
await action(self, key)
|
await action(self, key)
|
||||||
elif self.mode == "insert":
|
elif self.mode == "insert":
|
||||||
if key == "ESCAPE":
|
if key == "ESCAPE":
|
||||||
@ -451,7 +486,8 @@ class MainView():
|
|||||||
else:
|
else:
|
||||||
self.inputs += key
|
self.inputs += key
|
||||||
self.command_box = ""
|
self.command_box = ""
|
||||||
await self.drawtool.redraw()
|
if redraw:
|
||||||
|
await self.drawtool.redraw()
|
||||||
|
|
||||||
def insert_move_left(self):
|
def insert_move_left(self):
|
||||||
self.inputs_cursor = max(0, self.cursor - 1)
|
self.inputs_cursor = max(0, self.cursor - 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user