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