Skip to content

Commit

Permalink
chore(telnet): Add terminal type and window size data to log
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 3, 2024
1 parent a98776a commit bd38886
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/server/telnet/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bufio"
"bytes"
"encoding/binary"
"fmt"
"io"
"net"
"strings"
"time"

"github.com/gabe565/ascii-movie/internal/util"
Expand All @@ -17,6 +19,10 @@ type WindowSize struct {
Width, Height uint16
}

func (w WindowSize) String() string {
return fmt.Sprintf("%dx%d", w.Width, w.Height)
}

func Proxy(conn net.Conn) (io.ReadCloser, termenv.Profile, <-chan WindowSize, <-chan error) {
pr, pw := io.Pipe()
termCh := make(chan string, 1)
Expand Down Expand Up @@ -112,20 +118,20 @@ outer:
if len(command) != 0 {
switch Operator(command[0]) {
case TerminalType:
if !wroteTermType && len(command) > 2 {
log.Trace().Msg("Got terminal type")
term := command[2 : len(command)-2]
termCh <- string(term)
if !wroteTermType && len(command) > 4 {
wroteTermType = true
term := strings.ToLower(string(command[2 : len(command)-2]))
log.Trace().Str("type", term).Msg("Got terminal type")
termCh <- term
}
case NegotiateAboutWindowSize:
if len(command) >= 5 {
log.Trace().Msg("Got window size")
r := bytes.NewReader(command[1:])
var size WindowSize
if err := binary.Read(r, binary.BigEndian, &size); err != nil {
return err
}
log.Trace().Stringer("size", size).Msg("Got window size")
sizeCh <- size
}
}
Expand Down

0 comments on commit bd38886

Please # to comment.