v0.1.3 adapters for service and 256 color removed

This commit is contained in:
2026-07-21 05:13:25 -04:00
parent e5c78a87f2
commit 056401d20a
2 changed files with 0 additions and 200 deletions
-54
View File
@@ -1,54 +0,0 @@
package terminal
import "github.com/lixenwraith/color"
// Generic xterm 256-color constants proxied to the central color package
// to maintain backwards compatibility for the terminal package.
const (
P256DeepNavy = color.P256DeepNavy
P256DarkBlue = color.P256DarkBlue
P256SteelBlue = color.P256SteelBlue
P256LightBlue = color.P256LightBlue
P256DeepTeal = color.P256DeepTeal
P256Teal = color.P256Teal
P256Green = color.P256Green
P256Cyan = color.P256Cyan
P256LightCyan = color.P256LightCyan
P256CobaltBlue = color.P256CobaltBlue
P256DarkPurpleBlue = color.P256DarkPurpleBlue
P256Indigo = color.P256Indigo
P256Purple = color.P256Purple
P256Violet = color.P256Violet
P256MediumPurple = color.P256MediumPurple
P256Orchid = color.P256Orchid
P256YellowGreen = color.P256YellowGreen
P256Maroon = color.P256Maroon
P256DarkCrimson = color.P256DarkCrimson
P256Crimson = color.P256Crimson
P256Red = color.P256Red
P256Rose = color.P256Rose
P256RedOrange = color.P256RedOrange
P256Orange = color.P256Orange
P256Amber = color.P256Amber
P256Gold = color.P256Gold
P256Yellow = color.P256Yellow
P256DarkAmber = color.P256DarkAmber
P256Gray = color.P256Gray
)
// Cube256 returns the xterm 256-palette index for an RGB cube coordinate.
func Cube256(r, g, b uint8) uint8 {
return color.Cube256(r, g, b)
}
// CubeRGB256 returns the (r, g, b) cube coordinates for a 256-palette color cube index.
func CubeRGB256(index uint8) (r, g, b uint8) {
return color.CubeRGB256(index)
}
// Gray256 returns the xterm 256-palette index for a grayscale step.
func Gray256(step uint8) uint8 {
return color.Gray256(step)
}
-146
View File
@@ -1,146 +0,0 @@
package terminal
import (
"fmt"
"os"
"runtime/debug"
"sync"
)
// TerminalService manages terminal lifecycle and input polling
type TerminalService struct {
term Terminal
colorMode ColorMode
eventCh chan Event
stopCh chan struct{}
doneCh chan struct{}
mu sync.Mutex
running bool
}
// NewService creates a new terminal service
func NewService() *TerminalService {
return &TerminalService{
eventCh: make(chan Event, 256),
stopCh: make(chan struct{}),
doneCh: make(chan struct{}),
}
}
// Name implements Service
func (s *TerminalService) Name() string {
return "terminal"
}
// Dependencies implements Service
func (s *TerminalService) Dependencies() []string {
return nil
}
// Init implements Service
// args[0]: ColorMode (optional, defaults to DetectColorMode())
func (s *TerminalService) Init(args ...any) error {
s.colorMode = DetectColorMode()
if len(args) > 0 {
if cm, ok := args[0].(ColorMode); ok {
s.colorMode = cm
}
}
s.term = New(s.colorMode)
if err := s.term.Init(); err != nil {
return fmt.Errorf("terminal init: %w", err)
}
// Enable mouse click reporting
if err := s.term.SetMouseMode(MouseModeClick); err != nil {
// No-op for mouse error, continue
}
return nil
}
// Start implements Service - launches input polling goroutine
func (s *TerminalService) Start() error {
s.mu.Lock()
if s.running {
s.mu.Unlock()
return nil
}
s.running = true
s.mu.Unlock()
go s.pollLoop()
return nil
}
// pollLoop reads input events until stop signal
func (s *TerminalService) pollLoop() {
defer close(s.doneCh)
defer func() {
if r := recover(); r != nil {
EmergencyReset(os.Stdout)
os.Stdout.Sync()
os.Stderr.Sync()
fmt.Fprintf(os.Stderr, "\r\n\x1b[31mTERMINAL POLL CRASHED: %v\x1b[0m\r\n", r)
fmt.Fprintf(os.Stderr, "Stack Trace:\r\n%s\r\n", debug.Stack())
os.Stderr.Sync()
os.Exit(1)
}
}()
for {
select {
case <-s.stopCh:
return
default:
}
ev := s.term.PollEvent()
if ev.Type == EventClosed || ev.Type == EventError {
return
}
select {
case s.eventCh <- ev:
case <-s.stopCh:
return
}
}
}
// Stop implements Service - signals stop and restores terminal
func (s *TerminalService) Stop() error {
s.mu.Lock()
if !s.running {
s.mu.Unlock()
return nil
}
s.running = false
s.mu.Unlock()
close(s.stopCh)
// Post synthetic close event to unblock PollEvent
if s.term != nil {
s.term.PostEvent(Event{Type: EventClosed})
}
<-s.doneCh
if s.term != nil {
s.term.Fini()
}
return nil
}
// Terminal returns the wrapped terminal instance
func (s *TerminalService) Terminal() Terminal {
return s.term
}
// Events returns the input event channel
func (s *TerminalService) Events() <-chan Event {
return s.eventCh
}