Take a look
Opened this issue · 5 comments
Moosems commented
https://wiki.tcl-lang.org/page/terminal+emulator
What if we just make this into a wrapper around Expect?
littlewhitecloud commented
@Moosems This code?
###############################################################################
# Term for a simple terminal interface
###############################################################################
# The terminal bindings are implemented by defining a new bindtag 'Term'
###############################################################################
# Configure your serial port here
#
set Term(Port) com1
set Term(Mode) "19200,n,8,1"
set Term(Font) Courier
# Global variables
#
set Term(Text) {}
##################### Terminal In/Out events ############################
proc term_out { chan key } {
switch -regexp -- $key {
[\x07-\x08] -
\x0D -
[\x20-\x7E] { puts -nonewline $chan $key; return -code break }
[\x01-\x06] -
[\x09-\x0C] -
[\x0E-\x1F] -
\x7F { return }
default { return }
} ;# switch
}
proc term_in { ch } {
upvar #0 Term(Text) txt
switch -regexp -- $ch {
\x07 { bell }
\x0A { # ignore }
\x0D { $txt insert end "\n" }
default { $txt insert end $ch }
}
$txt see end
}
proc receiver {chan} {
foreach ch [ split [read $chan] {}] {
term_in $ch
}
}
##################### Windows ############################
proc scrolled_text { f args } {
frame $f
eval {text $f.text \
-xscrollcommand [list $f.xscroll set] \
-yscrollcommand [list $f.yscroll set]} $args
scrollbar $f.xscroll -orient horizontal \
-command [list $f.text xview]
scrollbar $f.yscroll -orient vertical \
-command [list $f.text yview]
grid $f.text $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.text
}
##### main #######
set chan [open $Term(Port) r+]
fconfigure $chan -mode $Term(Mode) -translation binary -buffering none -blocking 0
fileevent $chan readable [list receiver $chan]
set Term(Text) [scrolled_text .t -width 80 -height 25 -font $Term(Font) ]
pack .t -side top -fill both -expand true
bind $Term(Text) <Any-Key> [list term_out $chan %A]
catch {console hide}
Moosems commented
I just meant using Expect
:).
littlewhitecloud commented
what?
Moosems commented
littlewhitecloud commented
I have no idea about that, can you give me an example?