app

package
v1.0.1-0...-517973f Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MPL-2.0 Imports: 54 Imported by: 1 module, 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 app is the Kvit Notes window: the sidebar, the note list and the editor pane, over one vault. cmd/kvit-notes opens it.

Index

Constants

View Source
const ToolbarHeight = 36

ToolbarHeight is the strip's height in design pixels, as Kvit's toolbar.

View Source
const WelcomeNote = `# Welcome to Kvit Notes

The quick **brown** fox has *seven* cubs. Markers such as the stars show only around the caret.

## Things to try

- Type ` + "`# `" + ` at the start of an empty paragraph to make a heading
- Type ` + "`/`" + ` in an empty block for the block menu
- [ ] Drag a block by the handle that appears on hover
- [x] Undo anything with Ctrl+Z

> A quotation keeps its lines
> together.

` + "```" + `
func main() {
    fmt.Println("code keeps its indentation")
}
` + "```" + `

---

Bold with Ctrl+B, italic with Ctrl+I, ==highlight==, ~~strike~~, ++underline++ and [links](https://kvit.app).
`

WelcomeNote is the note an empty vault starts with.

Variables

View Source
var OpenFile func(ui *kvitui.UI, path string)

OpenFile opens a Markdown file on its own in a window of its own; the command sets it, since that window is the command's.

Functions

func AcceptDroppedNotes

func AcceptDroppedNotes(win *kvitui.Window, open func(path string))

AcceptDroppedNotes makes a window take note files dropped anywhere on it, giving each to open. A part of the window that takes drops of its own comes first, as unison asks the panel under the pointer before its parents, and the window's content is the last of those. The window also registers the text and address types so the editor can take drops from other applications; the content itself only takes note files.

func AllowQuit

func AllowQuit() bool

AllowQuit is unison's AllowQuitCallback: a quit, however it was asked for, closes every window rather than hiding the last one. A window that refuses to close leaves the app running, and the setting applies again.

func ClosesToTray

func ClosesToTray(ui *kvitui.UI, win *kvitui.Window, save func())

ClosesToTray makes a window one that closing to the tray applies to: when it is the last one open, the icon is shown and the reader asked for it, closing it runs save and hides it instead. A window closed while another is hidden in the tray closes, and the app goes on running for the hidden one. The vault windows are made so as they open; the command makes its note-file windows so.

func MathCommands

func MathCommands(ui *kvitui.UI) *mathcmd.Model

MathCommands is the math command menu's list for ui, to give each editor through SetMathCommands. It is made the first time it is asked for: its recently used commands are read from the settings, and written back each time a command is chosen.

func OpenOrRaise

func OpenOrRaise(ui *kvitui.UI, root string) error

OpenOrRaise brings forward the window a vault is open in, or opens it in a new window.

func OpenSettings

func OpenSettings(ui *kvitui.UI, win *kvitui.Window, v *vault.Vault)

OpenSettings shows the settings dialog over a window; the This vault section is there when a vault is open in it.

func OpenShortcuts

func OpenShortcuts(ui *kvitui.UI, win *kvitui.Window)

OpenShortcuts shows the keyboard shortcuts over a window.

func Quit

func Quit()

Quit is the tray's Quit: it asks every window to close, which saves its note, and ends the app when all have.

func Quitting

func Quitting()

Quitting is unison's QuittingCallback: it takes the icon out of the notification area, where Windows would otherwise leave it until the pointer passed over it.

func RaiseAny

func RaiseAny() bool

RaiseAny brings the first vault window forward, and reports whether there was one.

func ShowKvit

func ShowKvit()

ShowKvit brings the app's window forward, showing it if the last close hid it.

func StartTray

func StartTray(t *platform.Tray, icon ...image.Image)

StartTray shows the app's tray icon, where the desktop has a notification area, with its tooltip and menu. icon is the app's icon at the sizes there are.

func Tray

func Tray() *platform.Tray

Tray is the app's tray icon while it is shown, or nil.

Types

type Backlinks struct {
	*unison.Panel
	// contains filtered or unexported fields
}

Backlinks is the pane.

type ListItem

type ListItem struct {
	Key      string // what the row stands for, such as the note's path
	Title    string
	Snippet  string // "" shows "Empty note"
	Details  string // the date and the word count
	Pinned   bool
	Favorite bool
}

ListItem is one row of the note list.

type NoteList

type NoteList struct {
	unison.Panel

	// Items are the rows, in order.
	Items []ListItem
	// Current is the index of the row the keyboard is on and whose note is
	// open, or -1.
	Current int
	// OnOpen runs when a row is chosen by a press, the arrows, or a screen
	// reader.
	OnOpen func(i int)
	// OnDrag runs while a row is dragged, and OnDrop when it is let go,
	// with the pointer in the window's root coordinates.
	OnDrag, OnDrop func(i int, where geom.Point)
	// Selected are the rows picked with Ctrl or Shift for acting on
	// together; OnSelect runs when they change.
	Selected map[int]bool
	OnSelect func()
	// DropLine is the gap a dragged row would go into, drawn as a line:
	// before row DropLine, or -1 for none.
	DropLine int
	// contains filtered or unexported fields
}

