Add the ability to add custom prompts to the settings file, generic prompts are covered with the existing detection code.
This commit is contained in:
parent
97e2da614b
commit
26c6e32c59
@ -214,6 +214,22 @@ list=
|
|||||||
vmenuPath=
|
vmenuPath=
|
||||||
quickMenu=speech#rate;speech#pitch;speech#volume
|
quickMenu=speech#rate;speech#pitch;speech#volume
|
||||||
|
|
||||||
|
[prompt]
|
||||||
|
# Custom prompt patterns for silence until prompt feature
|
||||||
|
# You can add your own shell prompt patterns as regular expressions
|
||||||
|
# Each pattern should be on a separate line, format: customPatterns=pattern1,pattern2,pattern3
|
||||||
|
# Examples:
|
||||||
|
# For PS1='[\u@\h \W] \$ ' use: \[.*@.*\s.*\]\s*[$#>]\s*
|
||||||
|
# For "[storm@fenrir ~] $" use: \[.*@.*\s.*\]\s*[$#>]\s*
|
||||||
|
# For custom prompts ending with specific strings, use patterns like: .*your_prompt_ending$
|
||||||
|
customPatterns=
|
||||||
|
|
||||||
|
# Specific prompt strings to match exactly (useful for very specific custom prompts)
|
||||||
|
# Format: exactMatches=prompt1,prompt2,prompt3
|
||||||
|
# Examples:
|
||||||
|
# exactMatches=[storm@fenrir ~] $,[root@fenrir ~] #
|
||||||
|
exactMatches=
|
||||||
|
|
||||||
[time]
|
[time]
|
||||||
# automatic time anouncement
|
# automatic time anouncement
|
||||||
enabled=False
|
enabled=False
|
||||||
|
@ -46,22 +46,52 @@ class command():
|
|||||||
if not self.env['commandBuffer']['silenceUntilPrompt']:
|
if not self.env['commandBuffer']['silenceUntilPrompt']:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Look for common shell prompt patterns
|
# First check for exact matches from settings (with backward compatibility)
|
||||||
# $ prompt (user)
|
try:
|
||||||
# # prompt (root)
|
exactMatches = self.env['runtime']['settingsManager'].getSetting('prompt', 'exactMatches')
|
||||||
# > prompt (some shells)
|
if exactMatches:
|
||||||
# Also check for common prompt prefixes like user@host:path$
|
exactList = [match.strip() for match in exactMatches.split(',') if match.strip()]
|
||||||
promptPatterns = [
|
for exactMatch in exactList:
|
||||||
r'[^$]*\$$', # Ends with $ (user prompt)
|
if text.strip() == exactMatch:
|
||||||
r'[^#]*#$', # Ends with # (root prompt)
|
self.env['runtime']['debug'].writeDebugOut("Found exact prompt match: " + exactMatch, debug.debugLevel.INFO)
|
||||||
r'[^>]*>$', # Ends with > (some shells)
|
self.disableSilence()
|
||||||
r'.*[\w@]+:.*[$#>]\s*$', # user@host:path$ style
|
return True
|
||||||
]
|
except:
|
||||||
|
# Prompt section doesn't exist in settings, skip custom exact matches
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Get custom patterns from settings (with backward compatibility)
|
||||||
|
promptPatterns = []
|
||||||
|
try:
|
||||||
|
customPatterns = self.env['runtime']['settingsManager'].getSetting('prompt', 'customPatterns')
|
||||||
|
# Add custom patterns from settings if they exist
|
||||||
|
if customPatterns:
|
||||||
|
customList = [pattern.strip() for pattern in customPatterns.split(',') if pattern.strip()]
|
||||||
|
promptPatterns.extend(customList)
|
||||||
|
except:
|
||||||
|
# Prompt section doesn't exist in settings, skip custom patterns
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Add default shell prompt patterns
|
||||||
|
promptPatterns.extend([
|
||||||
|
r'^\s*\\\$\s*$', # Just $ (with whitespace)
|
||||||
|
r'^\s*#\s*$', # Just # (with whitespace)
|
||||||
|
r'^\s*>\s*$', # Just > (with whitespace)
|
||||||
|
r'.*@.*[\\\$#>]\s*$', # Contains @ and ends with prompt char (user@host style)
|
||||||
|
r'^\[.*\]\s*[\\\$#>]\s*$', # [anything]$ style prompts
|
||||||
|
r'^[a-zA-Z0-9._-]+[\\\$#>]\s*$', # Simple shell names like bash-5.1$
|
||||||
|
])
|
||||||
|
|
||||||
for pattern in promptPatterns:
|
for pattern in promptPatterns:
|
||||||
if re.search(pattern, text.strip()):
|
try:
|
||||||
self.disableSilence()
|
if re.search(pattern, text.strip()):
|
||||||
return True
|
self.env['runtime']['debug'].writeDebugOut("Found prompt pattern: " + pattern, debug.debugLevel.INFO)
|
||||||
|
self.disableSilence()
|
||||||
|
return True
|
||||||
|
except re.error as e:
|
||||||
|
# Invalid regex pattern, skip it and log the error
|
||||||
|
self.env['runtime']['debug'].writeDebugOut("Invalid prompt pattern: " + pattern + " Error: " + str(e), debug.debugLevel.ERROR)
|
||||||
|
continue
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -40,25 +40,62 @@ class command():
|
|||||||
# Debug: Print what we're checking
|
# Debug: Print what we're checking
|
||||||
self.env['runtime']['debug'].writeDebugOut("Prompt detector checking: '" + text + "'", debug.debugLevel.INFO)
|
self.env['runtime']['debug'].writeDebugOut("Prompt detector checking: '" + text + "'", debug.debugLevel.INFO)
|
||||||
|
|
||||||
# Look for common shell prompt patterns
|
# First check for exact matches from settings (with backward compatibility)
|
||||||
promptPatterns = [
|
try:
|
||||||
r'[^$]*\$$', # Ends with $ (user prompt)
|
exactMatches = self.env['runtime']['settingsManager'].getSetting('prompt', 'exactMatches')
|
||||||
r'[^#]*#$', # Ends with # (root prompt)
|
if exactMatches:
|
||||||
r'[^>]*>$', # Ends with > (some shells)
|
exactList = [match.strip() for match in exactMatches.split(',') if match.strip()]
|
||||||
r'.*[\w@]+:.*[$#>]\s*$', # user@host:path$ style
|
for exactMatch in exactList:
|
||||||
]
|
if text.strip() == exactMatch:
|
||||||
|
self.env['runtime']['debug'].writeDebugOut("Found exact prompt match: " + exactMatch, debug.debugLevel.INFO)
|
||||||
|
self._restoreSpeech()
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
# Prompt section doesn't exist in settings, skip custom exact matches
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Get custom patterns from settings (with backward compatibility)
|
||||||
|
promptPatterns = []
|
||||||
|
try:
|
||||||
|
customPatterns = self.env['runtime']['settingsManager'].getSetting('prompt', 'customPatterns')
|
||||||
|
# Add custom patterns from settings if they exist
|
||||||
|
if customPatterns:
|
||||||
|
customList = [pattern.strip() for pattern in customPatterns.split(',') if pattern.strip()]
|
||||||
|
promptPatterns.extend(customList)
|
||||||
|
except:
|
||||||
|
# Prompt section doesn't exist in settings, skip custom patterns
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Add default shell prompt patterns
|
||||||
|
promptPatterns.extend([
|
||||||
|
r'^\s*\\\$\s*$', # Just $ (with whitespace)
|
||||||
|
r'^\s*#\s*$', # Just # (with whitespace)
|
||||||
|
r'^\s*>\s*$', # Just > (with whitespace)
|
||||||
|
r'.*@.*[\\\$#>]\s*$', # Contains @ and ends with prompt char (user@host style)
|
||||||
|
r'^\[.*\]\s*[\\\$#>]\s*$', # [anything]$ style prompts
|
||||||
|
r'^[a-zA-Z0-9._-]+[\\\$#>]\s*$', # Simple shell names like bash-5.1$
|
||||||
|
])
|
||||||
|
|
||||||
for pattern in promptPatterns:
|
for pattern in promptPatterns:
|
||||||
if re.search(pattern, text.strip()):
|
try:
|
||||||
self.env['runtime']['debug'].writeDebugOut("Found prompt pattern: " + pattern, debug.debugLevel.INFO)
|
if re.search(pattern, text.strip()):
|
||||||
# Disable silence mode
|
self.env['runtime']['debug'].writeDebugOut("Found prompt pattern: " + pattern, debug.debugLevel.INFO)
|
||||||
self.env['commandBuffer']['silenceUntilPrompt'] = False
|
self._restoreSpeech()
|
||||||
# Re-enable speech
|
return True
|
||||||
self.env['runtime']['settingsManager'].setSetting('speech', 'enabled', 'True')
|
except re.error as e:
|
||||||
self.env['runtime']['outputManager'].presentText(_("Speech restored"), soundIcon='SpeechOn', interrupt=True)
|
# Invalid regex pattern, skip it and log the error
|
||||||
return True
|
self.env['runtime']['debug'].writeDebugOut("Invalid prompt pattern: " + pattern + " Error: " + str(e), debug.debugLevel.ERROR)
|
||||||
|
continue
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _restoreSpeech(self):
|
||||||
|
"""Helper method to restore speech when prompt is detected"""
|
||||||
|
# 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)
|
||||||
|
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
Loading…
x
Reference in New Issue
Block a user