Debian Codegraph @

src/fenrirscreenreader/commands/onCursorChange/65000-present_line_if_cursor_change_vertical.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 from fenrirscreenreader.core.i18n import _
8 from fenrirscreenreader.utils import line_utils
9 from fenrirscreenreader.utils import word_utils
10
11
12 class command:
13 def __init__(self):
14 self.lastIdent = -1
15
16 def initialize(self, environment):
17 self.env = environment
18
19 def shutdown(self):
20 pass
21
22 def get_description(self):
23 return ""
24
25 def run(self):
26 if not self.env["runtime"]["SettingsManager"].get_setting_as_bool(
27 "focus", "cursor"
28 ):
29 return
30 if self.env["runtime"]["ScreenManager"].is_screen_change():
31 self.lastIdent = 0
32 return
33 # Don't announce cursor movements when auto-read is handling incoming text
34 # This prevents interrupting ongoing auto-read announcements
35 if self.env["runtime"]["ScreenManager"].is_delta():
36 return
37
38 # is a vertical change?
39 if not self.env["runtime"]["CursorManager"].is_cursor_vertical_move():
40 return
41
42 x, y, curr_line = line_utils.get_current_line(
43 self.env["screen"]["new_cursor"]["x"],
44 self.env["screen"]["new_cursor"]["y"],
45 self.env["screen"]["new_content_text"],
46 )
47 # Don't interrupt ongoing auto-read announcements with cursor movement
48 do_interrupt = True
49 if self.env["runtime"]["SettingsManager"].get_setting_as_bool(
50 "speech", "auto_read_incoming"
51 ):
52 do_interrupt = False
53
54 if curr_line.isspace():
55 self.env["runtime"]["OutputManager"].present_text(
56 _("blank"), sound_icon="EmptyLine", interrupt=do_interrupt, flush=False
57 )
58 else:
59 # ident
60 curr_ident = len(curr_line) - len(curr_line.lstrip())
61 if self.lastIdent == -1:
62 self.lastIdent = curr_ident
63 if self.env["runtime"]["SettingsManager"].get_setting_as_bool(
64 "general", "auto_present_indent"
65 ):
66 if self.env["runtime"]["SettingsManager"].get_setting_as_int(
67 "general", "auto_present_indent_mode"
68 ) in [0, 1]:
69 if self.lastIdent != curr_ident:
70 self.env["runtime"]["OutputManager"].play_frequence(
71 curr_ident * 50, 0.1, interrupt=do_interrupt
72 )
73 if self.env["runtime"]["SettingsManager"].get_setting_as_int(
74 "general", "auto_present_indent_mode"
75 ) in [0, 2]:
76 if self.lastIdent != curr_ident:
77 self.env["runtime"]["OutputManager"].present_text(
78 _("indented ") + str(curr_ident) + " ",
79 interrupt=do_interrupt,
80 flush=False,
81 )
82 do_interrupt = False
83 # barrier
84 say_line = curr_line
85 if self.env["runtime"]["SettingsManager"].get_setting_as_bool(
86 "barrier", "enabled"
87 ):
88 is_barrier, barrierLine = self.env["runtime"][
89 "BarrierManager"
90 ].handle_line_barrier(
91 self.env["screen"]["new_content_text"].split("\n"),
92 self.env["screen"]["new_cursor"]["x"],
93 self.env["screen"]["new_cursor"]["y"],
94 )
95 if is_barrier:
96 say_line = barrierLine
97 # output
98 self.env["runtime"]["OutputManager"].present_text(
99 say_line, interrupt=do_interrupt, flush=False
100 )
101 self.lastIdent = curr_ident
102
103 def set_callback(self, callback):
104 pass