Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take a look #53

Open
Moosems opened this issue Sep 10, 2023 · 5 comments
Open

Take a look #53

Moosems opened this issue Sep 10, 2023 · 5 comments

Comments

@Moosems
Copy link
Collaborator

Moosems commented Sep 10, 2023

https://wiki.tcl-lang.org/page/terminal+emulator

What if we just make this into a wrapper around Expect?

@littlewhitecloud
Copy link
Owner

littlewhitecloud commented Sep 24, 2023

@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
Copy link
Collaborator Author

Moosems commented Sep 30, 2023

I just meant using Expect :).

@littlewhitecloud
Copy link
Owner

littlewhitecloud commented Sep 30, 2023

what?

@Moosems
Copy link
Collaborator Author

Moosems commented Sep 30, 2023

@littlewhitecloud
Copy link
Owner

I have no idea about that, can you give me an example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants