config

package
v0.0.0-...-706a68b Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package config handles cosmo-tui's on-disk state: credential storage and the user's runtime configuration.

Both live under the user's config directory: $XDG_CONFIG_HOME or ~/.config on Linux and macOS (deliberately not Apple's ~/Library/Application Support — terminal users expect ~/.config), %AppData% on Windows. Tokens go in a single 0600 auth.json (the Unix mode bits are ignored on Windows, but the file still lands inside the user's already-protected profile); options come from a plaintext "config" file beside it (see Options).

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCredentials = errors.New("no credentials stored; log in first")

ErrNoCredentials is returned by Load when auth.json holds no usable token pair: it is absent, unparseable, or missing a refresh token. All three mean the same thing to the caller - sign in again - and a fresh login rewrites the file, so a corrupt one repairs itself rather than wedging startup.

View Source
var ErrNoWalletKey = errors.New("no wallet key stored")

ErrNoWalletKey is returned by LoadWalletKey when no wallet key is stored.

View Source
var Tabs = []string{"info", "news", "room", "live", "talk", "objekt", "gravity", "profile"}

Tabs is the full set of UI tabs in default display order; it is also the set of valid values for the "tabs" option.

Functions

func LoadWalletKey

func LoadWalletKey() ([]byte, error)

LoadWalletKey reads the stored wallet private key, returning ErrNoWalletKey when none is stored yet.

func OptionsPath

func OptionsPath() (string, error)

OptionsPath returns the config file location under the OS config dir.

func Path

func Path() (string, error)

Path returns the auth.json location under the OS config dir.

func RegisterFlags

func RegisterFlags(fs *flag.FlagSet, opts *Options)

RegisterFlags registers every config option as a flag on fs, applying values to opts through the same setters the config file uses, so flags given on the command line override the loaded config.

func RemoveWalletKey

func RemoveWalletKey() error

RemoveWalletKey deletes the stored wallet key, reporting success when there was nothing to delete. Used to drop a key that no longer belongs to the signed-in account, so a stale one cannot linger unnoticed behind the "sending unavailable" notice.

func Save

func Save(c Credentials) error

Save writes credentials to auth.json with owner-only permissions, creating the parent directory as needed.

func SaveWalletKey

func SaveWalletKey(key []byte) error

SaveWalletKey persists the raw wallet private key (hex) with owner-only permissions.

Types

type Credentials

type Credentials struct {
	AccessToken  string `json:"accessToken"`
	RefreshToken string `json:"refreshToken"`
}

Credentials is the normalized token pair we persist. Cosmo's login/refresh responses nest these under a "credentials" object; see cosmo.ExtractCredentials.

func Load

func Load() (Credentials, error)

Load reads the stored credentials, returning ErrNoCredentials when the file is absent or its contents are unusable (truncated, corrupt, or lacking a refresh token). A read error that is not "absent" - a permission problem, or the path being a directory - is reported as-is: that is a broken environment rather than stale state, and logging in again would only fail at Save.

type Options

type Options struct {
	// Base directories for downloads; media lands in
	// <dir>/cosmo-<group>/<member> beneath them. Each defaults to ".",
	// keeping the historical behavior of downloading relative to the
	// working directory.
	PostDownloadDir   string // room-post media
	ReplayDownloadDir string // replay vods (yt-dlp)
	TalkDownloadDir   string // talk media

	// ReplayFragments is the number of replay-vod fragments fetched in
	// parallel during a download; 0 uses hls.DefaultConcurrency.
	ReplayFragments int

	// LinkHandler is a user script/program that replaces the default
	// openers (xdg-open, in-terminal mpv): every view/open keybind runs
	// it detached with the URL as its single argument. Empty = unset.
	LinkHandler string

	// Artists filters and orders the group carousel (the A key); the
	// first entry is the startup group. Canonical ids, in the user's
	// order. Nil = every group, canonical order.
	Artists []string

	// Tabs selects and orders the visible UI tabs; the first entry is the
	// startup tab. Canonical ids from Tabs, in the user's order. Nil = all
	// tabs, default order.
	Tabs []string

	// Nicknames shows artist-set nicknames on the talk page (matching
	// the app). Off by default, which shows members' real names instead.
	Nicknames bool

	// AutoTranslate turns on auto-translation by default: the talk tab's
	// toggle starts on, and room posts translate on open.
	AutoTranslate bool
}

Options holds the user's runtime configuration, read from the plaintext "config" file that lives next to auth.json and overridable per run via command-line flags of the same name (see RegisterFlags). Each option is one field here, with its default in DefaultOptions and its key registered in optionSetters.

The file is `key=value` lines with `#` comments (whole-line or inline). Values may be double-quoted to preserve spaces or `#`, and paths may start with `~/` to mean the user's home directory. Unknown keys, duplicates, and malformed lines are errors so typos surface at startup instead of being silently ignored.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the configuration used when the config file is absent or leaves an option unset.

func LoadOptions

func LoadOptions() (Options, error)

LoadOptions reads the config file, returning defaults if it doesn't exist.

Jump to

Keyboard shortcuts

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