loop

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SHIFT_INDICATOR  int = 1 << 2
	ALT_INDICATOR        = 1 << 3
	CTRL_INDICATOR       = 1 << 4
	MOTION_INDICATOR     = 1 << 5
)
View Source
const (
	LEGACY_KEYS                     KeyboardStateBits = 0
	DISAMBIGUATE_KEYS                                 = 1
	REPORT_KEY_EVENT_TYPES                            = 2
	REPORT_ALTERNATE_KEYS                             = 4
	REPORT_ALL_KEYS_AS_ESCAPE_CODES                   = 8
	REPORT_TEXT_WITH_KEYS                             = 16
	FULL_KEYBOARD_PROTOCOL                            = DISAMBIGUATE_KEYS | REPORT_ALTERNATE_KEYS | REPORT_ALL_KEYS_AS_ESCAPE_CODES | REPORT_TEXT_WITH_KEYS | REPORT_KEY_EVENT_TYPES
	NO_KEYBOARD_STATE_CHANGE                          = 32
)
View Source
const (
	SAVE_CURSOR                   = "\0337"
	RESTORE_CURSOR                = "\0338"
	SAVE_PRIVATE_MODE_VALUES      = "\033[?s"
	RESTORE_PRIVATE_MODE_VALUES   = "\033[?r"
	SAVE_COLORS                   = "\033[#P"
	RESTORE_COLORS                = "\033[#Q"
	DECSACE_DEFAULT_REGION_SELECT = "\033[*x"
	CLEAR_SCREEN                  = "\033[H\033[2J"
)
View Source
const MoveCursorToTemplate = "\x1b[%d;%dH"

Variables

View Source
var SIGNULL unix.Signal

Functions

func CursorShape

func CursorShape(shape CursorShapes, blink bool) string

func EscapeCodeToSetWindowTitle

func EscapeCodeToSetWindowTitle(title string) string

func FullKeyboardProtocol

func FullKeyboardProtocol(self *Loop)

func MouseTrackingMode

func MouseTrackingMode(self *Loop, mt MouseTracking)

func NoAlternateScreen

func NoAlternateScreen(self *Loop)

func NoInBandResizeNotifications

func NoInBandResizeNotifications(self *Loop)

func NoKeyboardStateChange

func NoKeyboardStateChange(self *Loop)

func NoMouseTracking

func NoMouseTracking(self *Loop)

func NoRestoreColors

func NoRestoreColors(self *Loop)

func OnlyDisambiguateKeys

func OnlyDisambiguateKeys(self *Loop)

Types

type CursorShapes

type CursorShapes uint
const (
	BLOCK_CURSOR     CursorShapes = 1
	UNDERLINE_CURSOR CursorShapes = 3
	BAR_CURSOR       CursorShapes = 5
)

type DefaultColor

type DefaultColor int
const (
	BACKGROUND   DefaultColor = 11
	FOREGROUND   DefaultColor = 10
	CURSOR       DefaultColor = 12
	SELECTION_BG DefaultColor = 17
	SELECTION_FG DefaultColor = 19
)

type EscapeCodeType

type EscapeCodeType int
const (
	CSI EscapeCodeType = iota
	DCS
	OSC
	APC
	SOS
	PM
)

type IdType

type IdType uint64

type KeyEvent

type KeyEvent struct {
	Type         KeyEventType
	Mods         KeyModifiers
	Key          string
	ShiftedKey   string
	AlternateKey string
	Text         string
	Handled      bool

	// The CSI string this key event was decoded from. Empty if not decoded from CSI.
	CSI string
}

func KeyEventFromCSI

func KeyEventFromCSI(csi string) *KeyEvent

func (*KeyEvent) AsCSI

func (self *KeyEvent) AsCSI() string

func (*KeyEvent) HasCapsLock

func (self *KeyEvent) HasCapsLock() bool

func (*KeyEvent) Matches

func (self *KeyEvent) Matches(spec string, event_type KeyEventType) bool

