server

package
v0.0.0-...-ccc1ece Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "0.1.0-alpha"

Variables

This section is empty.

Functions

func CreateEvent

func CreateEvent(sessionID string, eventData interface{}) *pb.Event

CreateEvent creates a new event with timestamp

Types

type DragMode

type DragMode int

DragMode identifies the type of drag operation.

const (
	DragModeNone DragMode = iota
	DragModeMove
	DragModeResizeLeft
	DragModeResizeRight
	DragModeResizeTop
	DragModeResizeBottom
	DragModeResizeTopLeft
	DragModeResizeTopRight
	DragModeResizeBottomLeft
	DragModeResizeBottomRight
)

type DragState

type DragState struct {
	Active    bool
	Window    *WindowPrimitive
	Mode      DragMode
	StartX    int // Mouse position at drag start
	StartY    int
	StartRect Rect // Window rect at drag start
}

DragState tracks an active drag operation.

type EventDispatcher

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

EventDispatcher manages event subscriptions and dispatching

func NewEventDispatcher

func NewEventDispatcher() *EventDispatcher

NewEventDispatcher creates a new event dispatcher

func (*EventDispatcher) Dispatch

func (d *EventDispatcher) Dispatch(event *pb.Event)

Dispatch sends an event to the appropriate subscriber(s)

func (*EventDispatcher) Subscribe

func (d *EventDispatcher) Subscribe(sessionID string, filter *pb.EventFilter) *EventSubscriber

Subscribe creates a new event subscription for a session

func (*EventDispatcher) Unsubscribe

func (d *EventDispatcher) Unsubscribe(sessionID string)

Unsubscribe removes a session's event subscription

func (*EventDispatcher) UpdateFilter

func (d *EventDispatcher) UpdateFilter(sessionID string, filter *pb.EventFilter) bool

UpdateFilter updates the filter for a session's subscription

type EventSubscriber

type EventSubscriber struct {
	SessionID string
	Filter    *pb.EventFilter
	Events    chan *pb.Event
	Done      chan struct{}
	// contains filtered or unexported fields
}

EventSubscriber represents a client's event subscription

func (*EventSubscriber) IsClosed

func (s *EventSubscriber) IsClosed() bool

IsClosed returns true if the subscriber has been closed

type HitZone

type HitZone int

HitZone identifies which part of a window was clicked.

const (
	HitZoneNone HitZone = iota
	HitZoneTitleBar
	HitZoneCloseButton
	HitZoneMaximizeButton
	HitZoneMinimizeButton
	HitZoneBorderLeft
	HitZoneBorderRight
	HitZoneBorderTop
	HitZoneBorderBottom
	HitZoneCornerTopLeft
	HitZoneCornerTopRight
	HitZoneCornerBottomLeft
	HitZoneCornerBottomRight
	HitZoneInterior
)
type MenuBarPrimitive struct {
	*tview.Box
	// contains filtered or unexported fields
}

MenuBarPrimitive is a custom tview.Primitive that renders a horizontal menu bar with dropdown menus. It supports mouse clicks and keyboard navigation.

func NewMenuBarPrimitive

func NewMenuBarPrimitive() *MenuBarPrimitive

NewMenuBarPrimitive creates a new menu bar.

func (mb *MenuBarPrimitive) AddMenu(menu *MenuEntry)

AddMenu adds a menu to the menu bar.

func (mb *MenuBarPrimitive) CloseMenu()

CloseMenu closes any open dropdown.

func (mb *MenuBarPrimitive) Draw(screen tcell.Screen)

Draw renders the menu bar and any open dropdown.

func (mb *MenuBarPrimitive) Focus(delegate func(p tview.Primitive))

Focus is called when the menu bar receives focus.

func (mb *MenuBarPrimitive) GetMenu(menuID string) *MenuEntry

GetMenu returns a menu by ID.

func (mb *MenuBarPrimitive) GetMenus() []*MenuEntry

GetMenus returns all menus (for testing/introspection).

func (mb *MenuBarPrimitive) HasFocus() bool

HasFocus returns true if the menu bar has focus.

func (mb *MenuBarPrimitive) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler returns the key event handler.

func (mb *MenuBarPrimitive) IsMenuOpen() bool

IsMenuOpen returns whether a dropdown is currently open.

func (mb *MenuBarPrimitive) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)

MouseHandler returns the mouse event handler.

func (mb *MenuBarPrimitive) RemoveMenu(menuID string) bool

RemoveMenu removes a menu by ID.