NoteList is the list of notes.

func NewNoteList

func NewNoteList(ui *kvitui.UI) *NoteList

NewNoteList returns an empty note list.

func (*NoteList) ClearSelection

func (l *NoteList) ClearSelection()

ClearSelection drops every picked row.

func (*NoteList) PerformAccessibilityAction

func (l *NoteList) PerformAccessibilityAction(req accessibility.ActionRequest) bool

PerformAccessibilityAction opens the note a screen reader selects.

func (*NoteList) ProvideAccessibility

func (l *NoteList) ProvideAccessibility(b *unison.AccessibilityBuilder)

ProvideAccessibility describes the rows in view, and the current row, which holds the keyboard focus the list has.

func (*NoteList) SelectedRows

func (l *NoteList) SelectedRows() []int

SelectedRows are the picked rows, in order.

func (*NoteList) SetItems

func (l *NoteList) SetItems(items []ListItem, current string)

SetItems replaces the rows, keeping the current row on the same key when it is still there, and the picked rows on theirs.

type Outline

type Outline struct {
	*unison.Panel

	// Levels is which heading levels are listed, bit 0 for level 1.
	Levels int
	// OnLevels runs when the reader changes Levels.
	OnLevels func(levels int)
	// OnClose hides the pane.
	OnClose func()
	// OnGo scrolls the note to a block.
	OnGo func(index int)
	// contains filtered or unexported fields
}

Outline is the outline pane.

func NewOutline

func NewOutline(ui *kvitui.UI, ed *editor.Editor) *Outline

NewOutline returns the outline pane for an editor.

func (*Outline) Current

func (o *Outline) Current() int

Current is the row of the section the caret is in, -1 for none.

func (*Outline) Go

func (o *Outline) Go(row int)

Go scrolls the note to a row's heading.

func (*Outline) Refresh

func (o *Outline) Refresh()

Refresh reads the headings again, after the note or the caret changed.

func (*Outline) Rows

func (o *Outline) Rows() []string

Rows are the headings listed, for tests: each one's text, indented two spaces a level.

type ResultsList

type ResultsList struct {
	unison.Panel

	// OnOpen opens a note, at a hit when it is not nil.
	OnOpen func(path string, hit *search.Hit)
	// Counting is what a note's count counts, for a screen reader.
	Counting string
	// contains filtered or unexported fields
}

ResultsList draws the results.

func (*ResultsList) PerformAccessibilityAction

func (l *ResultsList) PerformAccessibilityAction(req accessibility.ActionRequest) bool

PerformAccessibilityAction opens a row chosen by a screen reader.

func (*ResultsList) ProvideAccessibility

func (l *ResultsList) ProvideAccessibility(b *unison.AccessibilityBuilder)

ProvideAccessibility describes each row: a note with its count, or a line found in it.

type Scope

type Scope struct {
	Kind ScopeKind
	Path string
}

Scope is what the note list shows: every note, the favourites, one folder (Path is its path in the vault, "" the top), the notes with one tag, or the trash.

type ScopeKind

type ScopeKind int

ScopeKind is what a scope of the note list is.

const (
	ScopeAll ScopeKind = iota
	ScopeFavorites
	ScopeFolder
	ScopeTag
	ScopeTrash
)

The scopes.

type ScopeList

type ScopeList struct {
	unison.Panel

	// Rows are the rows, top to bottom; the trash is drawn at the foot of
	// whatever height the list is given.
	Rows []ScopeRow
	// Current is the scope the note list shows.
	Current Scope
	// OnChoose runs when a scope is chosen.
	OnChoose func(Scope)
	// OnToggle runs when a folder is opened or closed.
	OnToggle func(folder string, expanded bool)
	// OnDrag runs while a folder row is dragged, and OnDrop when it is let
	// go, with the pointer in the window's root coordinates.
	OnDrag, OnDrop func(folder string, where geom.Point)

	// Target is the row a dragged note or folder would be dropped on, or -1.
	Target int
	// contains filtered or unexported fields
}

ScopeList is the sidebar's list of scopes.

func NewScopeList

func NewScopeList(ui *kvitui.UI) *ScopeList

NewScopeList returns an empty list.

func (*ScopeList) PerformAccessibilityAction

func (l *ScopeList) PerformAccessibilityAction(req accessibility.ActionRequest) bool

PerformAccessibilityAction chooses, opens or closes a scope for a screen reader.

