focus

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 0 Imported by: 2

Documentation

Overview

Package focus is a small, pure focus-ring state machine shared by every chatshell screen. It replaces the boolean flags DataTug's chat UI used (gridFocused, messageFocused, workspaceFocused, ...) with a single source of truth: which Zone holds focus and, when the zone is Transcript, which "stop" (an index into the transcript's ordered list of focusable entries, e.g. result grids and user messages) is focused.

Semantics (identical to DataTug's chat UI, generalised):

  • Shift+Up from an empty input focuses the latest (bottom-most) focusable transcript stop.
  • Shift+Up / Shift+Down move between transcript stops.
  • Shift+Down past the last stop returns focus to the input.
  • Shift+Right moves focus to the sidebar, remembering where focus was so Shift+Left can return to it.
  • Shift+Left, from the sidebar, returns focus to the remembered zone/stop.
  • Esc always returns focus to the input.

Ring holds no rendering state and knows nothing about tea.Msg; callers decide which key presses trigger which method (see tui/chatshell).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

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

Ring is the focus-ring state machine. The zero value is ready to use and starts focused on the input, matching New().

func New

func New() *Ring

New returns a Ring focused on the input.

func (*Ring) Esc

func (r *Ring) Esc()

Esc always returns focus to the input.

func (*Ring) FocusInput

func (r *Ring) FocusInput()

FocusInput focuses the composer directly (equivalent to Esc).

func (*Ring) FocusSidebar

func (r *Ring) FocusSidebar()

FocusSidebar moves focus to the sidebar, remembering the current zone/stop so ShiftLeft can return to it. A no-op when already in the sidebar.

func (*Ring) FocusStop

func (r *Ring) FocusStop(index int)

FocusStop focuses transcript stop index directly, e.g. after a click or an Enter-driven navigation elsewhere in the product. index must be a valid stop (the caller is expected to have checked it against the current stop count); an out-of-range index is clamped to input focus.

func (*Ring) ShiftDown

func (r *Ring) ShiftDown(stops int) bool

ShiftDown implements Shift+Down: moves toward later transcript stops, and past the last stop returns focus to the input. It reports whether focus moved.

func (*Ring) ShiftLeft

func (r *Ring) ShiftLeft(stops int) bool

ShiftLeft implements Shift+Left: returns focus from the sidebar to where it was before ShiftRight. stops is the CURRENT number of focusable transcript entries: when the remembered zone was Transcript and its stop no longer exists (entries were removed while the sidebar had focus), the returned stop is clamped to the last valid one, or to Input when there are no stops left at all. It reports whether focus moved.

func (*Ring) ShiftRight

func (r *Ring) ShiftRight() bool

ShiftRight implements Shift+Right: moves focus into the sidebar. Callers gate this on the sidebar being visible/split. It reports whether focus moved.

func (*Ring) ShiftUp

func (r *Ring) ShiftUp(stops int) bool

ShiftUp implements Shift+Up. stops is the current number of focusable transcript entries. It reports whether focus moved.

func (*Ring) Stop

func (r *Ring) Stop() int

Stop reports the focused transcript stop index. It is only meaningful when Zone() == ZoneTranscript; otherwise it returns -1.

func (*Ring) Zone

func (r *Ring) Zone() Zone

Zone reports which region currently holds focus.

type Zone

type Zone int

Zone identifies which region of the chat screen holds focus.

const (
	// ZoneInput is the composer (textarea).
	ZoneInput Zone = iota
	// ZoneTranscript is one of the transcript's focusable stops (Stop()).
	ZoneTranscript
	// ZoneSidebar is the working-context sidebar.
	ZoneSidebar
)

func (Zone) String

func (z Zone) String() string

Jump to

Keyboard shortcuts

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