+ 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)
125 lines
3.5 KiB
JavaScript
Executable file
125 lines
3.5 KiB
JavaScript
Executable file
; Copyright 2022 Freedom Scientific Inc.
|
|
|
|
import "uia.jsb"
|
|
include "hjconst.jsh"
|
|
include "common.jsm"
|
|
include "uia.jsh"
|
|
|
|
globals
|
|
int WindowsTerminalObjectID,
|
|
object WindowsTerminalTextProvider,
|
|
int WindowsTerminalLastKeyPress,
|
|
int NoSelect
|
|
|
|
Script ScriptFileName()
|
|
ScriptAndAppNames("Windows Terminal")
|
|
EndScript
|
|
|
|
Void Function FocusChangedEventProcessAncestors(handle FocusWindow, handle PrevWindow)
|
|
if GetObjectClassName() == "TermControl"
|
|
sayObjectTypeAndText(2)
|
|
ELSE
|
|
FocusChangedEventProcessAncestors(FocusWindow, PrevWindow)
|
|
EndIf
|
|
EndFunction
|
|
|
|
Int Function IgnoreObjectAtLevel(int level)
|
|
var
|
|
int type = GetObjectSubTypeCode()
|
|
if type == WT_LISTBOX ||
|
|
type == WT_LISTBOXITEM
|
|
return true ; prevent overspeaking with Ctrl+Tab
|
|
EndIf
|
|
return FALSE
|
|
EndFunction
|
|
|
|
string function GetTextInConsoleWindow()
|
|
var
|
|
object oNull,
|
|
object visibleRanges,
|
|
object range
|
|
if GetObjectClassName() != "TermControl"
|
|
return ""
|
|
EndIf
|
|
WindowsTerminalTextProvider = FSUIAGetFocusedElement().GetTextPattern()
|
|
visibleRanges = WindowsTerminalTextProvider.GetVisibleRanges()
|
|
var string textRange = visibleRanges(0)
|
|
var string text = textRange.GetText(-1)
|
|
return text
|
|
EndFunction
|
|
|
|
script VirtualizeWindow()
|
|
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(StringTrimTrailingBlanks(text))
|
|
UserBufferActivate()
|
|
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
|
|
var string out = ""
|
|
if ArrayLength(lines) == 1
|
|
out = StringConcatenate (out, lines[x])
|
|
EndIf
|
|
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], " ")
|
|
EndIf
|
|
EndFor
|
|
out = StringConcatenate (out, lines[x+1], "\n")
|
|
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
|
|
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)
|
|
if activityId == "TerminalTextOutput"
|
|
if WindowsTerminalLastKeyPress >= 2
|
|
WindowsTerminalLastKeyPress = 0
|
|
ENDIF
|
|
if WindowsTerminalLastKeyPress == 0
|
|
Say (ki, OT_NONHIGHLIGHTED_SCREEN_TEXT)
|
|
else
|
|
WindowsTerminalLastKeyPress = WindowsTerminalLastKeyPress+1
|
|
ENDIF
|
|
else
|
|
Say (ki, OT_NONHIGHLIGHTED_SCREEN_TEXT)
|
|
ENDIF
|
|
EndFunction
|