state

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package state keeps what would be missed if lost: the drafts of edits not yet sent, and the locks that keep two gist from one gist's drafts.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("being edited in another gist process")

ErrLocked says another gist process is editing the gist.

Functions

This section is empty.

Types

type Draft

type Draft struct {
	Gist string `json:"gist"`
	File string `json:"file"`
	// Revision and Original are what the edit started from, and what it is
	// compared with.
	Revision string `json:"revision"`
	Original []byte `json:"original"`
	// Content is the file as edited.
	Content []byte    `json:"content"`
	Created time.Time `json:"created"`
}

Draft is an edit not yet sent. Its text is kept as bytes, as a file need not be valid UTF-8 and JSON strings would change what is not.

type Lock

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

Lock is the hold of one process on a gist. Drafts are written and removed only through it, so another process cannot replace a draft or remove it.

func (*Lock) DeleteDraft

func (l *Lock) DeleteDraft(file string) error

DeleteDraft removes the draft of a file of the lock's gist, which need not exist.

func (*Lock) DeleteDrafts

func (l *Lock) DeleteDrafts() error

DeleteDrafts removes all the drafts of the lock's gist.

func (*Lock) Release

func (l *Lock) Release() error

Release lets the lock go.

func (*Lock) SaveDraft

func (l *Lock) SaveDraft(d Draft) error

SaveDraft keeps d, for the gist of the lock. It is written whole or not at all, so a crash leaves no broken draft.

type ReleaseSeen

type ReleaseSeen struct {
	// Checked is when they were last read.
	Checked time.Time `json:"checked,omitzero"`
	// Latest is the newest found, and Told the newest told of.
	Latest string `json:"latest,omitempty"`
	Told   string `json:"told,omitempty"`
}

ReleaseSeen is what was last found of gist's releases.

type Store

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

Store is the state directory.

func Open

func Open(dir string) *Store

Open is the store in dir.

func (*Store) Draft

func (s *Store) Draft(gist, file string) (Draft, bool, error)

Draft reads the draft of a file.

func (*Store) DraftGists

func (s *Store) DraftGists() ([]string, error)

DraftGists are the gists that have drafts.

func (*Store) Drafts

func (s *Store) Drafts(gist string) ([]Draft, error)

Drafts reads the drafts of a gist.

func (*Store) DraftsDir

func (s *Store) DraftsDir() string

DraftsDir is where drafts are kept.

func (*Store) HasDraft

func (s *Store) HasDraft(gist, file string) bool

HasDraft says a file has a draft, without reading it.

func (*Store) Lock

func (s *Store) Lock(gist string) (*Lock, error)

Lock takes the gist's lock, failing with ErrLocked when another process has it. The operating system lets it go if the process dies.

func (*Store) PaneWidth added in v2.2.0

func (s *Store) PaneWidth() int

PaneWidth is the width the pane beside the preview was dragged to, or 0.

func (*Store) PreviewHeight

func (s *Store) PreviewHeight() int

PreviewHeight is the height the preview was left at, or 0.

func (*Store) ReleaseSeen

func (s *Store) ReleaseSeen() ReleaseSeen

ReleaseSeen is what was last found of the releases.

func (*Store) SavePaneWidth added in v2.2.0

func (s *Store) SavePaneWidth(w int) error

SavePaneWidth remembers the width of the pane; 0 forgets it.

func (*Store) SavePreviewHeight

func (s *Store) SavePreviewHeight(h int) error

SavePreviewHeight remembers the height of the preview.

func (*Store) SaveReleaseSeen

func (s *Store) SaveReleaseSeen(r ReleaseSeen) error

SaveReleaseSeen remembers it.

Jump to

Keyboard shortcuts

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