func (mb *MenuBarPrimitive) SetActiveBackgroundColor(c tcell.Color)

SetActiveBackgroundColor sets the active menu title background.

func (mb *MenuBarPrimitive) SetActiveTextColor(c tcell.Color)

SetActiveTextColor sets the active menu title text color.

func (mb *MenuBarPrimitive) SetBarBackgroundColor(c tcell.Color)

SetBackgroundColor sets the menu bar background color.

func (mb *MenuBarPrimitive) SetBarTextColor(c tcell.Color)

SetTextColor sets the menu bar text color.

func (mb *MenuBarPrimitive) SetOnItemSelected(fn func(menuBarID, menuID, menuItemID, label string))

SetOnItemSelected sets the callback for when a menu item is selected.

func (mb *MenuBarPrimitive) SetPreviousFocus(p tview.Primitive)

SetPreviousFocus stores the widget that had focus before the menu opened.

type MenuEntry struct {
	ID    string
	Title string
	Items []*MenuItemEntry
}

MenuEntry represents a menu that belongs to a menu bar.

type MenuItemEntry struct {
	ID              string
	Label           string
	ShortcutDisplay string
	Separator       bool
	Disabled        bool
}

MenuItemEntry represents a single item in a menu.

type Rect

type Rect struct {
	X, Y, Width, Height int
}

Rect is a simple rectangle.

type Server

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

Server represents the Yutani display server

func New

func New(cfg *config.Config, opts ...ServerOption) (*Server, error)

New creates a new Yutani server with the given configuration and options.

func NewTestServer

func NewTestServer(maxSessions int) (*Server, error)

NewTestServer creates a server for testing with simulation screen. This is a convenience wrapper around New() with test mode enabled.

func (*Server) App

func (s *Server) App() *tview.Application

App returns the tview application

func (*Server) Events

func (s *Server) Events() *EventDispatcher

Events returns the event dispatcher

func (*Server) GetSimulationScreen

func (s *Server) GetSimulationScreen() tcell.SimulationScreen

GetSimulationScreen returns the simulation screen if in test mode, nil otherwise. Callers should check IsTestMode() first or handle nil.

func (*Server) IsRunning

func (s *Server) IsRunning() bool

IsRunning returns whether the server is currently running

func (*Server) IsTestMode

func (s *Server) IsTestMode() bool

IsTestMode returns whether the server is running in test mode

func (*Server) MaxSessions

func (s *Server) MaxSessions() int

MaxSessions returns the maximum number of sessions

func (*Server) Run

func (s *Server) Run() error

Run starts the TUI application (blocking call) This should be called from the main goroutine

func (*Server) Screen

func (s *Server) Screen() tcell.Screen

Screen returns the tcell screen

func (*Server) Sessions

func (s *Server) Sessions() *SessionRegistry

Sessions returns the session registry

func (*Server) Start

func (s *Server) Start() error

Start initializes the TUI (does not block)

func (*Server) Stop

func (s *Server) Stop()

Stop stops the server

func (*Server) Widgets

func (s *Server) Widgets() *WidgetRegistry

Widgets returns the widget registry

type ServerOption

type ServerOption func(*Server)

ServerOption is a function that configures a Server.

func WithTestMode

func WithTestMode(testMode bool) ServerOption

WithTestMode configures the server to run in test mode.

type Session

type Session struct {
	ID          string
	ClientName  string
	CreatedAt   time.Time
	Preferences SessionPreferences
}

Session represents a client session

type SessionPreferences

type SessionPreferences struct {
	ReceiveMouseEvents  bool
	ReceiveKeyEvents    bool
	ReceiveResizeEvents bool
}

SessionPreferences holds session-specific preferences

type SessionRegistry

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

SessionRegistry manages active sessions

func NewSessionRegistry

func NewSessionRegistry(maxSessions int) *SessionRegistry

NewSessionRegistry creates a new session registry

func (*SessionRegistry) Count

func (r *SessionRegistry) Count() int

Count returns the number of active sessions

func (*SessionRegistry) Create

func (r *SessionRegistry) Create(clientName string, prefs SessionPreferences) (*Session, error)

Create creates a new session

func (*SessionRegistry) Delete

func (r *SessionRegistry) Delete(id string) bool

Delete removes a session

func (*SessionRegistry) Exists

func (r *SessionRegistry) Exists(id string) bool

Exists checks if a session exists

func (*SessionRegistry) Get

func (r *SessionRegistry) Get(id string) (*Session, bool)

