VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Grab the color of the ANSI color escape sequence (https://forums.vandyke.com/showthread.php?t=12497)

MeeksFamily06 10-03-2016 05:25 PM

Grab the color of the ANSI color escape sequence
 
Ok, I connect to a server that uses ANSI to change the color of the text to red when there is an issue in a particular area. I am trying to build a script and I am trying to figure out how to grab the color of a text to see if it is red. SO I would like it to grab the text as such

lpResult = crt.Screen.Get(14, 41, 14, 41 + 1)


Then grab the color of that text to check to see if ANSI made it red.

Any ideas on how one would accomplish this?

jdev 10-03-2016 05:56 PM

SecureCRT scripting doesn't expose a way to ask what the color of text is on the screen.

There might be other ways to accomplish your goal...

For instance you could have a script that runs waiting for the color escape sequence for red to appear, and then trigger on that sequence. However, you'd need to know if attributes are ever combined. Does the remote also bold the text at the same time it sets ANSI color to red?

To find out, you'd need to tell SecureCRT to capture a raw log (File -> Raw log session), then connect to the host and wait for some red text to appear. Once the red text appears, you'd turn off raw logging (File -> Raw log session) and then take a look inside the raw log file to determine what escape sequence was used to color the text red.

In its most basic form, the ANSI code to "begin red colored text" is:
ESC [ 31 m

The VBScript code to wait for this to appear would be:
Code:

  crt.Screen.Synchronous = True
  crt.Screen.WaitForString(chr(27) & "[31m")

Once the WaitForString() above returned, you'd know that the subsequent text to be received would be painted in red until such time as an ESC [ 0 m were received or an ESC [ m.
Code:

    strRedText = crt.Screen.ReadString(chr(27) & "[0m", chr(27) & "[m")
    crt.Dialog.MessageBox("Received some red text!" & vbcrlf & vbcrlf & strRedText)


There's all sorts of caveats that relate to the above, but it's not an easy problem to solve because there's no scripting API that you can ask SecureCRT to tell you the color of the text on any particular section of the screen.

--Jake

MeeksFamily06 10-08-2016 06:44 PM

Ok, I forced AIU 8 to cause an alarm and go red from another session. This was the raw session log.

 CKT OOS AIU 8


then I made one in AIU 9

 CKT OOS AIU 9

What I am hoping to do is when I come in, in the morning, I want to start the macro and it follow the red alarms to where the issue is. There are several screen you go through to get there.

So like I want to run a

aiu = crt.Screen.Get(6, 33, 6, 34)

but a way to check to see if that is in alarm in some way. Though I do appreciate the idea for the

crt.Screen.WaitForString(chr(27) & "[31m")

and will certainly keep that in mind. The only issue I have with that command is, it has no idea where on the screen it picked up on the chr(27) & "[31m" so it waits for it, then is not sure where on the screen it is.

jdev 10-10-2016 10:06 AM

As a reminder, Screen.Get will not return anything but plain text -- no color information is available to the scripting API at this point, so let's abandon that approach.

Your raw log info shows that it's the *background*, not the text itself that is colored in red. In other words, the alarm condition is displaying red background over text in *reverse*. This means that the escape sequence you'd want to use involves 41m, not 31m. For example:

Code:

' Send the characters/keystrokes that cause the alarm screen
' to be displayed... You fill in the blanks here...
' ...
' ...
'
' then...

strAllAlarmsDetected = ""
Do
    If Not crt.Screen.WaitForString(chr(27) & "[41m", 2) Then
        Exit Do
    End If

    ' If we get here, we know that we've seen an ESC [ 41 m
    ' ...so now, we ReadString() up to the ESC [ 40 m, where
    ' reverse is turned off.
    strAlarmText = crt.Screen.ReadString(chr(27) & "[40m")
    strAllAlarmsDetected = strAllAlarmsDetected & vbcrlf & strAlarmText
Loop

If strAllAlarmsDetected <> "" Then
    crt.Dialog.MessageBox("The following alarms were detected: " & strAlarmText)
Else
    crt.Dialog.MessageBox("No alarms detected.")
End If

--Jake


All times are GMT -6. The time now is 01:08 PM.