Files
sshtermy/third_party/vt/osc.go
T
db9979andClaude Opus 5.5 2513a7818d MIT-Lizenz, weniger Speicher pro Tab, schnellere Ausgabe und Manager (#47)
* MIT-Lizenz; Terminal-Verlauf kompakt, schnellerer Bildlauf, Manager mit vielen Verbindungen schneller

- LICENSE (MIT), winget/Homebrew/apt-Metadaten, README, Webseite, --version
- termemu: Verlauf mit 8 statt 112 Byte pro Zeichen, Ringpuffer
- third_party/vt: angepasste Kopie (rotateLines, SetScrollbackHook)
- Store: Connections() zwischengespeichert; Manager: buildRows ohne Teillisten,
  Fußzeile misst Breiten einmal
- Benchmarks: make bench

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUjBAAPCAZVnGzCZxdS

* Testprogramm aus dem Commit entfernt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUjBAAPCAZVnGzCZxdS

* Testprogramm entfernt, *.test ignorieren

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUjBAAPCAZVnGzCZxdS

* TestSerialSession: auf stehenden Prompt warten statt auf das erste #

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUjBAAPCAZVnGzCZxdS

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-06 10:02:26 +01:00

137 lines
3.0 KiB
Go

// Package vt provides a virtual terminal implementation.
// SKIP: Fix typecheck errors - function signature mismatches and undefined types
package vt
import (
"bytes"
"image/color"
"io"
"github.com/charmbracelet/x/ansi"
)
// handleOsc handles an OSC escape sequence.
func (e *Emulator) handleOsc(cmd int, data []byte) {
e.flushGrapheme() // Flush any pending grapheme before handling OSC sequences.
if !e.handlers.handleOsc(cmd, data) {
e.logf("unhandled sequence: OSC %q", data)
}
}
func (e *Emulator) handleTitle(cmd int, data []byte) {
parts := bytes.Split(data, []byte{';'})
if len(parts) != 2 {
// Invalid, ignore
return
}
switch cmd {
case 0: // Set window title and icon name
name := string(parts[1])
e.iconName, e.title = name, name
if e.cb.Title != nil {
e.cb.Title(name)
}
if e.cb.IconName != nil {
e.cb.IconName(name)
}
case 1: // Set icon name
name := string(parts[1])
e.iconName = name
if e.cb.IconName != nil {
e.cb.IconName(name)
}
case 2: // Set window title
name := string(parts[1])
e.title = name
if e.cb.Title != nil {
e.cb.Title(name)
}
}
}
func (e *Emulator) handleDefaultColor(cmd int, data []byte) {
if cmd != 10 && cmd != 11 && cmd != 12 &&
cmd != 110 && cmd != 111 && cmd != 112 {
// Invalid, ignore
return
}
parts := bytes.Split(data, []byte{';'})
if len(parts) == 0 {
// Invalid, ignore
return
}
cb := func(c color.Color) {
switch cmd {
case 10, 110: // Foreground color
e.SetForegroundColor(c)
case 11, 111: // Background color
e.SetBackgroundColor(c)
case 12, 112: // Cursor color
e.SetCursorColor(c)
}
}
switch len(parts) {
case 1: // Reset color
cb(nil)
case 2: // Set/Query color
arg := string(parts[1])
if arg == "?" {
var xrgb ansi.XRGBColor
switch cmd {
case 10: // Query foreground color
xrgb.Color = e.ForegroundColor()
if xrgb.Color != nil {
io.WriteString(e.pw, ansi.SetForegroundColor(xrgb.String())) //nolint:errcheck,gosec
}
case 11: // Query background color
xrgb.Color = e.BackgroundColor()
if xrgb.Color != nil {
io.WriteString(e.pw, ansi.SetBackgroundColor(xrgb.String())) //nolint:errcheck,gosec
}
case 12: // Query cursor color
xrgb.Color = e.CursorColor()
if xrgb.Color != nil {
io.WriteString(e.pw, ansi.SetCursorColor(xrgb.String())) //nolint:errcheck,gosec
}
}
} else if c := ansi.XParseColor(arg); c != nil {
cb(c)
}
}
}
func (e *Emulator) handleWorkingDirectory(cmd int, data []byte) {
if cmd != 7 {
// Invalid, ignore
return
}
// The data is the working directory path.
parts := bytes.Split(data, []byte{';'})
if len(parts) != 2 {
// Invalid, ignore
return
}
path := string(parts[1])
e.cwd = path
if e.cb.WorkingDirectory != nil {
e.cb.WorkingDirectory(path)
}
}
func (e *Emulator) handleHyperlink(cmd int, data []byte) {
parts := bytes.Split(data, []byte{';'})
if len(parts) != 3 || cmd != 8 {
// Invalid, ignore
return
}
e.scr.cur.Link.Params = string(parts[1])
e.scr.cur.Link.URL = string(parts[2])
}