ui

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Story list styles.
	TitleStyle = lipgloss.NewStyle().
				Foreground(white).
				Bold(true)

	SelectedTitleStyle = lipgloss.NewStyle().
						Foreground(orange).
						Bold(true)

	MetaStyle = lipgloss.NewStyle().
				Foreground(subtleGray)

	ScoreStyle = lipgloss.NewStyle().
				Foreground(orange).
				Bold(true)

	IndexStyle = lipgloss.NewStyle().
				Foreground(dimGray).
				Width(4).
				Align(lipgloss.Right)

	// Comment styles.
	CommentAuthorStyle = lipgloss.NewStyle().
						Foreground(orange).
						Bold(true)

	CommentTimeStyle = lipgloss.NewStyle().
						Foreground(subtleGray)

	CommentTextStyle = lipgloss.NewStyle().
						Foreground(white)

	IndentStyle = lipgloss.NewStyle().
				Foreground(dimGray)

	// Header / title bar.
	HeaderStyle = lipgloss.NewStyle().
				Background(orange).
				Foreground(lipgloss.Color("#000000")).
				Bold(true).
				Padding(0, 1)

	// Status bar.
	StatusStyle = lipgloss.NewStyle().
				Foreground(subtleGray).
				Italic(true)

	// User profile.
	UserNameStyle = lipgloss.NewStyle().
					Foreground(orange).
					Bold(true).
					Underline(true)

	UserKarmaStyle = lipgloss.NewStyle().
					Foreground(yellow).
					Bold(true)

	// Help bar.
	HelpStyle = lipgloss.NewStyle().
				Foreground(dimGray)

	// Separator.
	SepStyle = lipgloss.NewStyle().
				Foreground(dimGray).
				SetString("  ·  ")

	// URL.
	URLStyle = lipgloss.NewStyle().
				Foreground(green).
				Italic(true)
)

Functions

func LoadCmd

func LoadCmd(loader func() ([]*api.Item, error)) tea.Cmd

LoadCmd returns a command that fetches stories and sends StoriesLoaded.

func LoadItemCmd

func LoadItemCmd(client *api.Client, id int) tea.Cmd

LoadItemCmd fetches a story and its first-level comments in parallel.

func LoadUserCmd

func LoadUserCmd(client *api.Client, username string) tea.Cmd

LoadUserCmd fetches a user profile and their recent submissions.

func Run

func Run(client *api.Client, title string, loader func() ([]*api.Item, error)) error

Run starts the bubbletea program with the given loader.

func RunItem

func RunItem(client *api.Client, id int) error

RunItem opens a single item's comment view directly.

func RunUser

func RunUser(client *api.Client, username string) error

RunUser opens a user profile view directly.

func RunWithItems

func RunWithItems(client *api.Client, title string, items []*api.Item) error

RunWithItems starts the TUI with a pre-built item list (e.g. search results).

func RunWithLoader

func RunWithLoader(client *api.Client, title string, loader func() ([]*api.Item, error)) error

RunWithLoader starts the TUI loading items async.

func Sep

func Sep() string

Sep renders the separator bullet.

Types

type App

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

App is the root bubbletea model for the interactive browser.

func NewApp

func NewApp(client *api.Client, title string, loader func() ([]*api.Item, error)) *App

NewApp creates a new App ready to show the given story list.

func (*App) Init

func (a *App) Init() tea.Cmd

func (*App) Update

func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*App) View

func (a *App) View() string

type BackMsg

type BackMsg struct{}

BackMsg is sent when the user wants to go back to the list.

type CommentsModel

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

CommentsModel is a bubbletea model for a threaded comment view.

func NewCommentsModel

func NewCommentsModel() CommentsModel

NewCommentsModel returns a loading comments model.

func (CommentsModel) Init

func (m CommentsModel) Init() tea.Cmd

func (CommentsModel) Update

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

func (CommentsModel) View

func (m CommentsModel) View() string

type ItemLoaded

type ItemLoaded struct {
	Story    *api.Item
	Comments []*api.Item
	Err      error
}

ItemLoaded is sent when a single item (and its comment tree) is ready.

type ListModel

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

ListModel is a bubbletea model for a scrollable list of stories.

func NewListModel

func NewListModel(title string) ListModel

NewListModel creates a list model with a given title. Items are populated later.

func (ListModel) Init

func (m ListModel) Init() tea.Cmd

func (ListModel) Update

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

func (ListModel) View

func (m ListModel) View() string

type OpenItem

type OpenItem struct{ ID int }

OpenItem is sent when the user wants to open a story's comments.

type OpenURL

type OpenURL struct{ URL string }

OpenURL is sent when the user wants to open a URL.

type StoriesLoaded

type StoriesLoaded struct {
	Items []*api.Item
	Err   error
}

StoriesLoaded is sent when story items have been fetched.

type UserLoaded

type UserLoaded struct {
	User  *api.User
	Items []*api.Item
	Err   error
}

UserLoaded is sent when a user profile has been fetched.

type UserModel

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

UserModel is a bubbletea model for a user profile view.

func NewUserModel

func NewUserModel() UserModel

NewUserModel returns a loading user model.

func (UserModel) Init

func (m UserModel) Init() tea.Cmd

func (UserModel) Update

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

func (UserModel) View

func (m UserModel) View() string

type View

type View int

View is an enum for which screen is active.

const (
	ViewList View = iota
	ViewComments
	ViewUser
)

Jump to

Keyboard shortcuts

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