session

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package session manages persistent session state for grut. Each working directory gets its own session file stored in the XDG data directory. Sessions capture tab layout and focus state so the TUI can restore its previous configuration on the next launch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsFirstRun

func IsFirstRun() bool

IsFirstRun returns true when the first-run marker file does not exist, meaning the user has never launched grut before (or has not seen the help overlay).

func IsFirstRunIn

func IsFirstRunIn(dir string) bool

IsFirstRunIn checks for the marker file in the given directory. Used by tests that need to control the marker location.

func MarkFirstRunDone

func MarkFirstRunDone() error

MarkFirstRunDone creates the first-run marker file, indicating that the help overlay has been shown. The operation is idempotent — calling it multiple times has no effect beyond the initial file creation.

func MarkFirstRunDoneIn

func MarkFirstRunDoneIn(dir string) error

MarkFirstRunDoneIn creates the marker file in the given directory. Used by tests that need to control the marker location.

func ResetFirstRun added in v0.0.2

func ResetFirstRun() error

ResetFirstRun removes the first-run marker file so the welcome screen auto-shows on next launch. The operation is idempotent — calling it when the marker is already absent is a no-op.

func ResetFirstRunIn added in v0.0.2

func ResetFirstRunIn(dir string) error

ResetFirstRunIn removes the marker file in the given directory. Used by tests that need to control the marker location.

Types

type Manager

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

Manager provides session persistence backed by TOML files in the XDG data directory. Each working directory maps to a unique file via a truncated SHA-256 hash.

func NewManager

func NewManager() *Manager

NewManager creates a session manager that stores files under the standard XDG data path (~/.local/share/grut/sessions).

func (*Manager) Delete

func (m *Manager) Delete(workDir string) error

Delete removes the session file for the given working directory. It returns nil when the file does not exist.

func (*Manager) Load

func (m *Manager) Load(workDir string) (*SessionState, error)

Load reads the session for the given working directory. It returns (nil, nil) when no session file exists for that directory, allowing callers to fall back to the default layout without error handling.

func (*Manager) Save

func (m *Manager) Save(state SessionState) error

Save writes the given session state to disk, creating intermediate directories as needed.

func (*Manager) SessionPath

func (m *Manager) SessionPath(workDir string) string

SessionPath returns the file path for the session associated with workDir. The filename is the first 16 hex characters of the SHA-256 hash of workDir.

func (*Manager) SetDataDir

func (m *Manager) SetDataDir(dir string)

SetDataDir overrides the data directory (used in tests).

type SessionState

type SessionState struct {
	SavedAt   time.Time  `toml:"saved_at"`
	WorkDir   string     `toml:"work_dir"`
	Tabs      []TabState `toml:"tabs"`
	Version   int        `toml:"version"`
	ActiveTab int        `toml:"active_tab"`
}

SessionState is the top-level structure persisted to a TOML file.

type TabState

type TabState struct {
	Name         string `toml:"name"`
	Preset       string `toml:"preset"`
	FocusedPanel string `toml:"focused_panel"`
}

TabState captures the minimal state needed to restore a single tab.

Jump to

Keyboard shortcuts

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