Get retrieves a session by ID

func (*SessionRegistry) List

func (r *SessionRegistry) List() []string

List returns all active session IDs

func (*SessionRegistry) ListAll

func (r *SessionRegistry) ListAll() []*Session

ListAll returns all active sessions

type WidgetInfo

type WidgetInfo struct {
	ID         string
	SessionID  string
	Type       pb.WidgetType
	Primitive  tview.Primitive
	Properties *pb.WidgetProperties
	ParentID   string
	ChildIDs   []string
}

WidgetInfo stores metadata about a widget

type WidgetRegistry

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

WidgetRegistry manages widgets and their ownership

func NewWidgetRegistry

func NewWidgetRegistry() *WidgetRegistry

NewWidgetRegistry creates a new widget registry

func (*WidgetRegistry) AddChild

func (r *WidgetRegistry) AddChild(parentID, childID string) bool

AddChild adds a child widget to a parent

func (*WidgetRegistry) Count

func (r *WidgetRegistry) Count() int

Count returns the total number of widgets

func (*WidgetRegistry) Delete

func (r *WidgetRegistry) Delete(id string) bool

Delete removes a widget and its children recursively

func (*WidgetRegistry) DeleteBySession

func (r *WidgetRegistry) DeleteBySession(sessionID string) int

DeleteBySession removes all widgets owned by a session

func (*WidgetRegistry) FindByPrimitive

func (r *WidgetRegistry) FindByPrimitive(p tview.Primitive) string

FindByPrimitive returns the widget ID for a given primitive, or "" if not found.

func (*WidgetRegistry) Get

func (r *WidgetRegistry) Get(id string) (tview.Primitive, bool)

Get retrieves a widget primitive by ID

func (*WidgetRegistry) GetInfo

func (r *WidgetRegistry) GetInfo(id string) (*WidgetInfo, bool)

GetInfo retrieves full widget info by ID

func (*WidgetRegistry) GetOwner

func (r *WidgetRegistry) GetOwner(widgetID string) (string, bool)

GetOwner returns the session ID that owns a widget

func (*WidgetRegistry) GetRoot

func (r *WidgetRegistry) GetRoot(sessionID string) (string, bool)

GetRoot returns the root widget ID for a session

func (*WidgetRegistry) ListBySession

func (r *WidgetRegistry) ListBySession(sessionID string) []*WidgetInfo

ListBySession returns all widget infos owned by a session

func (*WidgetRegistry) Register

func (r *WidgetRegistry) Register(sessionID string, widgetType pb.WidgetType, widget tview.Primitive, properties *pb.WidgetProperties) string

Register registers a widget for a session and returns its ID

func (*WidgetRegistry) RemoveChild

func (r *WidgetRegistry) RemoveChild(parentID, childID string) bool

RemoveChild removes a child widget from a parent

func (*WidgetRegistry) SetRoot

func (r *WidgetRegistry) SetRoot(sessionID, widgetID string) bool

SetRoot sets the root widget for a session

func (*WidgetRegistry) UpdateProperties

func (r *WidgetRegistry) UpdateProperties(widgetID string, properties *pb.WidgetProperties) bool

UpdateProperties updates widget properties

type WindowManagerPrimitive

type WindowManagerPrimitive struct {
	*tview.Box
	// contains filtered or unexported fields
}

WindowManagerPrimitive manages child windows with absolute positioning, z-ordering, and drag-to-move/resize.

func NewWindowManagerPrimitive

func NewWindowManagerPrimitive() *WindowManagerPrimitive

NewWindowManagerPrimitive creates a new window manager.

func (*WindowManagerPrimitive) AddWindow

func (wm *WindowManagerPrimitive) AddWindow(win *WindowPrimitive)

AddWindow adds a window to the manager (on top).

func (*WindowManagerPrimitive) BringToFront

func (wm *WindowManagerPrimitive) BringToFront(win *WindowPrimitive)

BringToFront moves a window to the top of the z-order.

func (*WindowManagerPrimitive) Draw

func (wm *WindowManagerPrimitive) Draw(screen tcell.Screen)

Draw renders the window manager and all child windows.

func (*WindowManagerPrimitive) FindWindow

func (wm *WindowManagerPrimitive) FindWindow(win *WindowPrimitive) int

FindWindow returns the window at a given pointer to WindowPrimitive.

func (*WindowManagerPrimitive) Focus

func (wm *WindowManagerPrimitive) Focus(delegate func(p tview.Primitive))