func (*KeyEvent) MatchesCaseInsensitiveTextOrKey

func (self *KeyEvent) MatchesCaseInsensitiveTextOrKey(spec string) bool

func (*KeyEvent) MatchesCaseSensitiveTextOrKey

func (self *KeyEvent) MatchesCaseSensitiveTextOrKey(spec string) bool

func (*KeyEvent) MatchesParsedShortcut

func (self *KeyEvent) MatchesParsedShortcut(ps *ParsedShortcut, event_type KeyEventType) bool

func (*KeyEvent) MatchesPressOrRepeat

func (self *KeyEvent) MatchesPressOrRepeat(spec string) bool

func (*KeyEvent) MatchesRelease

func (self *KeyEvent) MatchesRelease(spec string) bool

func (*KeyEvent) String

func (self *KeyEvent) String() string

type KeyEventType

type KeyEventType uint8
const (
	PRESS   KeyEventType = 1
	REPEAT  KeyEventType = 2
	RELEASE KeyEventType = 4
)

func (KeyEventType) String

func (self KeyEventType) String() string

type KeyModifiers

type KeyModifiers uint16
const (
	SHIFT     KeyModifiers = 1
	ALT       KeyModifiers = 2
	CTRL      KeyModifiers = 4
	SUPER     KeyModifiers = 8
	HYPER     KeyModifiers = 16
	META      KeyModifiers = 32
	CAPS_LOCK KeyModifiers = 64
	NUM_LOCK  KeyModifiers = 128
)

func (KeyModifiers) HasCapsLock

func (self KeyModifiers) HasCapsLock() bool

func (KeyModifiers) String

func (self KeyModifiers) String() string

func (KeyModifiers) WithoutLocks

func (self KeyModifiers) WithoutLocks() KeyModifiers

type KeyboardStateBits

type KeyboardStateBits uint8

type Loop

type Loop struct {

	// Suspend the loop restoring terminal state, and run the provided function. When it returns terminal state is
	// put back to what it was before suspending unless the function returns an error or an error occurs saving/restoring state.
	SuspendAndRun func(func() error) error

	// Called when the terminal has been fully setup. Any string returned is sent to
	// the terminal on shutdown
	OnInitialize func() (string, error)

	// Called just before the loop shuts down. Any returned string is written to the terminal before
	// shutdown
	OnFinalize func() string

	// Called when a key event happens
	OnKeyEvent func(event *KeyEvent) error

	// Called when a mouse event happens
	OnMouseEvent func(event *MouseEvent) error

	// Called when text is received either from a key event or directly from the terminal
	// Called with an empty string when bracketed paste ends
	OnText func(text string, from_key_event bool, in_bracketed_paste bool) error

	// Called when the terminal is resized
	OnResize func(old_size ScreenSize, new_size ScreenSize) error

	// Called when writing is done
	OnWriteComplete func(msg_id IdType, has_pending_writes bool) error

	// Called when a response to an rc command is received
	OnRCResponse func(data []byte) error

	// Called when a response to a query command is received
	OnQueryResponse func(key, val string, valid bool) error

	// Called when any input from tty is received
	OnReceivedData func(data []byte) error

	// Called when an escape code is received that is not handled by any other handler
	OnEscapeCode func(EscapeCodeType, []byte) error

	// Called when resuming from a SIGTSTP or Ctrl-z
	OnResumeFromStop func() error

	// Called when main loop is woken up
	OnWakeup func() error

	// Called on SIGINT return true if you wish to handle it yourself
	OnSIGINT func() (bool, error)

	// Called on SIGTERM return true if you wish to handle it yourself
	OnSIGTERM func() (bool, error)
	// contains filtered or unexported fields
}

func New

func New(options ...func(self *Loop)) (*Loop, error)

func (*Loop) AddTimer

func (self *Loop) AddTimer(interval time.Duration, repeats bool, callback TimerCallback) (IdType, error)

func (*Loop) AllowLineWrapping

