2 new features, silence speech until prompt returns and progress bar beeps.

This commit is contained in:
Storm Dragon
2025-06-07 00:52:13 -04:00
parent 0930a86ce7
commit 97e2da614b
9 changed files with 430 additions and 26 deletions

View File

@@ -0,0 +1,64 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from fenrirscreenreader.core import debug
class command():
def __init__(self):
pass
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getDescription(self):
return 'Detects shell prompts for silence until prompt feature'
def run(self):
# Only run if silence until prompt is active
try:
if 'silenceUntilPrompt' in self.env['commandBuffer'] and self.env['commandBuffer']['silenceUntilPrompt']:
# Check the current line for prompt patterns
if self.env['screen']['newContentText']:
lines = self.env['screen']['newContentText'].split('\n')
if lines and self.env['screen']['newCursor']['y'] < len(lines):
currentLine = lines[self.env['screen']['newCursor']['y']]
self.checkForPrompt(currentLine)
except Exception as e:
# Silently ignore errors to avoid disrupting normal operation
pass
def checkForPrompt(self, text):
"""Check if the current line contains a shell prompt pattern"""
import re
# Debug: Print what we're checking
self.env['runtime']['debug'].writeDebugOut("Prompt detector checking: '" + text + "'", debug.debugLevel.INFO)
# Look for common shell prompt patterns
promptPatterns = [
r'[^$]*\$$', # Ends with $ (user prompt)
r'[^#]*#$', # Ends with # (root prompt)
r'[^>]*>$', # Ends with > (some shells)
r'.*[\w@]+:.*[$#>]\s*$', # user@host:path$ style
]
for pattern in promptPatterns:
if re.search(pattern, text.strip()):
self.env['runtime']['debug'].writeDebugOut("Found prompt pattern: " + pattern, debug.debugLevel.INFO)
# Disable silence mode
self.env['commandBuffer']['silenceUntilPrompt'] = False
# Re-enable speech
self.env['runtime']['settingsManager'].setSetting('speech', 'enabled', 'True')
self.env['runtime']['outputManager'].presentText(_("Speech restored"), soundIcon='SpeechOn', interrupt=True)
return True
return False
def setCallback(self, callback):
pass