Focus delegates to the frontmost window.

func (*WindowManagerPrimitive) GetWindows

func (wm *WindowManagerPrimitive) GetWindows() []*WindowPrimitive

GetWindows returns the internal window list (back-to-front).

func (*WindowManagerPrimitive) GetZOrder

func (wm *WindowManagerPrimitive) GetZOrder() []*WindowPrimitive

GetZOrder returns window list from front to back.

func (*WindowManagerPrimitive) HasFocus

func (wm *WindowManagerPrimitive) HasFocus() bool

HasFocus returns whether any window has focus.

func (*WindowManagerPrimitive) InputHandler

func (wm *WindowManagerPrimitive) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler delegates keyboard input to the frontmost window.

func (*WindowManagerPrimitive) MouseHandler

func (wm *WindowManagerPrimitive) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)

MouseHandler is the central mouse dispatcher for the window manager.

func (*WindowManagerPrimitive) RemoveWindow

func (wm *WindowManagerPrimitive) RemoveWindow(win *WindowPrimitive) bool

RemoveWindow removes a window from the manager.

func (*WindowManagerPrimitive) SendToBack

func (wm *WindowManagerPrimitive) SendToBack(win *WindowPrimitive)

SendToBack moves a window to the bottom of the z-order.

func (*WindowManagerPrimitive) SetBgColor

func (wm *WindowManagerPrimitive) SetBgColor(c tcell.Color)

SetBgColor sets the background fill color.

func (*WindowManagerPrimitive) SetOnWindowActivated

func (wm *WindowManagerPrimitive) SetOnWindowActivated(f func(win *WindowPrimitive))

func (*WindowManagerPrimitive) SetOnWindowClosed

func (wm *WindowManagerPrimitive) SetOnWindowClosed(f func(win *WindowPrimitive))

func (*WindowManagerPrimitive) SetOnWindowMoved

func (wm *WindowManagerPrimitive) SetOnWindowMoved(f func(win *WindowPrimitive))

func (*WindowManagerPrimitive) SetOnWindowResized

func (wm *WindowManagerPrimitive) SetOnWindowResized(f func(win *WindowPrimitive))

func (*WindowManagerPrimitive) SetOnWindowStateChanged

func (wm *WindowManagerPrimitive) SetOnWindowStateChanged(f func(win *WindowPrimitive, state WindowState))

type WindowPrimitive

type WindowPrimitive struct {
	*tview.Box
	// contains filtered or unexported fields
}

WindowPrimitive is a custom tview.Primitive that wraps a child widget with a decorated frame including a title bar with [_][^][X] buttons and resizable borders.

func NewWindowPrimitive

func NewWindowPrimitive(child tview.Primitive) *WindowPrimitive

NewWindowPrimitive creates a new window wrapping the given child.

func (*WindowPrimitive) Close

func (w *WindowPrimitive) Close()

Close fires the close callback.

func (*WindowPrimitive) Draw

func (w *WindowPrimitive) Draw(screen tcell.Screen)

Draw renders the window to the screen.

func (*WindowPrimitive) Focus

func (w *WindowPrimitive) Focus(delegate func(p tview.Primitive))

Focus delegates focus to the child.

func (*WindowPrimitive) GetChild

func (w *WindowPrimitive) GetChild() tview.Primitive

GetChild returns the child primitive.

func (*WindowPrimitive) GetMaxHeight

func (w *WindowPrimitive) GetMaxHeight() int

func (*WindowPrimitive) GetMaxWidth

func (w *WindowPrimitive) GetMaxWidth() int

func (*WindowPrimitive) GetMinHeight

func (w *WindowPrimitive) GetMinHeight() int

func (*WindowPrimitive) GetMinWidth

func (w *WindowPrimitive) GetMinWidth() int

func (*WindowPrimitive) GetRestoredRect

func (w *WindowPrimitive) GetRestoredRect() Rect

GetRestoredRect returns the saved rect for restore from maximized/minimized.

func (*WindowPrimitive) GetWindowState

func (w *WindowPrimitive) GetWindowState() WindowState

GetWindowState returns the current window state.

func (*WindowPrimitive) HasFocus

func (w *WindowPrimitive) HasFocus() bool

HasFocus returns whether the child has focus.

func (*WindowPrimitive) HitTest

func (w *WindowPrimitive) HitTest(screenX, screenY int) HitZone

HitTest determines which zone of the window was clicked.

func (*WindowPrimitive) InputHandler

