| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Fenrir TTY screen reader |
| 5 |
# By Chrys, Storm Dragon, and contributors. |
| 6 |
|
| 7 |
import string |
| 8 |
|
| 9 |
from fenrirscreenreader.core.i18n import _ |
| 10 |
from fenrirscreenreader.utils import word_utils |
| 11 |
|
| 12 |
|
| 13 |
class command: |
| 14 |
def __init__(self): |
| 15 |
pass |
| 16 |
|
| 17 |
def initialize(self, environment): |
| 18 |
self.env = environment |
| 19 |
|
| 20 |
def shutdown(self): |
| 21 |
pass |
| 22 |
|
| 23 |
def get_description(self): |
| 24 |
return "No Description found" |
| 25 |
|
| 26 |
def run(self): |
| 27 |
# is navigation? |
| 28 |
if ( |
| 29 |
not abs( |
| 30 |
self.env["screen"]["old_cursor"]["x"] |
| 31 |
- self.env["screen"]["new_cursor"]["x"] |
| 32 |
) |
| 33 |
> 1 |
| 34 |
): |
| 35 |
return |
| 36 |
|
| 37 |
# just when cursor move worddetection is needed |
| 38 |
if not self.env["runtime"][ |
| 39 |
"CursorManager" |
| 40 |
].is_cursor_horizontal_move(): |
| 41 |
return |
| 42 |
# for now no new line |
| 43 |
if self.env["runtime"]["CursorManager"].is_cursor_vertical_move(): |
| 44 |
return |
| 45 |
# currently writing |
| 46 |
if self.env["runtime"]["ScreenManager"].is_delta(): |
| 47 |
return |
| 48 |
|
| 49 |
# get the word |
| 50 |
new_content = self.env["screen"]["new_content_text"].split("\n")[ |
| 51 |
self.env["screen"]["new_cursor"]["y"] |
| 52 |
] |
| 53 |
x, y, curr_word, end_of_screen, line_break = ( |
| 54 |
word_utils.get_current_word( |
| 55 |
self.env["screen"]["new_cursor"]["x"], 0, new_content |
| 56 |
) |
| 57 |
) |
| 58 |
|
| 59 |
# is there a word? |
| 60 |
if curr_word == "": |
| 61 |
return |
| 62 |
|
| 63 |
# at the start of a word |
| 64 |
if (x + len(curr_word) != self.env["screen"]["new_cursor"]["x"]) and ( |
| 65 |
self.env["screen"]["new_cursor"]["x"] != x |
| 66 |
): |
| 67 |
return |
| 68 |
|
| 69 |
# Don't interrupt ongoing auto-read announcements |
| 70 |
do_interrupt = True |
| 71 |
if self.env["runtime"]["SettingsManager"].get_setting_as_bool( |
| 72 |
"speech", "auto_read_incoming" |
| 73 |
): |
| 74 |
do_interrupt = False |
| 75 |
|
| 76 |
self.env["runtime"]["OutputManager"].present_text( |
| 77 |
curr_word, interrupt=do_interrupt, flush=False |
| 78 |
) |
| 79 |
|
| 80 |
def set_callback(self, callback): |
| 81 |
pass |