func (*ScopeList) ProvideAccessibility

func (l *ScopeList) ProvideAccessibility(b *unison.AccessibilityBuilder)

ProvideAccessibility describes each scope as a tree item, the current one holding the focus the list has.

func (*ScopeList) RowAt

func (l *ScopeList) RowAt(where geom.Point) int

RowAt is the row under a point in the list's own coordinates, or -1.

func (*ScopeList) SetRows

func (l *ScopeList) SetRows(rows []ScopeRow)

SetRows replaces the rows.

type ScopeRow

type ScopeRow struct {
	Scope      Scope
	Label      string
	Count      int
	Depth      int  // a folder's depth
	Expandable bool // a folder with folders in it
	Expanded   bool
	Heading    bool // a heading such as "Folders", which is not a scope
	Mark       palette.Color
	HasMark    bool // a folder's or tag's colour, drawn before the label
}

ScopeRow is one row of the sidebar's list.

type TagStrip

type TagStrip struct {
	*unison.Panel

	// OnAdd and OnRemove run when the reader adds or removes a tag.
	OnAdd    func(tag string)
	OnRemove func(tag string)
	// contains filtered or unexported fields
}

TagStrip shows a note's tags and adds and removes them.

func NewTagStrip

func NewTagStrip(ui *kvitui.UI) *TagStrip

NewTagStrip returns an empty strip.

func (*TagStrip) SetSuggestions

func (s *TagStrip) SetSuggestions(tags []string)

SetSuggestions is every tag the field offers.

func (*TagStrip) SetTags

func (s *TagStrip) SetTags(tags []string)

SetTags shows a note's tags.

type Toolbar

type Toolbar struct {
	*unison.Panel
	// contains filtered or unexported fields
}

Toolbar is the strip for an editor.

func NewToolbar

func NewToolbar(ui *kvitui.UI, ed *editor.Editor, hooks ToolbarHooks) *Toolbar

NewToolbar returns the strip for an editor.

func (*Toolbar) BlockKind

func (t *Toolbar) BlockKind() string

BlockKind is what the block type list shows.

func (*Toolbar) FocusFirst

func (t *Toolbar) FocusFirst() bool

FocusFirst puts the keyboard focus on the strip's first button (File, View or Insert), for F6 pane cycling. It reports whether there is one.

func (*Toolbar) FocusedChild

func (t *Toolbar) FocusedChild() bool

FocusedChild reports whether one of the strip's buttons holds the keyboard focus.

func (*Toolbar) GroupOn

func (t *Toolbar) GroupOn(key string) bool

GroupOn reports whether a customization group is shown, by settings key.

func (*Toolbar) OpenMenu

func (t *Toolbar) OpenMenu(key unison.KeyCode) bool

OpenMenu opens the menu Alt and a key names, File, View or Insert, and reports whether there is one.

func (*Toolbar) SetGroup

func (t *Toolbar) SetGroup(key string, on bool) bool

SetGroup shows or hides a customization group, keeping the setting, and reports whether there is one.

func (*Toolbar) SetPrefs

func (t *Toolbar) SetPrefs(p *prefs)

SetPrefs gives the strip the settings its group visibility is kept in, and applies them.

func (*Toolbar) Update

func (t *Toolbar) Update()

Update shows the kind of block the caret is in.

type ToolbarHooks

type ToolbarHooks struct {
	// File and View build the menus of those names when they open.
	File, View func() []kvitui.MenuItem
	// Back and Forward move through the notes opened.
	Back, Forward func()
	// Link opens the link dialog, as Ctrl+K does.
	Link func()
}

ToolbarHooks are what the strip's window-level buttons do; a nil hook leaves its button out, as a window over a single file has no history.

type Window

type Window struct {
	Win    *kvitui.Window
	Vault  *vault.Vault
	Editor *editor.Editor
	// contains filtered or unexported fields
}

Window is one Kvit Notes window over a vault.

func Open

func Open(ui *kvitui.UI, v *vault.Vault) (*Window, error)

Open opens a window over a vault.

func OpenVault

func OpenVault(ui *kvitui.UI, root string) (*Window, error)

OpenVault opens a vault in a new window. An empty vault gets a first note to read.

func (*Window) FindOpen

func (w *Window) FindOpen() (bool, string)

FindOpen reports whether the find bar is shown, and its count.

func (*Window) FocusMode

func (w *Window) FocusMode() bool

FocusMode reports whether focus mode is on.

func (*Window) Results

func (w *Window) Results() []string

Results are the rows the results list shows, for tests: a note as its title, a hit as its line indented two spaces.

func (*Window) SidesHidden

func (w *Window) SidesHidden() bool

SidesHidden reports whether Ctrl+\ has hidden the side panes.

Jump to

Keyboard shortcuts

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