func (self *Loop) AllowLineWrapping(allow bool)

func (*Loop) Beep

func (self *Loop) Beep()

func (*Loop) CallSoon

func (self *Loop) CallSoon(callback TimerCallback) (IdType, error)

func (*Loop) ClearPointerShapes

func (self *Loop) ClearPointerShapes() (ans []PointerShape)

Remove all pointer shapes from the shape stack resetting to default pointer shape. This is called automatically on loop termination.

func (*Loop) ClearScreen

func (self *Loop) ClearScreen()

func (*Loop) ClearScreenButNotGraphics

func (self *Loop) ClearScreenButNotGraphics()

func (*Loop) ClearToEndOfLine

func (self *Loop) ClearToEndOfLine()

func (*Loop) ClearToEndOfScreen

func (self *Loop) ClearToEndOfScreen()

func (*Loop) CopyTextToClipboard

func (self *Loop) CopyTextToClipboard(text string)

func (*Loop) CopyTextToPrimarySelection

func (self *Loop) CopyTextToPrimarySelection(text string)

func (*Loop) CurrentPointerShape

func (self *Loop) CurrentPointerShape() (ans PointerShape, has_shape bool)

func (*Loop) DeathSignalName

func (self *Loop) DeathSignalName() string

func (*Loop) DebugPrintln

func (self *Loop) DebugPrintln(args ...any)

func (*Loop) EndAtomicUpdate

func (self *Loop) EndAtomicUpdate()

func (*Loop) EndBracketedPaste

func (self *Loop) EndBracketedPaste()

func (*Loop) ExitCode

func (self *Loop) ExitCode() int

func (*Loop) FullKeyboardProtocol

func (self *Loop) FullKeyboardProtocol() *Loop

func (*Loop) IsAtomicUpdateActive

func (self *Loop) IsAtomicUpdateActive() bool

func (*Loop) KillIfSignalled

func (self *Loop) KillIfSignalled()

func (*Loop) MouseTrackingMode

func (self *Loop) MouseTrackingMode(mt MouseTracking) *Loop

func (*Loop) MoveCursorHorizontally

func (self *Loop) MoveCursorHorizontally(amt int)

func (*Loop) MoveCursorTo

func (self *Loop) MoveCursorTo(x, y int)

func (*Loop) MoveCursorVertically

func (self *Loop) MoveCursorVertically(amt int)

func (*Loop) NoAlternateScreen

func (self *Loop) NoAlternateScreen() *Loop

func (*Loop) NoKeyboardStateChange

func (self *Loop) NoKeyboardStateChange() *Loop

func (*Loop) NoMouseTracking

func (self *Loop) NoMouseTracking() *Loop

func (*Loop) NoRestoreColors

func (self *Loop) NoRestoreColors() *Loop

func (*Loop) OnlyDisambiguateKeys

func (self *Loop) OnlyDisambiguateKeys() *Loop

func (*Loop) PopPointerShape

func (self *Loop) PopPointerShape()

func (*Loop) PrintStyled

func (self *Loop) PrintStyled(style string, args ...any)

func (*Loop) Printf

func (self *Loop) Printf(format string, args ...any)

func (*Loop) Println

func (self *Loop) Println(args ...any)

func (*Loop) PushPointerShape

func (self *Loop) PushPointerShape(s PointerShape)

func (*Loop) QueryTerminal

func (self *Loop) QueryTerminal(fields ...string) IdType

func (*Loop) QueueWriteBytesCopy

func (self *Loop) QueueWriteBytesCopy(data []byte) IdType

func (*Loop) QueueWriteString

func (self *Loop) QueueWriteString(data string) IdType

func (*Loop) Quit

func (self *Loop) Quit(exit_code int)

func (*Loop) RemoveTimer

func (self *Loop) RemoveTimer(id IdType) bool

func (*Loop) RestoreCursorPosition

func (self *Loop) RestoreCursorPosition()

func (*Loop) Run

func (self *Loop) Run() (err error)

