| 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 _("Announces characters as they are typed") |
| 23 |
|
| 24 |
def run(self): |
| 25 |
# enabled? |
| 26 |
active = self.env["runtime"]["SettingsManager"].get_setting_as_int( |
| 27 |
"keyboard", "char_echo_mode" |
| 28 |
) |
| 29 |
# 0 = off |
| 30 |
if active == 0: |
| 31 |
return |
| 32 |
# 2 = caps only |
| 33 |
if active == 2: |
| 34 |
if not self.env["input"]["new_caps_lock"]: |
| 35 |
return |
| 36 |
# big changes are no char (but the value is bigger than one maybe the |
| 37 |
# differ needs longer than you can type, so a little strange random |
| 38 |
# buffer for now) |
| 39 |
x_move = abs( |
| 40 |
self.env["screen"]["new_cursor"]["x"] |
| 41 |
- self.env["screen"]["old_cursor"]["x"] |
| 42 |
) |
| 43 |
if x_move > 3: |
| 44 |
return |
| 45 |
if self.env["runtime"][ |
| 46 |
"InputManager" |
| 47 |
].get_last_deepest_input() in [["KEY_TAB"]]: |
| 48 |
return |
| 49 |
# detect deletion or chilling |
| 50 |
if ( |
| 51 |
self.env["screen"]["new_cursor"]["x"] |
| 52 |
<= self.env["screen"]["old_cursor"]["x"] |
| 53 |
): |
| 54 |
return |
| 55 |
# is there any change? |
| 56 |
if not self.env["runtime"]["ScreenManager"].is_delta(): |
| 57 |
return |
| 58 |
# filter unneded space on word begin |
| 59 |
curr_delta = self.env["screen"]["new_delta"] |
| 60 |
if ( |
| 61 |
len(curr_delta.strip()) != len(curr_delta) |
| 62 |
and curr_delta.strip() != "" |
| 63 |
): |
| 64 |
curr_delta = curr_delta.strip() |
| 65 |
self.env["runtime"]["OutputManager"].present_text( |
| 66 |
curr_delta, |
| 67 |
interrupt=True, |
| 68 |
ignore_punctuation=True, |
| 69 |
announce_capital=True, |
| 70 |
flush=False, |
| 71 |
) |
| 72 |
|
| 73 |
def set_callback(self, callback): |
| 74 |
pass |