I've tried to port a simple Tcl full-screen editor to IOS and failed completely as IOS tclsh escapes control characters written by the puts command. For example, the following escape sequence should clear the screen, but as the ESCAPE character is displayed as ^[, it doesn't work:
router(tcl)#puts "\033\[2J"Any ideas how to persuade the router to display raw binary data?
^[[2J
router(tcl)#

Not sure if this helps but:
ReplyDeleteSYNOPSIS
binary format formatString ?arg arg ...?
binary scan string formatString ?varName varName ...?
DESCRIPTION
This command provides facilities for manipulating binary data. The first form, binary format, creates a binary string from normal Tcl values. For example, given the values 16 and 22, on a 32 bit architecture, it might produce an 8-byte binary string consisting of two 4-byte integers, one for each of the numbers. The second form of the command, binary scan, does the opposite: it extracts data from a binary string and returns it as ordinary Tcl string values.
Here is a link to a TCL tutorial which i wrote
ReplyDeletehttp://www.internetworkpro.org/wiki/Edit_files_using_TCL
@windexh8er: Thanks, but it doesn't help. The binary format builds the string representation of binary data and is equivalent to what I did with the \033; the problem is that the puts command doesn't want to display binary data.
ReplyDelete@danshtr: Nice trick, which answers another question I've got a while ago. Thanks!
What if you populated a variable with the binary format formatString line and used puts to display it?
ReplyDeleteSame thing:
ReplyDeleterouter(tcl)#set x [binary format ca* 27 "\[2J" ]
^[[2J
router(tcl)#puts "$x"
^[[2J
puts "\e[2J" does quite strange effect.
ReplyDelete--
mtve
If you try to generate ansi escape sequences, you can use "term intern" on exec level
ReplyDeleteproc fahne { } {
exec "terminal international"
puts "\033\[2J"
puts "\033\[0;0H"
puts "\033\[0m |##########"
puts "\033\[0m |#########"
puts "\033\[0m |\033\[31m########"
puts "\033\[0m |\033\[31m########"
puts "\033\[0m |\033\[33m#########"
puts "\033\[0m |\033\[33m##########"
puts "\033\[0m |"
puts "\033\[0m |"
puts "\033\[0m |"
puts "\033\[0m\n\n\033\[32m Yepp \033\[0m"
}
fahne
Perfect. It works :) Now I'm getting the file contents on the screen as they should be, but cannot put the terminal into "raw" mode (giving Tclsh a character at a time). Maybe I'll get some crazy idea over weekend ;)
ReplyDeleteIf you are looking for something like Pascals getch I think you can use fileevent
ReplyDeleteproc processinput fd {} {
...
}
fileevent stdin readable {processinput stdin}
vwait forever
Well, the problem is that Tcl script gets the input only after the user has pressed the ENTER key, which is a problem if you're trying to implement a full-screen editor. So even your suggestion will not make stdin readable until the user has signalled the end of line.
ReplyDeleteOk you're right. Have a look at http://wiki.tcl.tk/11820
ReplyDeleteIf you remove the shell code, all stty commands and the encoding parameter from the fconfigure commands it is at least startable on ios (with "term inter").
I'm trying to port the newer version of it (http://wiki.tcl.tk/16056). And, yes, what we need is exactly the stty -raw :(
ReplyDelete