func (*Loop) SaveCursorPosition

func (self *Loop) SaveCursorPosition()

func (*Loop) ScreenSize

func (self *Loop) ScreenSize() (ScreenSize, error)

func (*Loop) SendOverlayReady

func (self *Loop) SendOverlayReady()

func (*Loop) SetCursorShape

func (self *Loop) SetCursorShape(shape CursorShapes, blink bool)

func (*Loop) SetCursorVisible

func (self *Loop) SetCursorVisible(visible bool)

func (*Loop) SetDefaultColor

func (self *Loop) SetDefaultColor(which DefaultColor, val style.RGBA)

func (*Loop) SetWindowTitle

func (self *Loop) SetWindowTitle(title string)

func (*Loop) SprintStyled

func (self *Loop) SprintStyled(style string, args ...any) string

func (*Loop) StartAtomicUpdate

func (self *Loop) StartAtomicUpdate()

func (*Loop) StartBracketedPaste

func (self *Loop) StartBracketedPaste()

func (*Loop) StyleRectangle

func (self *Loop) StyleRectangle(style string, start_x, start_y, end_x, end_y int) IdType

Apply the specified style to the specified rectangle of the screen (0-based indexing).

func (*Loop) StyleRegion

func (self *Loop) StyleRegion(style string, start_x, start_y, end_x, end_y int) IdType

Apply the specified style to the specified region of the screen (0-based indexing). The region is all cells from the start cell to the end cell. See StyleRectangle to apply style to a rectangular area.

func (*Loop) UnsafeQueueWriteBytes

func (self *Loop) UnsafeQueueWriteBytes(data []byte) IdType

This is dangerous as it is upto the calling code to ensure the data in the underlying array does not change

func (*Loop) WakeupMainThread

func (self *Loop) WakeupMainThread() bool

type Mode

type Mode uint32
const (
	LNM                        Mode = 20
	IRM                        Mode = 4
	DECKM                      Mode = 1 | private
	DECSCNM                    Mode = 5 | private
	DECOM                      Mode = 6 | private
	DECAWM                     Mode = 7 | private
	DECARM                     Mode = 8 | private
	DECTCEM                    Mode = 25 | private
	MOUSE_BUTTON_TRACKING      Mode = 1000 | private
	MOUSE_MOTION_TRACKING      Mode = 1002 | private
	MOUSE_MOVE_TRACKING        Mode = 1003 | private
	FOCUS_TRACKING             Mode = 1004 | private
	MOUSE_UTF8_MODE            Mode = 1005 | private
	MOUSE_SGR_MODE             Mode = 1006 | private
	MOUSE_URXVT_MODE           Mode = 1015 | private
	MOUSE_SGR_PIXEL_MODE       Mode = 1016 | private
	ALTERNATE_SCREEN           Mode = 1049 | private
	BRACKETED_PASTE            Mode = 2004 | private
	PENDING_UPDATE             Mode = 2026 | private
	INBAND_RESIZE_NOTIFICATION Mode = 2048 | private
	HANDLE_TERMIOS_SIGNALS     Mode = kitty.HandleTermiosSignals | private
)

func (Mode) EscapeCodeToReset

func (self Mode) EscapeCodeToReset() string

func (Mode) EscapeCodeToSet

func (self Mode) EscapeCodeToSet() string

type MouseButtonFlag

type MouseButtonFlag uint
const (
	NO_MOUSE_BUTTON   MouseButtonFlag = 0
	LEFT_MOUSE_BUTTON MouseButtonFlag = 1 << iota
	MIDDLE_MOUSE_BUTTON
	RIGHT_MOUSE_BUTTON
	FOURTH_MOUSE_BUTTON
	FIFTH_MOUSE_BUTTON
	SIXTH_MOUSE_BUTTON
	SEVENTH_MOUSE_BUTTON
	MOUSE_WHEEL_UP
	MOUSE_WHEEL_DOWN
	MOUSE_WHEEL_LEFT
	MOUSE_WHEEL_RIGHT
)

