Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-03-2016, 05:25 PM
MeeksFamily06 MeeksFamily06 is offline
Registered User
 
Join Date: Oct 2016
Posts: 3
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?
Reply With Quote
  #2  
Old 10-03-2016, 05:56 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 919
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
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 10-08-2016, 06:44 PM
MeeksFamily06 MeeksFamily06 is offline
Registered User
 
Join Date: Oct 2016
Posts: 3
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.
Reply With Quote
  #4  
Old 10-10-2016, 10:06 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 919
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
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply

Tags
ansi , color , crt.screen.get , red


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:23 PM.