Debian Codegraph @

src/fenrirscreenreader/commands/onScreenUpdate/60000-history.py

raw
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 # Fenrir TTY screen reader
5 # By Chrys, Storm Dragon, and contributors.
6
7
8 from fenrirscreenreader.core.i18n import _
9
10
11 class command:
12 def __init__(self):
13 pass
14
15 def initialize(self, environment):
16 self.env = environment
17
18 def shutdown(self):
19 pass
20
21 def get_description(self):
22 return ""
23
24 def run(self):
25 if self.env["screen"]["newAttribDelta"] != "":
26 return
27 if self.env["runtime"]["ScreenManager"].is_screen_change():
28 return
29 if self.env["runtime"]["CursorManager"].is_cursor_vertical_move():
30 return
31 if self.env["runtime"]["AttributeManager"].is_attribute_change():
32 return
33 # hack for pdmenu and maybe other dialog apps that place the cursor at
34 # last cell/row
35 # this is not to be identified as history
36 if (
37 self.env["screen"]["new_cursor"]["x"]
38 == self.env["runtime"]["ScreenManager"].get_columns() - 1
39 ) and (
40 self.env["screen"]["new_cursor"]["y"]
41 == self.env["runtime"]["ScreenManager"].get_rows() - 1
42 ):
43 return
44 if not (
45 self.env["runtime"]["InputManager"].get_last_deepest_input()
46 in [["KEY_UP"], ["KEY_DOWN"]]
47 ):
48 return
49
50 # Get the current cursor's line from both old and new content
51 prev_line = self.env["screen"]["old_content_text"].split("\n")[
52 self.env["screen"]["new_cursor"]["y"]
53 ]
54 curr_line = self.env["screen"]["new_content_text"].split("\n")[
55 self.env["screen"]["new_cursor"]["y"]
56 ]
57
58 is_blank = curr_line.strip() == ""
59
60 if prev_line == curr_line:
61 if self.env["screen"]["new_delta"] != "":
62 return
63
64 announce = curr_line
65 if not is_blank:
66 curr_prompt = curr_line.find("$")
67 root_prompt = curr_line.find("#")
68 if curr_prompt <= 0:
69 if root_prompt > 0:
70 curr_prompt = root_prompt
71 else:
72 announce = curr_line
73 if curr_prompt > 0:
74 remove_digits = str.maketrans("0123456789", " ")
75 if prev_line[:curr_prompt].translate(
76 remove_digits
77 ) == curr_line[:curr_prompt].translate(remove_digits):
78 announce = curr_line[curr_prompt + 1 :]
79 else:
80 announce = curr_line
81
82 if is_blank:
83 self.env["runtime"]["OutputManager"].present_text(
84 _("blank"), sound_icon="EmptyLine", interrupt=True, flush=False
85 )
86 else:
87 self.env["runtime"]["OutputManager"].present_text(
88 announce, interrupt=True, flush=False
89 )
90
91 self.env["commandsIgnore"]["onScreenUpdate"]["CHAR_DELETE_ECHO"] = True
92 self.env["commandsIgnore"]["onScreenUpdate"]["CHAR_ECHO"] = True
93 self.env["commandsIgnore"]["onScreenUpdate"]["INCOMING_IGNORE"] = True
94
95 def set_callback(self, callback):
96 pass