refactor: extract internal/session and eliminate I/O globals

Move serial port, trzsz filter, and pipe lifecycle into
internal/session.SerialSession. Replace 8 global I/O vars
(serialPort, trzszFilter, stdinPipe, stdoutPipe, clientIn,
clientOut, termch, termchOnce) with single sess variable.
Delete utils.go.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
JiXieShi
2026-05-23 21:49:43 +08:00
parent 31dd9da490
commit a1524a7e17
7 changed files with 165 additions and 137 deletions
+7 -3
View File
@@ -9,6 +9,7 @@ import (
"go.bug.st/serial"
"github.com/jixishi/SerialTerminalForWindowsTerminal/internal/event"
"github.com/jixishi/SerialTerminalForWindowsTerminal/internal/session"
"github.com/jixishi/SerialTerminalForWindowsTerminal/pkg/forward"
"github.com/jixishi/SerialTerminalForWindowsTerminal/pkg/luaplugin"
)
@@ -204,11 +205,14 @@ func TestReportForwardIngress(t *testing.T) {
}
func TestSendCtrl(t *testing.T) {
oldSp := serialPort
defer func() { serialPort = oldSp }()
if sess == nil {
sess = &session.SerialSession{}
}
oldSp := sess.Port
defer func() { sess.Port = oldSp }()
// Use a mock serial port
serialPort = &mockSerialPort{}
sess.Port = &mockSerialPort{}
a := &App{
cfg: &Config{},
uiEvents: make(chan event.UIEvent, 4),