func (w *WindowPrimitive) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler returns the input handler for keyboard events.

func (*WindowPrimitive) IsActive

func (w *WindowPrimitive) IsActive() bool

IsActive returns whether the window is active.

func (*WindowPrimitive) IsClosable

func (w *WindowPrimitive) IsClosable() bool

func (*WindowPrimitive) IsMaximizable

func (w *WindowPrimitive) IsMaximizable() bool

func (*WindowPrimitive) IsMinimizable

func (w *WindowPrimitive) IsMinimizable() bool

func (*WindowPrimitive) IsMovable

func (w *WindowPrimitive) IsMovable() bool

func (*WindowPrimitive) IsResizable

func (w *WindowPrimitive) IsResizable() bool

func (*WindowPrimitive) Maximize

func (w *WindowPrimitive) Maximize(parentRect Rect)

Maximize expands the window to fill the parent area.

func (*WindowPrimitive) Minimize

func (w *WindowPrimitive) Minimize()

Minimize collapses the window to just the title bar.

func (*WindowPrimitive) MouseHandler

func (w *WindowPrimitive) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)

MouseHandler returns the mouse handler. The actual drag logic is handled by the WindowManager.

func (*WindowPrimitive) Restore

func (w *WindowPrimitive) Restore()

Restore returns the window to its saved position/size.

func (*WindowPrimitive) SetActive

func (w *WindowPrimitive) SetActive(active bool)

SetActive marks the window as active or inactive.

func (*WindowPrimitive) SetActiveBorderColor

func (w *WindowPrimitive) SetActiveBorderColor(c tcell.Color)

func (*WindowPrimitive) SetChild

func (w *WindowPrimitive) SetChild(child tview.Primitive)

SetChild sets the child primitive.

func (*WindowPrimitive) SetClosable

func (w *WindowPrimitive) SetClosable(v bool)

func (*WindowPrimitive) SetInactiveBorderColor

func (w *WindowPrimitive) SetInactiveBorderColor(c tcell.Color)

func (*WindowPrimitive) SetMaxHeight

func (w *WindowPrimitive) SetMaxHeight(v int)

func (*WindowPrimitive) SetMaxWidth

func (w *WindowPrimitive) SetMaxWidth(v int)

func (*WindowPrimitive) SetMaximizable

func (w *WindowPrimitive) SetMaximizable(v bool)

func (*WindowPrimitive) SetMinHeight

func (w *WindowPrimitive) SetMinHeight(v int)

func (*WindowPrimitive) SetMinWidth

func (w *WindowPrimitive) SetMinWidth(v int)

func (*WindowPrimitive) SetMinimizable

func (w *WindowPrimitive) SetMinimizable(v bool)

func (*WindowPrimitive) SetMovable

func (w *WindowPrimitive) SetMovable(v bool)

func (*WindowPrimitive) SetOnActivated

func (w *WindowPrimitive) SetOnActivated(f func())

func (*WindowPrimitive) SetOnClosed

func (w *WindowPrimitive) SetOnClosed(f func())

func (*WindowPrimitive) SetOnMoved

func (w *WindowPrimitive) SetOnMoved(f func(x, y int))

func (*WindowPrimitive) SetOnResized

func (w *WindowPrimitive) SetOnResized(f func(w, h int))

func (*WindowPrimitive) SetOnStateChanged

func (w *WindowPrimitive) SetOnStateChanged(f func(state WindowState))

func (*WindowPrimitive) SetResizable

func (w *WindowPrimitive) SetResizable(v bool)

func (*WindowPrimitive) SetRestoredRect

func (w *WindowPrimitive) SetRestoredRect(r Rect)

SetRestoredRect saves the rect for later restore.

func (*WindowPrimitive) SetTitleBarColor

func (w *WindowPrimitive) SetTitleBarColor(c tcell.Color)

func (*WindowPrimitive) SetTitleBarTextColor

func (w *WindowPrimitive) SetTitleBarTextColor(c tcell.Color)

func (*WindowPrimitive) SetWindowState

func (w *WindowPrimitive) SetWindowState(state WindowState)

SetWindowState sets the window state.

func (*WindowPrimitive) String

func (w *WindowPrimitive) String() string

String returns a debug representation.

type WindowState

type WindowState int

WindowState represents the display state of a window.

const (
	WindowStateNormal    WindowState = 0
	WindowStateMaximized WindowState = 1
	WindowStateMinimized WindowState = 2
)

Jump to

Keyboard shortcuts

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