session

package
v0.2.23 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package session persists per-project editor state — open tabs (with cursor and scroll), the active tab, expanded tree folders, and the sidebar — so reopening a project puts the user back where they left off. This is state, not configuration: skiff stays dotfile-free, but remembering where you were is table stakes.

Storage is one file per project, $XDG_STATE_HOME/skiff/sessions/ <hash>.json (falling back to ~/.local/state/skiff/), where <hash> is derived from the project's absolute root path. One file per project is deliberate: a single shared store meant a corrupt or half-written file took every *other* project's state down with it on the next save, and the read-modify-write it forced lost updates between concurrent skiff instances. Now a save touches exactly one project's file and nothing else can be collateral damage.

Every failure mode degrades to "no session" — a corrupt file must never block startup, and must never be deleted behind the user's back. The directory is pruned to the most recent maxProjects files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Save

func Save(rootAbs string, p Project) error

Save writes rootAbs's session to its own file and prunes the directory. No shared state is read or rewritten, which is what makes concurrent skiff instances and corrupt neighbours harmless.

Types

type Project

type Project struct {
	Tabs         []TabState `json:"tabs,omitempty"`
	Active       int        `json:"active"`
	ActivePath   string     `json:"activePath,omitempty"`
	Expanded     []string   `json:"expanded,omitempty"`
	SidebarWidth int        `json:"sidebarWidth"`
	SidebarShown bool       `json:"sidebarShown"`
	SavedAt      time.Time  `json:"savedAt"`
}

Project is everything remembered about one project root. ActivePath is the authority for which tab gets focus; Active (an index into Tabs) is kept only so files written by older builds still restore something sane, because an index silently points at the wrong tab as soon as one saved file has vanished from disk.

func Load

func Load(rootAbs string) (Project, bool)

Load returns the remembered session for the project rooted at rootAbs, and whether one existed.

type TabState

type TabState struct {
	Path    string `json:"path"`
	Line    int    `json:"line"`
	Col     int    `json:"col"`
	ScrollY int    `json:"scrollY"`
	Preview bool   `json:"preview,omitempty"`
}

TabState is one remembered tab: a project-relative path plus the view state needed to land the user back on their line.

Jump to

Keyboard shortcuts

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