v0.2.0 16 colors, default colors, /dev/tty, bracketed paste, themed form controls

This commit is contained in:
lixen committed 2026-10-09 14:15:46 -04:00
1 parent 070131c7fd
commit 2b5d127e84
32 files changed
+1447 -424

No files matched your search

+10 -7
View File
@@ -19,10 +19,10 @@ import (
"fmt"
"io"
"os"
"strings"
"sync"
"github.com/lixenwraith/color"
"github.com/lixenwraith/terminal/internal/env"
"golang.org/x/term"
)
@@ -35,12 +35,15 @@ const (
colorMode16
)
// textConsole reports a TERM limited to 16 colors (Linux VT, FreeBSD syscons,
// VT100-class). It wins over COLORTERM, which profiles export everywhere.
func textConsole() bool {
term := os.Getenv("TERM")
return term == "linux" || term == "ansi" || strings.HasPrefix(term, "cons25") ||
strings.HasPrefix(term, "vt") || strings.HasSuffix(term, "-16color")
// detectColorMode maps what the environment says to a color mode
func detectColorMode() colorMode {
switch env.Colors() {
case 16:
return colorMode16
case 1 << 24:
return colorModeTrueColor
}
return colorMode256
}
// Printer manages styled output and the live block. Safe for concurrent use.
-29
View File
@@ -4,39 +4,10 @@ package inline
import (
"os"
"strings"
"golang.org/x/sys/unix"
)
func detectColorMode() colorMode {
if textConsole() {
return colorMode16
}
colorterm := os.Getenv("COLORTERM")
if colorterm == "truecolor" || colorterm == "24bit" {
return colorModeTrueColor
}
if os.Getenv("KITTY_WINDOW_ID") != "" ||
os.Getenv("KONSOLE_VERSION") != "" ||
os.Getenv("ITERM_SESSION_ID") != "" ||
os.Getenv("ALACRITTY_WINDOW_ID") != "" ||
os.Getenv("ALACRITTY_LOG") != "" ||
os.Getenv("WEZTERM_PANE") != "" {
return colorModeTrueColor
}
term := os.Getenv("TERM")
if strings.Contains(term, "truecolor") ||
strings.Contains(term, "24bit") ||
strings.Contains(term, "direct") {
return colorModeTrueColor
}
return colorMode256
}
func windowSize(f *os.File) (w, h int, ok bool) {
ws, err := unix.IoctlGetWinsize(int(f.Fd()), unix.TIOCGWINSZ)
if err != nil || ws.Col == 0 {
-7
View File
@@ -4,13 +4,6 @@ package inline
import "os"
func detectColorMode() colorMode {
if textConsole() {
return colorMode16
}
return colorMode256
}
func windowSize(f *os.File) (w, h int, ok bool) {
return 0, 0, false
}
-13
View File
@@ -8,19 +8,6 @@ import (
"golang.org/x/sys/windows"
)
func detectColorMode() colorMode {
if textConsole() {
return colorMode16
}
if os.Getenv("WT_SESSION") != "" || os.Getenv("WT_PROFILE_ID") != "" {
return colorModeTrueColor
}
if ct := os.Getenv("COLORTERM"); ct == "truecolor" || ct == "24bit" {
return colorModeTrueColor
}
return colorMode256
}
func windowSize(f *os.File) (w, h int, ok bool) {
var info windows.ConsoleScreenBufferInfo
if err := windows.GetConsoleScreenBufferInfo(windows.Handle(f.Fd()), &info); err != nil {