+ Better performance

+ Try to read prompt as one-liner (when arriving stripped format too)
+ Avoid overspeaking on window change to terminal and tab change (say only the real title, not the root process's title)
+ Fixed focusing on new session started from run (>=1.23 preview required)
This commit is contained in:
theadam 2025-04-06 21:05:16 +02:00
parent 13bfa7fa07
commit ea2230929d

View file

@ -1,28 +1,26 @@
; Copyright 2022 Freedom Scientific Inc.
; Copyright 2025 TheAdam <theadam.eu>
import "uia.jsb"
include "hjconst.jsh"
include "common.jsm"
include "uia.jsh"
const
TerminalClassName = "TermControl"
globals
int WindowsTerminalObjectID,
object WindowsTerminalTextProvider,
int WindowsTerminalLastKeyPress
int WindowsTerminalLastKeyPress,
int NoSelect
Script ScriptFileName()
ScriptAndAppNames("Windows Terminal")
EndScript
void function ProcessSayAppWindowOnFocusChange(handle AppWindow, handle FocusWindow)
EndFunction
void function ProcessSayRealWindowOnFocusChange( handle AppWindow, handle RealWindow, string RealWindowName, handle FocusWindow)
Void Function FocusChangedEventProcessAncestors(handle FocusWindow, handle PrevWindow)
if GetObjectClassName() == "TermControl"
sayObjectTypeAndText(2)
ELSE
FocusChangedEventProcessAncestors(FocusWindow, PrevWindow)
EndIf
EndFunction
Int Function IgnoreObjectAtLevel(int level)
@ -43,27 +41,33 @@ string function GetTextInConsoleWindow()
if GetObjectClassName() != "TermControl"
return ""
EndIf
if !WindowsTerminalTextProvider
WindowsTerminalTextProvider = FSUIAGetFocusedElement().GetTextPattern()
EndIf
visibleRanges = WindowsTerminalTextProvider.GetVisibleRanges()
range = visibleRanges(0)
return range.GetText(-1)
var string textRange = visibleRanges(0)
var string text = textRange.GetText(-1)
return text
EndFunction
script VirtualizeWindow()
var string text = StringTrimTrailingBlanks(GetTextInConsoleWindow())
var string text = StringTrimTrailingBlanks(GetTextInConsoleWindow())
if !text then
SayMessage(OT_ERROR,cmsgNoTextToVirtualize_L,cmsgNoTextToVirtualize_S)
return
endIf
SayMessage(ot_JAWS_Message,cmsgVirtualizeWindow_L,cmsgVirtualizeWindow_S)
UserBufferClear()
UserBufferAddText(text)
UserBufferAddText(StringTrimTrailingBlanks(text))
UserBufferActivate()
JAWSBottomOfFile()
EndScript
; Coming soon: Get the prompt out however still not work
string function GetLastLineFromConsoleText()
var string WindowText = StringTrimTrailingBlanks(GetTextInConsoleWindow())
var stringArray lines = StringSplit (WindowText, "\n", false)
var string LastLine = lines[ArrayLength (lines)-1]
return LastLine
EndFunction
string function ProcessUiaText(string text)
var stringArray lines = StringSplit (text, "\n", false)
var int x = 0
@ -75,14 +79,17 @@ For x = 0 to ArrayLength(lines)
if StringLength (stringStripAllBlanks (lines[x+1])) < 2 & lines[x+1] != "\n" & x != ArrayLength(lines)
out = StringConcatenate (out, StringReplaceChars (lines[x], "\n", " "))
else
out = StringConcatenate (out, lines[x], "\n")
out = StringConcatenate (out, lines[x], " ")
EndIf
EndFor
out = StringConcatenate (out, lines[x+1], "\n")
return out
return out
EndFunction
Void Function KeyPressedEvent (int nKey, string strKeyName, int nIsBrailleKey, int nIsScriptKey)
if nKey == 75 | nKey == 77
NoSelect = 1
EndIf
if (nKey > 100000)
WindowsTerminalLastKeyPress = WindowsTerminalLastKeyPress+1
else
@ -90,9 +97,20 @@ WindowsTerminalLastKeyPress = 0
EndIf
EndFunction
void function SelectionChangedEvent( string text, int wasTextSelected, optional int source )
if NoSelect == 1
Say(text,ot_line)
else
SelectionChangedEvent( text, wasTextSelected, source )
EndIf
NoSelect = 0
EndFunction
void function UIANotificationEvent(int notificationKind, int notificationProcessing, string displayString, string activityId, string appname)
;Say (activityId, OT_NONHIGHLIGHTED_SCREEN_TEXT)
var string ki = ProcessUiaText(displayString)
;Say (IntToString (WindowsTerminalLastKeyPress) , OT_NONHIGHLIGHTED_SCREEN_TEXT)
if activityId == "TerminalTextOutput"
if WindowsTerminalLastKeyPress >= 2
WindowsTerminalLastKeyPress = 0
ENDIF
@ -101,4 +119,7 @@ Say (ki, OT_NONHIGHLIGHTED_SCREEN_TEXT)
else
WindowsTerminalLastKeyPress = WindowsTerminalLastKeyPress+1
ENDIF
EndFunction
else
Say (ki, OT_NONHIGHLIGHTED_SCREEN_TEXT)
ENDIF
EndFunction