model

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package model provides rich domain models for terminal operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RawMode

type RawMode struct {
	// contains filtered or unexported fields
}

RawMode represents terminal raw mode state (entity with lifecycle).

Raw mode disables:

  • Line buffering (input available immediately)
  • Echo (typed characters not displayed)
  • Signal generation (Ctrl+C doesn't send SIGINT)
  • Input processing (Ctrl+S/Q, CR->NL translation)

This entity stores the original terminal state for restoration.

Invariants:

  • OriginalState is never nil after creation
  • Enabled flag accurately reflects raw mode status

Lifecycle:

  1. Created with original terminal state
  2. Enabled (raw mode activated)
  3. Disabled (terminal restored)

Platform-specific state:

  • Unix: syscall.Termios
  • Windows: uint32 (console mode)

func NewRawMode

func NewRawMode(originalState interface{}) (*RawMode, error)

NewRawMode creates raw mode entity with original state. The state type depends on platform:

  • Unix: syscall.Termios
  • Windows: uint32

func (*RawMode) Disable

func (r *RawMode) Disable() *RawMode

Disable marks raw mode as disabled (immutable). Returns new RawMode instance with enabled flag cleared.

func (*RawMode) Enable

func (r *RawMode) Enable() *RawMode

Enable marks raw mode as enabled (immutable). Returns new RawMode instance with enabled flag set.

func (*RawMode) IsEnabled

func (r *RawMode) IsEnabled() bool

IsEnabled returns true if raw mode is active.

func (*RawMode) OriginalState

func (r *RawMode) OriginalState() interface{}

OriginalState returns the saved terminal state for restoration. Type depends on platform - caller must type assert.

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

Terminal represents a terminal instance with its capabilities and state. This is the aggregate root for terminal operations.

Invariants:

  • Capabilities is never nil
  • Size is always valid (width, height >= 1)
  • Terminal is immutable after creation

Lifecycle:

  • Created with detected capabilities
  • Can be put into raw mode (creates RawMode entity)
  • Size can be updated on SIGWINCH

func NewTerminal

func NewTerminal(caps *value2.Capabilities) *Terminal

NewTerminal creates a new Terminal with detected capabilities. Initial size defaults to 80x24 if not specified.

func (*Terminal) Capabilities

func (t *Terminal) Capabilities() *value2.Capabilities

Capabilities returns terminal capabilities (immutable).

func (*Terminal) ColorDepth

func (t *Terminal) ColorDepth() value2.ColorDepth

ColorDepth is a convenience method for getting color depth.

func (*Terminal) IsRawMode

func (t *Terminal) IsRawMode() bool

IsRawMode returns true if terminal is in raw mode.

func (*Terminal) RawMode

func (t *Terminal) RawMode() *RawMode

RawMode returns the raw mode entity (nil if not in raw mode).

func (*Terminal) Size

func (t *Terminal) Size() value2.Size

Size returns current terminal size.

func (*Terminal) SupportsANSI

func (t *Terminal) SupportsANSI() bool

SupportsANSI is a convenience method for checking ANSI support.

func (*Terminal) SupportsColor

func (t *Terminal) SupportsColor() bool

SupportsColor is a convenience method for checking color support.

func (*Terminal) WithRawMode

func (t *Terminal) WithRawMode(rawMode *RawMode) *Terminal

WithRawMode returns new Terminal in raw mode (immutable). The RawMode entity contains the original terminal state for restoration.

func (*Terminal) WithSize

func (t *Terminal) WithSize(size value2.Size) *Terminal

WithSize returns new Terminal with updated size (immutable). This is called when SIGWINCH is received.

func (*Terminal) WithoutRawMode

func (t *Terminal) WithoutRawMode() *Terminal

WithoutRawMode returns new Terminal not in raw mode (immutable). This is called after raw mode is successfully disabled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL