view

package
v0.18.6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package view persists named "smart views" — saved bundles of the `nt list` filter so a user can capture a query once and recall it by name (T4). Views live in $NT_DIR/views.json, a machine-managed file (like undo.jsonl), kept separate from the hand-edited, read-only config.toml so `nt view save` never rewrites a user's annotated config. The package is surface-agnostic: it knows only the filter shape, not how any front-end renders a list, so the CLI, TUI, and web can all share these specs.

Index

Constants

View Source
const FileName = "views.json"

FileName is the views file's basename within $NT_DIR.

Variables

This section is empty.

Functions

func Apply added in v0.15.0

func Apply(tasks []*task.Task, spec Spec, blocked map[string]bool) []*task.Task

Apply selects and orders tasks per spec — the one shared implementation behind `nt list`, `nt view recall`, and the web's saved views, so the same named view can never filter differently on different surfaces (the drift the core audit warned about). blocked is the dependency-blocked id set (task.BlockedIDs) computed over the full document.

func Keep added in v0.15.0

func Keep(t *task.Task, spec Spec, blocked map[string]bool) bool

Keep reports whether one task is selected by spec. An explicit Status matches the task's effective status (a dependency-blocked open task is "blocked"); otherwise the default-list visibility rule applies: done hides unless All, dependency-blocked hides unless All/ShowBlocked.

func Load

func Load(dir string) (map[string]Spec, error)

Load reads $NT_DIR/views.json. A missing file yields an empty (non-nil) map and no error, so callers can treat "no views yet" as the normal first run.

func Names

func Names(views map[string]Spec) []string

Names returns the saved view names sorted alphabetically.

func Save

func Save(dir string, views map[string]Spec) error

Save writes the view set atomically. An empty map is written as `{}` rather than removing the file, keeping the path stable.

func SortTasks added in v0.15.0

func SortTasks(rows []*task.Task, by string)

SortTasks orders rows in place by the named sort: "urgency", "due" (no due date last), or "created". Anything else (including "") keeps file order.

func ValidName

func ValidName(s string) error

ValidName reports whether s is usable as a view name: non-empty, no spaces or path/glob characters, and not a reserved subcommand word.

Types

type Spec

type Spec struct {
	Status      string `json:"status,omitempty"`
	Tag         string `json:"tag,omitempty"`
	Project     string `json:"project,omitempty"`
	Sort        string `json:"sort,omitempty"`
	All         bool   `json:"all,omitempty"`
	ShowBlocked bool   `json:"showBlocked,omitempty"`
	Tree        bool   `json:"tree,omitempty"`
}

Spec is one saved view: the subset of `nt list` flags that select and order tasks. Output-only choices (e.g. --json) are deliberately excluded — they are a recall-time concern, not part of the saved query.

func (Spec) Args

func (s Spec) Args() []string

Args renders a Spec back into the `nt list` flags it represents, in a stable order. It is the inverse of capturing flags, used both to show a view's definition (`nt view list`) and to document what a recall will run. An empty Spec (the all-open default) renders as no flags.

func (Spec) Summary

func (s Spec) Summary() string

Summary is a one-line human description of a view's flags, e.g. "--status open --sort due", or "(all open tasks)" when it has no filters.

Jump to

Keyboard shortcuts

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