func (MouseButtonFlag) String

func (b MouseButtonFlag) String() string

type MouseEvent

type MouseEvent struct {
	Event_type  MouseEventType
	Buttons     MouseButtonFlag
	Mods        KeyModifiers
	Cell, Pixel struct{ X, Y int }
}

func MouseEventFromCSI

func MouseEventFromCSI(csi string, screen_size ScreenSize) *MouseEvent

func (MouseEvent) String

func (e MouseEvent) String() string

type MouseEventType

type MouseEventType uint
const (
	MOUSE_PRESS MouseEventType = iota
	MOUSE_RELEASE
	MOUSE_MOVE
	MOUSE_CLICK
)

func (MouseEventType) String

func (e MouseEventType) String() string

type MouseTracking

type MouseTracking uint8
const (
	NO_MOUSE_TRACKING MouseTracking = iota
	BUTTONS_ONLY_MOUSE_TRACKING
	BUTTONS_AND_DRAG_MOUSE_TRACKING
	FULL_MOUSE_TRACKING
)

type ParsedShortcut

type ParsedShortcut struct {
	Mods    KeyModifiers
	KeyName string
}

func ParseShortcut

func ParseShortcut(spec string) *ParsedShortcut

func (*ParsedShortcut) String

func (self *ParsedShortcut) String() string

type PointerShape

type PointerShape uint8
const (
	// start pointer shape enum (auto generated by gen-key-constants.py do not edit)
	DEFAULT_POINTER       PointerShape = 0
	TEXT_POINTER          PointerShape = 1
	POINTER_POINTER       PointerShape = 2
	HELP_POINTER          PointerShape = 3
	WAIT_POINTER          PointerShape = 4
	PROGRESS_POINTER      PointerShape = 5
	CROSSHAIR_POINTER     PointerShape = 6
	CELL_POINTER          PointerShape = 7
	VERTICAL_TEXT_POINTER PointerShape = 8
	MOVE_POINTER          PointerShape = 9
	E_RESIZE_POINTER      PointerShape = 10
	NE_RESIZE_POINTER     PointerShape = 11
	NW_RESIZE_POINTER     PointerShape = 12
	N_RESIZE_POINTER      PointerShape = 13
	SE_RESIZE_POINTER     PointerShape = 14
	SW_RESIZE_POINTER     PointerShape = 15
	S_RESIZE_POINTER      PointerShape = 16
	W_RESIZE_POINTER      PointerShape = 17
	EW_RESIZE_POINTER     PointerShape = 18
	NS_RESIZE_POINTER     PointerShape = 19
	NESW_RESIZE_POINTER   PointerShape = 20
	NWSE_RESIZE_POINTER   PointerShape = 21
	ZOOM_IN_POINTER       PointerShape = 22
	ZOOM_OUT_POINTER      PointerShape = 23
	ALIAS_POINTER         PointerShape = 24
	COPY_POINTER          PointerShape = 25
	NOT_ALLOWED_POINTER   PointerShape = 26
	NO_DROP_POINTER       PointerShape = 27
	GRAB_POINTER          PointerShape = 28
	GRABBING_POINTER      PointerShape = 29
)

func (PointerShape) String

func (e PointerShape) String() string

type ScreenSize

type ScreenSize struct {
	WidthCells, HeightCells, WidthPx, HeightPx, CellWidth, CellHeight uint
	// contains filtered or unexported fields
}

type TerminalStateOptions

type TerminalStateOptions struct {
	Alternate_screen bool
	// contains filtered or unexported fields
}

func (*TerminalStateOptions) ResetStateEscapeCodes

func (self *TerminalStateOptions) ResetStateEscapeCodes() string

func (*TerminalStateOptions) SetStateEscapeCodes

func (self *TerminalStateOptions) SetStateEscapeCodes() string

type TimerCallback

type TimerCallback func(timer_id IdType) error

Jump to

Keyboard shortcuts

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