| |||||||||||
Outputting in colors Posted by johnjacky (johnjacky), 2 October 2005 Hi,I am writing an expect program and would like to print a message in red if a command fails and green if it as successful. Is it possible to output messages in colors? if so what command should I refer to ? I am using simple send_user now, like send_user "Failed" Also where can I read more about the flags of send_user, if there are more which I can see from man pages. Thanks. Posted by admin (Graham Ellis), 2 October 2005 Yes, it's possible. Have a look at either Tk (if you're using a GUI), the character sequences you need to change colour on a terminal (if you're wonking from a command line), or the HTML colour specifications if you're working via a web server.Options to the Expect commands are fully documented in Don Libes' book - it's my reference of choice for Expect and every expect programmer should have one. (No, I don't get paid for recommenting it!!) Posted by Dimon (Dimon), 25 December 2007 I have solve this task with the next way:# ------------------------------------------------------------------------- # Procedure to inserting text into GUI console with coloring some key words # # Arguments: # data - text string to write into console # base - scrolltext widget: target for text writing # # Return: # none # # 'Console' is an alias of ScrolledText widget # ------------------------------------------------------------------------ proc InsertTextC {data base} { # Set the color for error message tag set Console $base Console tag configure redtag -foreground red # text printing if {[string length $data]>0} { Console insert end $data Console see end ; update } # Calc the carrage return codes in data set curret [regexp -all -indices -- {\n} $data match] # Read last string from GUI-console set endPos [expr [Console index end]-1] set startPos [expr $endPos - $curret] set lasttext [Console get $startPos $endPos] catch {string trim "\n"} # search for error indicating lexemas (specific for my application of cause) set res [regexp -nocase -line -indices -- {(failure)|(uncomplete)|(error+)} $lasttext indexes] # check for 'no error', lexema: it's important! if {[regexp -nocase -line -indices -- {error+} $lasttext indexes]} { if {[lindex $indexes 0]>=3} { set idx1 [expr [lindex $indexes 0]-3] set noerr [regexp -nocase -line -start $idx1 -- {No error} $lasttext match] if {$noerr>0} { set res 0 } } } if $res>0 { # Calc start and stop keyword's positions if {[llength $indexes]>0} { set idx1 [lindex $indexes 0] set idx2 [lindex $indexes 1] ; incr idx2 } # Calc start and stop indexes for position will be marked; format: string.char regexp -- {^\d*} $startPos lineNum set startPos $lineNum.$idx1 set endPos $lineNum.$idx2 } # Bind tag to error keyword if it was found if $res>0 { Console tag add redtag $startPos $endPos } return } It's really works This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |