tui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorPrimary    = lipgloss.Color("39")  // Cyan/blue
	ColorMuted      = lipgloss.Color("241") // Gray
	ColorBackground = lipgloss.Color("236") // Dark gray
	ColorSelected   = lipgloss.Color("57")  // Purple
	ColorSelectedFg = lipgloss.Color("229") // Light yellow
	ColorGreen      = lipgloss.Color("82")  // Green for gains
	ColorRed        = lipgloss.Color("196") // Red for losses
	ColorWarning    = lipgloss.Color("220") // Yellow for warnings
)

Color constants

Variables

View Source
var (
	HeaderStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(ColorPrimary).
				Background(ColorBackground).
				Padding(0, 1)

	ContentStyle = lipgloss.NewStyle().
					Padding(1, 2)

	KeyStyle = lipgloss.NewStyle().
				Foreground(ColorPrimary).
				Bold(true)

	DescStyle = lipgloss.NewStyle().
				Foreground(ColorMuted)

	SummaryStyle = lipgloss.NewStyle().Bold(true)

	LabelStyle = lipgloss.NewStyle().Foreground(ColorMuted)

	ValueStyle = lipgloss.NewStyle().Bold(true)

	GreenStyle = lipgloss.NewStyle().Foreground(ColorGreen)

	RedStyle = lipgloss.NewStyle().Foreground(ColorRed)

	ErrorStyle = lipgloss.NewStyle().Foreground(ColorRed)

	WarningStyle = lipgloss.NewStyle().
					Foreground(ColorWarning).
					Bold(true)

	InputStyle = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(ColorPrimary).
				Padding(0, 1)
)

Shared styles

Functions

func CancelOrder

func CancelOrder(orderID string, cfg *config.Config, store keyring.Store) tea.Cmd

CancelOrder returns a command that cancels an order.

func ConfigPath

func ConfigPath() string

ConfigPath returns the path to the TUI config file.

func FetchAccounts

func FetchAccounts(cfg *config.Config, store keyring.Store) tea.Cmd

FetchAccounts returns a command that fetches the list of accounts.

func FetchHistory

func FetchHistory(cfg *config.Config, store keyring.Store) tea.Cmd

FetchHistory returns a command that fetches transaction history.

func FetchHistoryWithToken

func FetchHistoryWithToken(cfg *config.Config, store keyring.Store, nextToken string) tea.Cmd

FetchHistoryWithToken returns a command that fetches history with optional pagination token.

func FetchInstrumentInfo

func FetchInstrumentInfo(symbol string, cfg *config.Config, store keyring.Store) tea.Cmd

FetchInstrumentInfo returns a command that fetches instrument information.

func FetchOptionChain

func FetchOptionChain(symbol, expiration string, cfg *config.Config, store keyring.Store) tea.Cmd

FetchOptionChain returns a command that fetches the option chain.

func FetchOptionExpirations

func FetchOptionExpirations(symbol string, cfg *config.Config, store keyring.Store) tea.Cmd

FetchOptionExpirations returns a command that fetches option expirations.

func FetchOptionGreeks

func FetchOptionGreeks(symbols []string, cfg *config.Config, store keyring.Store) tea.Cmd

FetchOptionGreeks returns a command that fetches greeks for option symbols.

func FetchOrders

func FetchOrders(cfg *config.Config, store keyring.Store) tea.Cmd

FetchOrders returns a command that fetches open orders.

func FetchPortfolio

func FetchPortfolio(cfg *config.Config, store keyring.Store) tea.Cmd

FetchPortfolio returns a command that fetches portfolio data.

func FetchTradeQuote

func FetchTradeQuote(symbol string, cfg *config.Config, store keyring.Store) tea.Cmd

FetchTradeQuote returns a command that fetches a quote for the trade form.

func FetchWatchlistQuotes

func FetchWatchlistQuotes(symbols []string, cfg *config.Config, store keyring.Store) tea.Cmd

FetchWatchlistQuotes returns a command that fetches quotes for watchlist symbols.

func PlaceOrder

func PlaceOrder(m *TradeModel, cfg *config.Config, store keyring.Store) tea.Cmd

PlaceOrder returns a command that places an order.

func SaveConfig

func SaveConfig(cfg *UIConfig) error

SaveConfig saves the TUI config to disk.

func TableStyles

func TableStyles() table.Styles

TableStyles returns the default table styles for TUI tables.

Types

type Account

type Account = publicapi.Account

Account types

type AccountChangedMsg

type AccountChangedMsg struct {
	AccountID string
}

AccountChangedMsg is sent when the user switches accounts.

type AccountsErrorMsg

type AccountsErrorMsg struct {
	Err error
}

AccountsErrorMsg is sent when account loading fails.

type AccountsLoadedMsg

type AccountsLoadedMsg struct {
	Accounts []Account
}

AccountsLoadedMsg is sent when accounts are loaded successfully.

type AccountsResponse

type AccountsResponse = publicapi.AccountsResponse

Account types

type AssetInstrumentErrorMsg

type AssetInstrumentErrorMsg struct {
	Symbol string
	Err    error
}

AssetInstrumentErrorMsg is sent when instrument lookup fails.

type AssetInstrumentLoadedMsg

type AssetInstrumentLoadedMsg struct {
	Symbol        string
	Type          string
	Name          string
	OptionTrading string
}

AssetInstrumentLoadedMsg is sent when instrument info is loaded.

type AssetSelectedMsg

type AssetSelectedMsg struct {
	Symbol     string
	Type       string
	Name       string
	Optionable bool
	Quote      *Quote // Optional quote data if available
}

AssetSelectedMsg is sent when an asset is selected.

type AssetSelectorCancelledMsg

type AssetSelectorCancelledMsg struct{}

AssetSelectorCancelledMsg is sent when the selector is cancelled.

type AssetSelectorMode

type AssetSelectorMode int

AssetSelectorMode represents the current mode of the asset selector.

const (
	AssetSelectorModeSearch AssetSelectorMode = iota
	AssetSelectorModeWatchlist
	AssetSelectorModePortfolio
)

type AssetSelectorModel

type AssetSelectorModel struct {
	Mode        AssetSelectorMode
	SearchInput textinput.Model
	Cursor      int

	// Data sources
	WatchSymbols []string
	WatchQuotes  map[string]Quote
	Positions    []Position

	// Search results
	SearchSymbol  string
	SearchResult  *AssetInstrumentLoadedMsg
	SearchLoading bool
	SearchErr     error

	// Dimensions
	Width  int
	Height int
}

AssetSelectorModel holds the state for the asset selector component.

func NewAssetSelectorModel

func NewAssetSelectorModel(mode AssetSelectorMode) *AssetSelectorModel

NewAssetSelectorModel creates a new asset selector in the specified mode.

func (*AssetSelectorModel) SetPortfolioData

func (m *AssetSelectorModel) SetPortfolioData(positions []Position)

SetPortfolioData sets the portfolio data for the selector.

func (*AssetSelectorModel) SetWatchlistData

func (m *AssetSelectorModel) SetWatchlistData(symbols []string, quotes map[string]Quote)

SetWatchlistData sets the watchlist data for the selector.

func (*AssetSelectorModel) Update

func (m *AssetSelectorModel) Update(msg tea.Msg, cfg *config.Config, store keyring.Store) (*AssetSelectorModel, tea.Cmd)

Update handles messages for the asset selector.

func (*AssetSelectorModel) View

func (m *AssetSelectorModel) View() string

View renders the asset selector.

type BuyingPower

type BuyingPower = publicapi.BuyingPower

Portfolio types

type CostBasis

type CostBasis = publicapi.CostBasis

Portfolio types

type Equity

type Equity = publicapi.Equity

Portfolio types

type Gain

type Gain = publicapi.Gain

Portfolio types

type GreeksDisplayMode

type GreeksDisplayMode int

GreeksDisplayMode represents how Greeks are displayed.

const (
	GreeksDisplayCompact  GreeksDisplayMode = iota // Delta, Theta, IV inline
	GreeksDisplayExpanded                          // All Greeks: Delta, Gamma, Theta, Vega, Rho, IV
)

type HistoryErrorMsg

type HistoryErrorMsg struct {
	Err error
}

HistoryErrorMsg is sent when history loading fails.

type HistoryLoadedMsg

type HistoryLoadedMsg struct {
	Transactions []Transaction
	NextToken    string
}

HistoryLoadedMsg is sent when history is loaded successfully.

type HistoryModel

type HistoryModel struct {
	State        HistoryState
	Transactions []Transaction
	Err          error
	LastUpdated  time.Time
	Table        table.Model

	// Pagination
	NextToken   string
	HasMore     bool
	LoadingMore bool

	// Detail panel
	ShowDetail  bool
	DetailIndex int
}

HistoryModel holds the state for the history view.

func NewHistoryModel

func NewHistoryModel() *HistoryModel

NewHistoryModel creates a new history model.

func (*HistoryModel) FooterKeys

func (m *HistoryModel) FooterKeys(keys []struct{ key, desc string }) []struct{ key, desc string }

FooterKeys returns the footer keys for the history view.

func (*HistoryModel) SelectedTransaction

func (m *HistoryModel) SelectedTransaction() *Transaction

SelectedTransaction returns the currently selected transaction, if any.

func (*HistoryModel) SetHeight

func (m *HistoryModel) SetHeight(height int)

SetHeight sets the table height.

func (*HistoryModel) Update

func (m *HistoryModel) Update(msg tea.Msg) (*HistoryModel, tea.Cmd, bool)

Update handles messages for the history view. Returns the model, command, and whether the event was handled.

func (*HistoryModel) View

func (m *HistoryModel) View() string

View renders the history view.

type HistoryResponse

type HistoryResponse = publicapi.HistoryResponse

History types

type HistoryState

type HistoryState int

HistoryState represents the loading state of history data.

const (
	HistoryStateLoading HistoryState = iota
	HistoryStateLoaded
	HistoryStateError
)

type Instrument

type Instrument = publicapi.Instrument

Portfolio types

type Model

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

Model is the main bubbletea model for the TUI.

func New

func New(cfg *config.Config, uiCfg *UIConfig, store keyring.Store) Model

New creates a new TUI model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View implements tea.Model.

type OptionChainErrorMsg

type OptionChainErrorMsg struct {
	Err error
}

OptionChainErrorMsg is sent when loading the chain fails.

type OptionChainLoadedMsg

type OptionChainLoadedMsg struct {
	Chain *api.OptionChainResponse
}

OptionChainLoadedMsg is sent when the option chain is loaded.

type OptionExpirationsErrorMsg

type OptionExpirationsErrorMsg struct {
	Err error
}

OptionExpirationsErrorMsg is sent when loading expirations fails.

type OptionExpirationsLoadedMsg

type OptionExpirationsLoadedMsg struct {
	Expirations []string
	OptionsBP   string
}

OptionExpirationsLoadedMsg is sent when expirations are loaded.

type OptionGreeksLoadedMsg

type OptionGreeksLoadedMsg struct {
	Greeks []api.OptionGreeks
}

OptionGreeksLoadedMsg is sent when greeks are loaded.

type OptionQuoteLoadedMsg

type OptionQuoteLoadedMsg struct {
	Last string
}

OptionQuoteLoadedMsg is sent when the underlying quote is loaded.

type OptionsFocus

type OptionsFocus int

OptionsFocus represents what is currently focused.

const (
	OptionsFocusSymbol OptionsFocus = iota
	OptionsFocusExpiration
	OptionsFocusCalls
	OptionsFocusPuts
)

type OptionsModel

type OptionsModel struct {
	State       OptionsState
	Focus       OptionsFocus
	Err         error
	LastUpdated time.Time

	// Symbol input
	SymbolInput textinput.Model
	Symbol      string
	Quote       *Quote

	// Expirations
	Expirations        []string
	SelectedExpiration int

	// Option chain data
	Chain       *api.OptionChainResponse
	Greeks      map[string]api.GreeksData
	CallsCursor int
	PutsCursor  int
	GreeksMode  GreeksDisplayMode
	Height      int
	OptionsBP   string

	// Detail panel
	ShowDetailPanel bool
	SelectedOption  *api.OptionQuote

	// Asset selector (for watchlist/portfolio selection)
	AssetSelector     *AssetSelectorModel
	ShowAssetSelector bool
}

OptionsModel holds the state for the options view.

func NewOptionsModel

func NewOptionsModel() *OptionsModel

NewOptionsModel creates a new options model.

func (*OptionsModel) FooterKeys

func (m *OptionsModel) FooterKeys(keys []struct{ key, desc string }) []struct{ key, desc string }

FooterKeys returns the footer keys for the options view.

func (*OptionsModel) SetHeight

func (m *OptionsModel) SetHeight(h int)

SetHeight sets the available height for the options chain.

func (*OptionsModel) Update

func (m *OptionsModel) Update(msg tea.Msg, cfg *config.Config, store keyring.Store) (*OptionsModel, tea.Cmd)

Update handles messages for the options view.

func (*OptionsModel) View

func (m *OptionsModel) View() string

View renders the options view.

type OptionsState

type OptionsState int

OptionsState represents the current state of the options view.

const (
	OptionsStateIdle OptionsState = iota
	OptionsStateLoadingExpirations
	OptionsStateSelectingExpiration
	OptionsStateLoadingChain
	OptionsStateChainLoaded
	OptionsStateError
)

type Order

type Order = publicapi.Order

Order types

type OrderCancelErrorMsg

type OrderCancelErrorMsg struct {
	Err error
}

OrderCancelErrorMsg is sent when order cancellation fails.

type OrderCancelledMsg

type OrderCancelledMsg struct {
	OrderID string
}

OrderCancelledMsg is sent when an order is cancelled.

type OrdersErrorMsg

type OrdersErrorMsg struct {
	Err error
}

OrdersErrorMsg is sent when orders loading fails.

type OrdersLoadedMsg

type OrdersLoadedMsg struct {
	Orders []Order
}

OrdersLoadedMsg is sent when orders are loaded successfully.

type OrdersMode

type OrdersMode int

OrdersMode represents the input mode of the orders view.

const (
	OrdersModeNormal OrdersMode = iota
	OrdersModeCanceling
)

type OrdersModel

type OrdersModel struct {
	State         OrdersState
	Orders        []Order
	Err           error
	LastUpdated   time.Time
	Table         table.Model
	Mode          OrdersMode
	CancelOrderID string
	CancelSymbol  string
}

OrdersModel holds the state for the orders view.

func NewOrdersModel

func NewOrdersModel() *OrdersModel

NewOrdersModel creates a new orders model.

func (*OrdersModel) SelectedOrder

func (m *OrdersModel) SelectedOrder() *Order

SelectedOrder returns the currently selected order, if any.

func (*OrdersModel) SetHeight

func (m *OrdersModel) SetHeight(height int)

SetHeight sets the table height.

func (*OrdersModel) Update

func (m *OrdersModel) Update(msg tea.Msg, cfg *config.Config, store keyring.Store) (*OrdersModel, tea.Cmd, bool)

Update handles messages for the orders view. Returns the model, command, and whether the event was handled.

func (*OrdersModel) View

func (m *OrdersModel) View() string

View renders the orders view.

type OrdersResponse

type OrdersResponse = publicapi.OrdersResponse

Order types

type OrdersState

type OrdersState int

OrdersState represents the loading state of orders data.

const (
	OrdersStateLoading OrdersState = iota
	OrdersStateLoaded
	OrdersStateError
)

type Portfolio

type Portfolio = publicapi.Portfolio

Portfolio types

type PortfolioErrorMsg

type PortfolioErrorMsg struct {
	Err error
}

PortfolioErrorMsg is sent when portfolio loading fails.

type PortfolioLoadedMsg

type PortfolioLoadedMsg struct {
	Portfolio Portfolio
}

PortfolioLoadedMsg is sent when portfolio data is loaded successfully.

type PortfolioModel

type PortfolioModel struct {
	State       PortfolioState
	Data        Portfolio
	Err         error
	LastUpdated time.Time
	Table       table.Model
}

PortfolioModel holds the state for the portfolio view.

func NewPortfolioModel

func NewPortfolioModel() *PortfolioModel

NewPortfolioModel creates a new portfolio model.

func (*PortfolioModel) SetHeight

func (m *PortfolioModel) SetHeight(height int)

SetHeight sets the table height.

func (*PortfolioModel) Update

func (m *PortfolioModel) Update(msg tea.Msg) (*PortfolioModel, tea.Cmd)

Update handles messages for the portfolio view.

func (*PortfolioModel) View

func (m *PortfolioModel) View() string

View renders the portfolio view.

type PortfolioState

type PortfolioState int

PortfolioState represents the loading state of portfolio data.

const (
	PortfolioStateLoading PortfolioState = iota
	PortfolioStateLoaded
	PortfolioStateError
)

type Position

type Position = publicapi.Position

Portfolio types

type Price

type Price = publicapi.Price

Portfolio types

type Quote

type Quote = publicapi.Quote

Quote types

type QuoteInstrument

type QuoteInstrument = publicapi.QuoteInstrument

Quote types

type QuoteRequest

type QuoteRequest = publicapi.QuoteRequest

Quote types

type QuotesResponse

type QuotesResponse = publicapi.QuotesResponse

Quote types

type TickMsg

type TickMsg time.Time

TickMsg is sent periodically for auto-refresh.

type ToolbarFocusMsg

type ToolbarFocusMsg struct{}

ToolbarFocusMsg is sent when a child view requests toolbar focus.

type TradeField

type TradeField int

TradeField represents the currently focused input field.

const (
	TradeFieldSymbol TradeField = iota
	TradeFieldSide
	TradeFieldOrderType
	TradeFieldQuantity
	TradeFieldLimitPrice
)

type TradeMode

type TradeMode int

TradeMode represents the input mode of the trade view.

const (
	TradeModeForm TradeMode = iota
	TradeModeConfirm
)

type TradeModel

type TradeModel struct {
	State     TradeState
	Mode      TradeMode
	Err       error
	LastError string

	// Form fields
	FocusedField    TradeField
	SymbolInput     textinput.Model
	QuantityInput   textinput.Model
	LimitPriceInput textinput.Model

	// Selections
	Side      TradeSide
	OrderType TradeOrderType

	// Quote data for the symbol
	Quote       *Quote
	QuoteLoaded bool

	// Order result
	OrderID     string
	OrderSymbol string

	// Asset selector
	AssetSelector     *AssetSelectorModel
	ShowAssetSelector bool

	// Watchlist data for asset selector (set by parent)
	WatchlistSymbols []string
	WatchlistQuotes  map[string]Quote
}

TradeModel holds the state for the trade view.

func NewTradeModel

func NewTradeModel() *TradeModel

NewTradeModel creates a new trade model.

func (*TradeModel) FocusSymbol

func (m *TradeModel) FocusSymbol() tea.Cmd

FocusSymbol ensures the symbol input is focused when entering the trade view. Returns a tea.Cmd for the cursor blink animation.

func (*TradeModel) IsTextFieldFocused

func (m *TradeModel) IsTextFieldFocused() bool

IsTextFieldFocused returns true if focus is on a text input field.

func (*TradeModel) RefocusCurrent

func (m *TradeModel) RefocusCurrent() tea.Cmd

RefocusCurrent refocuses the currently focused field (used when returning from toolbar). Returns a tea.Cmd for the cursor blink animation.

func (*TradeModel) SetSymbol

func (m *TradeModel) SetSymbol(symbol string)

SetSymbol sets the symbol to trade (called when jumping from watchlist).

func (*TradeModel) SetWatchlistData

func (m *TradeModel) SetWatchlistData(symbols []string, quotes map[string]Quote)

SetWatchlistData sets the watchlist data for the asset selector.

func (*TradeModel) Update

func (m *TradeModel) Update(msg tea.Msg, cfg *config.Config, store keyring.Store) (*TradeModel, tea.Cmd)

Update handles messages for the trade view.

func (*TradeModel) View

func (m *TradeModel) View() string

View renders the trade view.

type TradeOrderErrorMsg

type TradeOrderErrorMsg struct {
	Err error
}

TradeOrderErrorMsg is sent when placing an order fails.

type TradeOrderPlacedMsg

type TradeOrderPlacedMsg struct {
	OrderID string
	Symbol  string
}

TradeOrderPlacedMsg is sent when an order is placed successfully.

type TradeOrderType

type TradeOrderType int

TradeOrderType represents market or limit order.

const (
	TradeOrderTypeMarket TradeOrderType = iota
	TradeOrderTypeLimit
)

func (TradeOrderType) String

func (t TradeOrderType) String() string

type TradeQuoteErrorMsg

type TradeQuoteErrorMsg struct {
	Err error
}

TradeQuoteErrorMsg is sent when fetching a quote fails.

type TradeQuoteMsg

type TradeQuoteMsg struct {
	Quote Quote
}

TradeQuoteMsg is sent when a quote is fetched for the trade form.

type TradeSide

type TradeSide int

TradeSide represents buy or sell.

const (
	TradeSideBuy TradeSide = iota
	TradeSideSell
)

func (TradeSide) String

func (s TradeSide) String() string

type TradeState

type TradeState int

TradeState represents the current state of the trade view.

const (
	TradeStateIdle TradeState = iota
	TradeStateFetchingQuote
	TradeStateReady
	TradeStateSubmitting
	TradeStateSuccess
	TradeStateError
)

type Transaction

type Transaction = publicapi.Transaction

History types

type UIConfig

type UIConfig struct {
	Watchlist []string `yaml:"watchlist,omitempty"`
}

UIConfig holds TUI-specific configuration separate from CLI config.

func LoadConfig

func LoadConfig() (*UIConfig, error)

LoadConfig loads the TUI config from disk.

type View

type View int

View represents the current active view in the TUI.

const (
	ViewPortfolio View = iota
	ViewWatchlist
	ViewOrders
	ViewTrade
	ViewOptions
	ViewHistory
)

type WatchlistErrorMsg

type WatchlistErrorMsg struct {
	Err error
}

WatchlistErrorMsg is sent when watchlist loading fails.

type WatchlistMode

type WatchlistMode int

WatchlistMode represents the input mode of the watchlist view.

const (
	WatchlistModeNormal WatchlistMode = iota
	WatchlistModeAdding
	WatchlistModeDeleting
)

type WatchlistModel

type WatchlistModel struct {
	State        WatchlistState
	Symbols      []string
	Quotes       map[string]Quote
	Err          error
	LastUpdated  time.Time
	Table        table.Model
	Mode         WatchlistMode
	AddInput     textinput.Model
	DeleteSymbol string
}

WatchlistModel holds the state for the watchlist view.

func NewWatchlistModel

func NewWatchlistModel(symbols []string) *WatchlistModel

NewWatchlistModel creates a new watchlist model.

func (*WatchlistModel) SelectedSymbol

func (m *WatchlistModel) SelectedSymbol() string

SelectedSymbol returns the currently selected symbol, if any.

func (*WatchlistModel) SetHeight

func (m *WatchlistModel) SetHeight(height int)

SetHeight sets the table height.

func (*WatchlistModel) Update

func (m *WatchlistModel) Update(msg tea.Msg, uiCfg *UIConfig) (*WatchlistModel, tea.Cmd, bool)

Update handles messages for the watchlist view. Returns the model, command, and whether the event was handled.

func (*WatchlistModel) View

func (m *WatchlistModel) View() string

View renders the watchlist view.

type WatchlistQuotesMsg

type WatchlistQuotesMsg struct {
	Quotes map[string]Quote
}

WatchlistQuotesMsg is sent when watchlist quotes are loaded.

type WatchlistSavedMsg

type WatchlistSavedMsg struct{}

WatchlistSavedMsg is sent when watchlist config is saved.

type WatchlistState

type WatchlistState int

WatchlistState represents the loading state of watchlist data.

const (
	WatchlistStateLoading WatchlistState = iota
	WatchlistStateLoaded
	WatchlistStateError
)

Jump to

Keyboard shortcuts

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