ui

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 46 Imported by: ? 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 ui is the notebook the frontend in web drives: tabs, windows and the calls their pages make, apart from the program that shows the windows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConsoleHandler

func NewConsoleHandler(next slog.Handler, c *Console) slog.Handler

NewConsoleHandler is a handler that adds what is logged at info or above to c and passes everything on to next.

func TabCalls

func TabCalls(next http.Handler) http.Handler

TabCalls notes the tab each call from a tab's page came from, for the calls that act on a tab.

func WithTab

func WithTab(ctx context.Context, id int) context.Context

WithTab returns ctx for a call from tab id, as TabCalls notes it, for hosts whose calls don't come over HTTP.

Types

type About

type About struct {
	Version   string `json:"version"`
	Commit    string `json:"commit"`
	BuildTime string `json:"buildTime"`
	Modified  bool   `json:"modified"`
	GoVersion string `json:"goVersion"`
	OS        string `json:"os"`
	Arch      string `json:"arch"`
	// Home is for showing paths as ~/….
	Home string `json:"home"`
	// SettingsFile is the JSON file the settings live in.
	SettingsFile string `json:"settingsFile"`
	// Zshrc is the .zshrc the zsh wrapper setting edits.
	Zshrc string `json:"zshrc"`
	Tools []Tool `json:"tools"`
	Links []Link `json:"links"`
}

About is what Settings' About tab shows.

type App

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

App is the service the frontend calls. A call from a tab's page acts on that tab; one from a window's tab bar, on that window. Its exported methods are all calls the frontend makes; the Host drives it through its Control.

func New

func New(host Host, store *settings.Store, cwd, dir, source string) *App

New makes an App showing its windows with host and keeping its settings in store. cwd is the folder the program started in and dir the folder named on the command line, if any. source is what the files given to --source hold, for every shell to source.

func (*App) About

func (a *App) About() About

About gathers the version, build, paths and tools for the About tab.

func (*App) Answer

func (a *App) Answer(ctx context.Context, reply string) error

Answer replies to the question a confirm event asked: "run", "skip" or "stop".

func (*App) AnswerOutside

func (a *App) AnswerOutside(ctx context.Context, answer string) error

AnswerOutside remembers whether the file may reach the files Outside lists now, and starts its shells again so the answer holds for its runs. "allow" and "deny" are remembered; "" forgets the answer, so the page asks the next time the file opens.

func (*App) BlockAt

func (a *App) BlockAt(ctx context.Context, line int) (int, error)

BlockAt is the top-level block on line of the file, or -1.

func (*App) BlockAttrs

func (a *App) BlockAttrs() []doc.AttrSpec

BlockAttrs describes the block attributes, for completion, hover help and the attribute form.

func (*App) CLIState

func (a *App) CLIState() CLI

CLIState says where the command line tool stands.

func (*App) Cells

func (a *App) Cells(ctx context.Context) ([]notebook.Cell, error)

Cells is the document laid out for drawing.

func (*App) Changelog

func (a *App) Changelog() (string, error)

Changelog is the app's changelog, rendered, for its tab.

func (*App) Cheatsheet

func (a *App) Cheatsheet() (string, error)

Cheatsheet is the app's cheat sheet, rendered, for its tab.

func (*App) CheckInfos

func (a *App) CheckInfos(infos []string) [][]notebook.Problem

CheckInfos checks the attributes in fences' info strings. The source pane asks about every new one in one call: a long document has thousands, and asking about each in turn took seconds.

func (*App) ChooseFile

func (a *App) ChooseFile(ctx context.Context, title, dir string) (string, error)

ChooseFile asks for a markdown file, with title, starting in dir or the start folder, and returns it, or "" if none was picked.

func (*App) ChooseFolder

func (a *App) ChooseFolder(ctx context.Context, title, dir string) (string, error)

ChooseFolder asks for a folder, with title, starting in dir or the start folder, and returns it, or "" if none was picked.

func (*App) ChooseReport

func (a *App) ChooseReport(ctx context.Context, format report.Format, dest string) (string, error)

ChooseReport asks where to save a report in format, starting at dest, and returns the file, or "" if none was picked.

func (*App) ClearConsole

func (a *App) ClearConsole()

ClearConsole empties the console, in every window.

func (*App) ClearEarlierRuns

func (a *App) ClearEarlierRuns(ctx context.Context, i int) error

ClearEarlierRuns takes block i's earlier runs, kept by history=N, out of the file, and keeps its current output. Undo puts them back.

func (*App) ClearOutput

func (a *App) ClearOutput(ctx context.Context, i int) error

ClearOutput takes block i's output out of the file and forgets its run. Undo puts it back.

func (*App) ClearOutputs

func (a *App) ClearOutputs(ctx context.Context) error

ClearOutputs takes every block's output out of the document and starts its shells again.

func (*App) CloseTab

func (a *App) CloseTab(id int) error

CloseTab closes tab id, asking first if it has unsaved output.

func (*App) Console

func (a *App) Console() []ConsoleEntry

Console returns what the console holds, oldest first. New entries come as "console" events, a "console-stale" event names by Seq the entries that no longer apply, and a "console-cleared" event says it was cleared.

func (*App) CopyCastGIF

func (a *App) CopyCastGIF(cast string) error

CopyCastGIF puts an animated GIF of cast, an asciicast v2 recording, on the clipboard.

func (*App) CopySecret

func (a *App) CopySecret(text string) error

CopySecret puts text, which may hold a secret, on the clipboard, kept out of clipboard history where the system allows, and takes it off again after the settings' SecretShow unless something else was copied.

func (*App) CreateReport

func (a *App) CreateReport(ctx context.Context, r notebook.Report) error

CreateReport writes the report r describes.

func (*App) Curl

func (a *App) Curl(ctx context.Context, i int) (string, error)

Curl is http block i's request as a curl command line, with the placeholders filled in as running it now would, for Copy as curl.

func (*App) DeleteBlock

func (a *App) DeleteBlock(ctx context.Context, i int) (notebook.Deleted, error)

DeleteBlock takes top-level block i, with its output and tape, out of the file. Undo puts it back.

func (*App) DeleteEarlierRun

func (a *App) DeleteEarlierRun(ctx context.Context, i, k int) error

DeleteEarlierRun takes block i's earlier run k out of the file, and numbers the rest again. Undo puts it back.

func (*App) DependsAt

func (a *App) DependsAt(ctx context.Context) (Depends, error)

DependsAt is the names in the file's depends= that aren't a block that runs, for the source pane to underline, and the version of the text whose lines they name.

func (*App) DescribeFix

func (a *App) DescribeFix(ctx context.Context, warning string) (notebook.Fix, error)

DescribeFix says what FixWarning would do for warning, a console entry's message, in the file this window shows.

func (*App) DetachTab

func (a *App) DetachTab(x, y int) error

DetachTab gives the tab being dragged a window of its own, at x, y on the screen, if it shares its window. It does nothing if no tab is being dragged.

func (*App) Doc

func (a *App) Doc(ctx context.Context) (Doc, error)

Doc describes the open file. File is "" while the start screen shows.

func (*App) DragTab

func (a *App) DragTab(id int) error

DragTab notes that tab id is being dragged, so the window it is dropped on can take it.

func (*App) DropTab

func (a *App) DropTab(ctx context.Context, i int) error

DropTab puts the tab being dragged in the calling window, at index i of its tab bar. It does nothing if no tab is being dragged.

func (*App) Edit

Edit makes line edits typed in the source pane against version v of the file, if it is still at v. When it isn't, it changes nothing and says how the file changed since, so the pane can fold that in around what was typed and try again. A key costs the lines it changed, not the whole file twice, as SetText does.

func (*App) EndDrag

func (a *App) EndDrag(id int, outside bool, x, y int) error

EndDrag ends dragging tab id. If no window took it and it was let go outside its window, at x, y on the screen, it gets a window of its own there.

func (*App) Events

func (a *App) Events(ctx context.Context) ([]notebook.AuditEvent, error)

Events is the event log of the file this window shows: its shells starting and ending, and why, blocks running, the file changing on disk and mdsh ctl calls, oldest first. New events come as "audit" events.

func (*App) FixWarning

func (a *App) FixWarning(ctx context.Context, warning string) error

FixWarning makes the fix a console entry offers for warning, its message, in the file this window shows. Undo takes it back.

func (*App) FolderSettings

func (a *App) FolderSettings(rel string) (FolderForm, error)

FolderSettings reads the .mdsh.yaml of rel, a folder the start screen lists, for the folder settings dialog.

func (*App) Fonts

func (a *App) Fonts() fonts.Fonts

Fonts lists the font families installed on this computer, for the Look tab's font menus.

func (*App) FrontMatter

func (a *App) FrontMatter(ctx context.Context) (notebook.FrontMatter, error)

FrontMatter reads the file's front matter for the rendered view's front matter form.

func (*App) HasOutput

func (a *App) HasOutput(ctx context.Context) (bool, error)

HasOutput reports whether the file has output for ClearOutputs to take out, so Clear All Outputs is only offered when it would do something.

func (*App) HistoryComplete

func (a *App) HistoryComplete(ctx context.Context, input string) bool

HistoryComplete reports whether input is a whole command, so enter runs it, rather than starting another line.

func (*App) HistoryCompletions

func (a *App) HistoryCompletions(ctx context.Context, before string) (notebook.Completion, error)

HistoryCompletions completes the word at the end of before, what is typed in the History pane up to the cursor, for Tab.

func (*App) HistoryEnter

func (a *App) HistoryEnter(ctx context.Context, input string, record bool) error

HistoryEnter takes what was typed in the History pane: a note is added to the file as prose, and a command is added as a block and run. With record false, as the pane's Record switch sets, a command runs without being added.

func (*App) HistoryPrompt

func (a *App) HistoryPrompt(ctx context.Context, cols, rows int) (notebook.Prompt, error)

HistoryPrompt is the shell's PS1 and PS2, expanded, for the History pane's prompt, at the pane's size, cols by rows.

func (*App) IncludeFile

func (a *App) IncludeFile(ctx context.Context, i int) (notebook.IncludeFile, error)

IncludeFile reads the whole of include block i's file, for showing it and for dragging the include's range over it.

func (*App) InstallCLI

func (a *App) InstallCLI() (CLI, error)

InstallCLI puts the command line tool on PATH, and returns where it stands after.

func (*App) KillProcess

func (a *App) KillProcess(ctx context.Context, pid int) bool

KillProcess kills process pid and what it started, if it runs under one of the tab's shells, and reports whether it did.

func (*App) KillShell

func (a *App) KillShell(ctx context.Context) bool

KillShell ends the shell the running block runs in, at once, for a block that Stop didn't stop, once the user has said to. What blocks set in that shell is gone. It reports whether a block was running.

func (*App) LastSession

func (a *App) LastSession(ctx context.Context) error

LastSession opens the file in the sessions folder changed last, as NewSession opens a session.

func (*App) LinesSince

func (a *App) LinesSince(ctx context.Context, v notebook.Version) (notebook.Lines, error)

LinesSince is how the file changed after version v, as line events, for a source pane catching up with what Go wrote, such as a run's output, without reading the whole file again.

func (*App) Live

func (a *App) Live(ctx context.Context) ([]liveEvent, error)

Live is what the run going on in the tab has sent so far, for a page that starts partway through it.

func (*App) MoveBlock

func (a *App) MoveBlock(ctx context.Context, i, dir int, byBlock bool) (notebook.Move, error)

MoveBlock moves top-level block i up (dir < 0) or down past the next cell, or with byBlock past the next block. Undo takes it back.

func (*App) MoveTo

func (a *App) MoveTo(ctx context.Context, from, at int) (notebook.Move, error)

MoveTo moves the block or heading's section that starts at from to at, a cell's From or -1 for the end, as dragging does.

func (*App) Names

func (a *App) Names(ctx context.Context) (notebook.Names, error)

Names are the block ids and envs in the file, for completion.

func (*App) Neovim

func (a *App) Neovim() NeovimInfo

Neovim says which nvim the source pane would run.

func (*App) NewFile

func (a *App) NewFile(ctx context.Context, template string) error

NewFile asks where to make a new markdown file and opens it: in this tab if it shows the start screen, else in a new tab. The file is a copy of template, or a heading if template is "".

func (*App) NewSession

func (a *App) NewSession(ctx context.Context) error

NewSession opens the day's session, from the start screen: a file named for the date in the sessions folder, made from the session template if it isn't there yet, or else set to run in your login shell. It opens with the History pane open and focused.

func (*App) NewTab

func (a *App) NewTab(ctx context.Context) error

NewTab opens a tab with the start screen in the calling window, after the tab in front.

func (*App) NewWindow

func (a *App) NewWindow()

NewWindow opens a window with the start screen.

func (*App) NvimApply

func (a *App) NvimApply(ctx context.Context, seq int, edits []nvim.LineEdit) (bool, error)

NvimApply makes edits on Neovim's text, as the page merged Go's changes with what was typed, made against its text as of seq, the count of the nvim-lines events the page has had and its own NvimApply calls. It reports false, changing nothing, if Neovim has typing the page hasn't had: that comes as nvim-lines, and the page tries again.

func (*App) NvimCall

func (a *App) NvimCall(ctx context.Context, fn, args string) (string, error)

NvimCall calls fn in mdsh.lua with args, a JSON array, and returns its result as JSON: the cursor, setting the run buttons or folds, and so on.

func (*App) NvimInput

func (a *App) NvimInput(ctx context.Context, keys string) error

NvimInput types keys, in Neovim's notation.

func (*App) NvimMouse

func (a *App) NvimMouse(ctx context.Context, button, action, mod string, row, col int) error

NvimMouse passes on a mouse event at a grid cell.

func (*App) NvimPaste

func (a *App) NvimPaste(ctx context.Context, text string) error

NvimPaste pastes text.

func (*App) NvimResize

func (a *App) NvimResize(ctx context.Context, cols, rows int) error

NvimResize resizes the grid. Before Neovim runs there is nothing to resize: NvimStart takes the size.

func (*App) NvimSaved

func (a *App) NvimSaved(ctx context.Context) error

NvimSaved marks Neovim's buffer unchanged after a save.

func (*App) NvimStart

func (a *App) NvimStart(ctx context.Context, cols, rows int, background string) (NvimText, error)

NvimStart starts the tab's Neovim with a grid of cols by rows, editing the file's text, with 'background' set to "light" or "dark" to match the page. A running one is left as it is.

func (*App) NvimStop

func (a *App) NvimStop(ctx context.Context)

NvimStop quits the tab's Neovim, as the source pane closes.

func (*App) Open

func (a *App) Open(ctx context.Context) error

Open asks for markdown files and opens them: the first in this tab if it shows the start screen, the rest in new tabs.

func (a *App) OpenLink(ctx context.Context, href string) (string, error)

OpenLink follows href, a link in the tab's document: a web address opens in the browser, a markdown file in a new tab beside this one, and an image beside the document is shown full size in the window: OpenLink returns the address the window loads it from. Any other file is shown in the file manager, unless Settings › Files lists its type to open with the system's app. Opening it would run a .command, .app or script beside the document on one click, past every question a block asks (finding 6 of the v1.4.0 security review).

func (*App) OpenPath

func (a *App) OpenPath(ctx context.Context, file string) error

OpenPath opens file, from the start screen.

func (*App) OpenURL

func (a *App) OpenURL(u string) error

OpenURL opens a web address in the browser, for the About tab's links.

func (*App) Outside

func (a *App) Outside(ctx context.Context) (OutsideFiles, error)

Outside lists what the file reaches outside its root, for the page to ask about once per file, and again when the list changes, as mdsh --allow-outside allows it on the command line.

func (*App) Pin

func (a *App) Pin(file string, pin bool) error

Pin pins file to the top of the start screen, or unpins it.

func (*App) PlanMove

func (a *App) PlanMove(ctx context.Context, i, dir int, byBlock bool) (notebook.Move, error)

PlanMove works out MoveBlock's move without making it, for the source view to make as its own edit.

func (*App) Processes

func (a *App) Processes(ctx context.Context) []env.ShellProcs

Processes lists the tab's shells, each with the processes under it, for the Console's Processes tab. It is empty when no shell runs.

func (*App) Redo

func (a *App) Redo(ctx context.Context) (string, error)

Redo does again what Undo took back, and says what it was.

func (*App) Reload

func (a *App) Reload(ctx context.Context) error

Reload reads the file from disk again, dropping output not saved. The shells keep what blocks set in them, unless the front matter changed the shell, env.share or env.source.

func (*App) RememberView

func (a *App) RememberView(file, view string, history bool) error

RememberView notes how file is shown, for the next time it opens: view is "rendered", "source" or "both", and history is whether the History pane is open.

func (*App) RemoteImage

func (a *App) RemoteImage(ctx context.Context, src string, load bool) (string, error)

RemoteImage returns the image at src, an image in this window's document that the window doesn't load by itself, as a data: URI for it to show: an http: or https: address on another site, or a file outside the document's folder (or hidden in it), which the window's /doc route doesn't serve. With load false, it only does so for an image the user loaded in this document before, and returns "" for any other, without going to the network. With load true, from the note's Load button, it fetches the image, and remembers that this document may load it, so it loads by itself from then on. Anything that isn't a PNG, JPEG, GIF, WebP, BMP or icon, or is over 20 MB, is refused.

func (*App) ReplaceCast

func (a *App) ReplaceCast(ctx context.Context, i int, as string, frame int) error

ReplaceCast swaps tty block i's recording, in its output, for the text of frame n (as "text") or an animated GIF of it (as "gif"). Undo puts the recording back.

func (*App) ReportCommand

func (a *App) ReportCommand(ctx context.Context, r notebook.Report) (string, error)

ReportCommand is the mdsh command that makes the report r describes.

func (*App) ReportStart

func (a *App) ReportStart(ctx context.Context) (ReportStart, error)

ReportStart reads what the Report dialog shows when it opens.

func (*App) RestartShells

func (a *App) RestartShells(ctx context.Context) error

RestartShells starts the file's shells again, as if nothing had run, without changing the file. The page asks the user first: it is the one way the app ends shells that blocks set things up in.

func (*App) Reveal

func (a *App) Reveal(file string) error

Reveal shows file in the file manager.

func (*App) RunBlock

func (a *App) RunBlock(ctx context.Context, i int) error

RunBlock runs block i alone.

func (*App) RunFrom

func (a *App) RunFrom(ctx context.Context, i int) error

RunFrom runs block i and the blocks after it.

func (*App) RunSection

func (a *App) RunSection(ctx context.Context, from, to int) error

RunSection runs blocks from up to but not including to, a heading's section, as Run all runs them.

func (*App) Save

func (a *App) Save(ctx context.Context) error

Save writes the output into the file.

func (*App) SaveAs

func (a *App) SaveAs(ctx context.Context) (bool, error)

SaveAs asks where to save the file with its output, and from then on the tab shows the new file. It returns false if the user cancels.

func (*App) SelectTab

func (a *App) SelectTab(id int) error

SelectTab brings tab id to the front of its window.

func (*App) SetCastFrame

func (a *App) SetCastFrame(ctx context.Context, i int, body string, frame int) error

SetCastFrame writes frame=n, where a recording's player was left, on tty block i, or with i < 0 on the cast fence holding body. Undo takes it back.

func (*App) SetChoice

func (a *App) SetChoice(ctx context.Context, i int, checked []bool) error

SetChoice checks the options of choice block i as picked in it.

func (*App) SetDepends

func (a *App) SetDepends(ctx context.Context, i int, deps []int) error

SetDepends sets block i's depends= to the blocks deps names, by index, or takes it out when deps is empty. Undo takes it back.

func (*App) SetFolderSettings

func (a *App) SetFolderSettings(rel string, s collection.Settings) error

SetFolderSettings saves s as the .mdsh.yaml of rel, a folder the start screen lists. See collection.Write.

func (*App) SetFolds

func (a *App) SetFolds(ctx context.Context, folds []notebook.Fold) error

SetFolds writes folds made by hand in the rendered view to the file, as collapse attributes and mdsh:collapse lines, so it opens with them.

func (*App) SetFrontMatter

func (a *App) SetFrontMatter(ctx context.Context, f notebook.FrontMatter) error

SetFrontMatter writes the front matter form's fields to the file, changing only the keys whose field changed. Undo takes it back.

func (*App) SetHistory

func (a *App) SetHistory(ctx context.Context, on, restart bool) (bool, error)

SetHistory turns the History pane on or off for the file. Turning it on needs shells on a terminal: if theirs have none and blocks have run in them, it starts them again only with restart, the user having said so, and otherwise fails with notebook.ErrRestartNeeded. It reports whether they started again. The shells read the rc file Settings names as it is now.

func (*App) SetIncludeRange

func (a *App) SetIncludeRange(ctx context.Context, i, from, to int) error

SetIncludeRange writes from= and to= on include block i, as its grips were dragged to. Undo takes it back.

func (*App) SetRunOptions

func (a *App) SetRunOptions(ctx context.Context, args, only string, step, stopOnError bool) error

SetRunOptions sets the arguments (one line, split as a shell would), --only, --step and --stop-on-error for this file.

func (*App) SetSettings

func (a *App) SetSettings(s settings.Settings) error

SetSettings saves the settings edited in Settings (see edited). Open windows hear of it with a "settings" event.

func (*App) SetTask

func (a *App) SetTask(ctx context.Context, task int, done bool) error

SetTask checks or unchecks task list item task, as numbered by the cells' tasks, in the file.

func (*App) SetTerminalSize

func (a *App) SetTerminalSize(ctx context.Context, cols, rows int)

SetTerminalSize sets the terminal pane's size in cells, which the window works out from its width.

func (*App) SetText

func (a *App) SetText(ctx context.Context, base, text string) (bool, error)

SetText replaces the whole file, as typed in the source pane, if it is still base, and reports whether it did. When it isn't, the pane reads the file again, keeps what was typed and tries again.

func (*App) SetTextbox

func (a *App) SetTextbox(ctx context.Context, i int, text string) error

SetTextbox replaces the text of textbox block i, as typed in it.

func (*App) SetView

func (a *App) SetView(ctx context.Context, v View)

SetView notes what the calling tab shows.

func (*App) SetZshWrapper

func (a *App) SetZshWrapper(on bool) (ZshWrapper, error)

SetZshWrapper adds the mdsh function to the user's .zshrc, and to their .bashrc if they have one, or takes it out of both, and returns the new state. It doesn't make a .bashrc for someone who doesn't use bash.

func (*App) Settings

func (a *App) Settings() settings.Settings

Settings are the app-wide settings.

func (*App) ShowChangelog

func (a *App) ShowChangelog()

ShowChangelog brings the changelog's tab forward, opening one if there is none (see showPage).

func (*App) ShowCheatsheet

func (a *App) ShowCheatsheet()

ShowCheatsheet brings the cheat sheet's tab forward, opening one as ShowChangelog does.

func (*App) SourceBlocks

func (a *App) SourceBlocks(text string) []notebook.SourceBlock

SourceBlocks lists the blocks in the source pane's text, for completing and checking depends=.

func (*App) SourceBlocksAt

func (a *App) SourceBlocksAt(ctx context.Context) (SourceBlocks, error)

SourceBlocksAt is the file's blocks, for completing depends= in the source pane, and the version of the text whose lines they name.

func (*App) StartScreen

func (a *App) StartScreen() (Start, error)

StartScreen lists the markdown files under the start folder, and the recent files that still exist.

func (*App) Stop

func (a *App) Stop(ctx context.Context)

Stop stops the running block, answering stop if a block is waiting to be confirmed. The block is interrupted, as ctrl+c would, and its shell lives on.

func (*App) StopBackground

func (a *App) StopBackground(ctx context.Context, block int) bool

StopBackground kills block, which runs in the background, as Stop can't once the run that started it is over. It reports whether the block was still running.

func (*App) Tabs

func (a *App) Tabs(ctx context.Context) (Tabs, error)

Tabs are the calling window's tabs, for its tab bar.

func (*App) Templates

func (a *App) Templates() ([]library.File, error)

Templates lists the markdown files in the templates folder, for New File… to start from. With no templates folder set it lists none.

func (*App) Text

func (a *App) Text(ctx context.Context) (string, error)

Text is the whole file, for the split view's source pane.

func (*App) TextAt

func (a *App) TextAt(ctx context.Context) (SourceText, error)

TextAt is the whole file and its version.

func (*App) Type

func (a *App) Type(ctx context.Context, keys string)

Type sends keys typed in the terminal pane to the tty block running in it.

func (*App) Undo

func (a *App) Undo(ctx context.Context) (string, error)

Undo takes back the rendered view's last edit, such as checking a task, and says what it was: "" when there is none.

func (*App) UninstallCLI

func (a *App) UninstallCLI() (CLI, error)

UninstallCLI takes the command line tool off PATH, when it's this app's, and returns where it stands after.

func (*App) ZshWrapperState

func (a *App) ZshWrapperState() (ZshWrapper, error)

ZshWrapperState reads the user's .zshrc and .bashrc for the mdsh function, bringing a block from an older mdsh-gui up to date so it loads completion too.

type Build

type Build struct {
	Version  string // the release version, module version or "dev"
	Commit   string // the vcs revision, shortened
	Time     string // when the commit was made, as the vcs recorded it
	Modified bool   // the tree had uncommitted changes
}

Build is what the binary knows about itself, for the About tab.

func BuildInfo

func BuildInfo(version string, bi *debug.BuildInfo) Build

BuildInfo reads the version from the release build's version, else from bi: the module version for a go install build, and the vcs revision, time and modified flag when the build had them.

func (Build) String

func (b Build) String() string

String is the version as --version prints it: the version, then the commit and its time in parentheses when known, with "modified" after the commit when the tree had uncommitted changes.

type Button

type Button struct {
	Label   string
	Default bool // picked by return
	Cancel  bool // picked by escape
	Do      func()
}

Button is one of a Question's answers.

type CLI

type CLI struct {
	// Bundled is the mdsh this app carries, or "" when this build
	// carries none (go run, go install, a .deb, Windows, a browser).
	Bundled string `json:"bundled"`
	// Link is where Install puts it.
	Link string `json:"link"`
	// Copy is whether Install copies Bundled to Link (an AppImage)
	// rather than linking to it (macOS).
	Copy bool `json:"copy"`
	// Installed is whether Link is this app's: a symlink to Bundled, or
	// a copy with the marker beside it.
	Installed bool `json:"installed"`
	// Broken is where Link points when it's a symlink into an mdsh.app
	// that isn't this one, such as after the app moved.
	Broken string `json:"broken"`
	// OtherApp is whether Broken is still there: another mdsh.app, such
	// as an older release's, rather than where this one used to be.
	OtherApp bool `json:"otherApp"`
	// Linked is another mdsh on PATH that is this app's, such as the
	// Homebrew cask's link, which comes first on PATH.
	Linked string `json:"linked"`
	// Other is an mdsh on PATH that isn't this app's, such as the
	// formula's. Install won't put a second one beside it.
	Other string `json:"other"`
	// InPath is whether Link's folder is on PATH.
	InPath bool `json:"inPath"`
	// Home is for showing paths as ~/….
	Home string `json:"home"`
}

CLI is where the command line tool stands, for Settings › Shell. The desktop app carries mdsh and can put it on PATH; see docs/design/cli-in-app.md.

type Console

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

Console is the log the Console pane shows.

func NewConsole

func NewConsole() *Console

NewConsole makes an empty console. Log to it through a handler from NewConsoleHandler, and have Send take what it gets to the windows.

func (*Console) Send

func (c *Console) Send(ctx context.Context, emit func(ConsoleEntry), stale func([]int))

Send calls emit for each new entry, and stale with the Seqs of the entries that go stale, until the app ends.

type ConsoleEntry

type ConsoleEntry struct {
	Seq     int       `json:"seq"` // counts up from 1, so a page can tell it missed one
	Time    time.Time `json:"time"`
	Level   string    `json:"level"`
	Message string    `json:"message"`        // the message, then its attributes as key=value
	File    string    `json:"file,omitempty"` // the file the entry is about, from a "file" attribute
	Line    int       `json:"line,omitempty"` // the line in File, from a "line" attribute; 0 if none
	Fix     string    `json:"fix,omitempty"`  // names the fix for it, from a "fix" attribute
	// Stale says it no longer applies: an edit fixed what it warned of.
	Stale bool `json:"stale,omitempty"`
}

ConsoleEntry is one line of the console.

type Control

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

Control is how a Host drives its App: what its windows tell it, and its menu commands. It is apart from App so the frontend can't call it.

func ControlOf

func ControlOf(a *App) Control

ControlOf is a's Control.

func (Control) Assets

func (c Control) Assets(frontend http.Handler) http.Handler

Assets serves frontend, and at notebook.DocPrefix the files beside the open documents, such as the images their blocks write.

func (Control) ClearRecent

func (c Control) ClearRecent()

ClearRecent forgets the recent files.

func (Control) CloseTab

func (c Control) CloseTab()

CloseTab closes the tab in front, asking first if it has unsaved output.

func (Control) CloseWindow

func (c Control) CloseWindow()

CloseWindow closes the window in front.

func (Control) Closing

func (c Control) Closing(id uint) bool

Closing is told window id is closing, and says whether it may: its tabs close first, asking about unsaved output in each, and the window closes again once none are left.

func (Control) Console

func (c Control) Console() *Console

Console is the App's console, for the host to log to with a handler from NewConsoleHandler and to send on to the windows with its Send.

func (Control) CycleTab

func (c Control) CycleTab(by int)

CycleTab brings the tab by places from the one in front forward.

func (Control) Dropped

func (c Control) Dropped(id uint, files []string)

Dropped opens the markdown files dropped on window id.

func (Control) File

func (c Control) File(id uint) string

File is the file in front of window id, or "" if it shows the start screen.

func (Control) Focused

func (c Control) Focused(id uint)

Focused is told window id came to the front.

func (c Control) FollowLink(href string) error

FollowLink follows href, a link in the document of the tab in front, as OpenLink does; an image beside the document is shown full size in the tab's window.

func (Control) LinkTarget

func (c Control) LinkTarget(href string) string

LinkTarget is where href, a link in the document of the tab in front, goes: a web address or a file's path, or href itself if it can't tell.

func (Control) NewFile

func (c Control) NewFile()

NewFile runs File › New File…: the tab in front asks which template to start from. With no window open there is no page to ask in, so it makes a blank file.

func (Control) NewTab

func (c Control) NewTab()

NewTab opens a tab with the start screen in the window in front, or in a new window if there is none.

func (Control) NewWindow

func (c Control) NewWindow() Window

NewWindow opens a window with the start screen.

func (Control) NvimEdit

func (c Control) NvimEdit(op string, get func() (string, bool), set func(string) bool)

NvimEdit does the Neovim pane's right-click Cut, Copy or Paste in the current tab, with the clipboard's get and set. They act on Neovim's selection: the page, which only draws Neovim's grid, has none for the usual edit commands. Paste in visual mode replaces the selection, as Neovim's own paste does.

func (Control) Open

func (c Control) Open()

Open asks for markdown files and opens them in the window in front.

func (Control) OpenFile

func (c Control) OpenFile(file string)

OpenFile opens file in the window in front, telling the user if it can't.

func (Control) OpenFromSystem

func (c Control) OpenFromSystem(file string)

OpenFromSystem opens a file the system asked the app to open, such as from Finder's Open With. Before SystemOpensReady it is held.

func (Control) OpenSettings

func (c Control) OpenSettings(tab string)

OpenSettings brings the Settings tab forward, opening one if there is none, at one of its own tabs, such as "about", or at the one it was on for "".

func (Control) Quitting

func (c Control) Quitting()

Quitting lets every window close without asking about unsaved output, as the program is ending.

func (Control) Send

func (c Control) Send(action string)

Send sends action to the tab in front as a "menu" event, so its page runs it the way its own buttons and keys do.

func (Control) SendTo

func (c Control) SendTo(id uint, action string) bool

SendTo sends action to the tab in front in window id as a "menu" event, and reports whether id is one of the App's windows.

func (Control) SetBuild

func (c Control) SetBuild(b Build)

SetBuild says which build of the program is running, for the About tab.

func (Control) SetImages

func (c Control) SetImages(s *trust.Store)

SetImages sets where the App remembers the images from other sites the user loaded in each file. Nil remembers nothing.

func (Control) SetLSP

func (c Control) SetLSP(cmd func(file string) []string)

SetLSP says how to run the language server for a file, for the Neovim source pane: cmd(file) is the command and its arguments.

func (Control) SetOutside

func (c Control) SetOutside(s *trust.Store)

SetOutside sets where the App remembers which files may reach outside their folder, or hidden in it. Nil remembers nothing.

func (Control) SetTrust

func (c Control) SetTrust(s *trust.Store)

SetTrust sets where the answers to whether a file's env.source files may be read into its shells are remembered; nil remembers none.

func (Control) Settings

func (c Control) Settings() *settings.Store

Settings are the settings the App keeps.

func (Control) ShouldQuit

func (c Control) ShouldQuit() bool

ShouldQuit asks before quitting with unsaved output in any window.

func (Control) ShowChangelog

func (c Control) ShowChangelog()

ShowChangelog brings the changelog's tab forward, for a Help menu.

func (Control) ShowCheatsheet

func (c Control) ShowCheatsheet()

ShowCheatsheet brings the cheat sheet's tab forward, for a Help menu.

func (Control) ShowError

func (c Control) ShowError(err error)

ShowError tells the user about err, over the window in front.

func (Control) Start

func (c Control) Start(file string, run notebook.RunOptions) error

Start opens the first window, with file open in it, run with args, or with the start screen if file is "".

func (Control) SystemOpensReady

func (c Control) SystemOpensReady()

SystemOpensReady opens the files the system asked for before the app started; later ones open at once.

type Depends

type Depends struct {
	Problems []notebook.DependsProblem `json:"problems"`
	Version  notebook.Version          `json:"version"`
}

Depends are DependsAt's problems at a version of the file.

type Doc

type Doc struct {
	File    string `json:"file"`
	Dirty   bool   `json:"dirty"`
	Changed bool   `json:"changed"`
	Running bool   `json:"running"` // a run is going on
	// Fresh is set the first time Doc is asked for after a file opens
	// in the tab, but not after it is reloaded, so the page can show
	// the view the settings open files in.
	Fresh bool `json:"fresh"`
	// OpenHistory is set the first time Doc is asked for after a
	// session opens in the tab, so the page opens the History pane and
	// focuses it.
	OpenHistory bool                `json:"openHistory"`
	Run         notebook.RunOptions `json:"run"`
	// Args is Run.Args as one line, quoted as a shell would need.
	Args string `json:"args"`
	// History is set while the History pane is on for the file.
	History bool `json:"history"`
	// TermCols and TermRows are the terminal size the front matter asks
	// for, 0 where it doesn't.
	TermCols int `json:"termCols"`
	TermRows int `json:"termRows"`
	// EnvBanner, if set, says that the front matter brings in more than
	// the base set from the environment the app started in (env.share
	// with ..., or naming variables).
	EnvBanner string `json:"envBanner"`
	// FrontMatterError, if set, is why the front matter doesn't parse:
	// the page shows it and runs nothing until it does. FrontMatterFix
	// is the fix FixWarning makes for it, with that as the warning, if
	// there is one; its Label is "" if not.
	FrontMatterError string       `json:"frontMatterError"`
	FrontMatterFix   notebook.Fix `json:"frontMatterFix"`
	// LastView is how the file was last shown, "rendered", "source" or
	// "both", or "" if that isn't remembered. LastHistory is whether
	// its History pane was open then.
	LastView    string `json:"lastView"`
	LastHistory bool   `json:"lastHistory"`
}

Doc is what the frontend shows about the open file.

type FolderForm

type FolderForm struct {
	// Path is the folder's absolute path.
	Path     string              `json:"path"`
	Settings collection.Settings `json:"settings"`
	// Images are image files in the folder, for the icon and background.
	Images []string `json:"images"`
}

FolderForm is what the folder settings dialog edits.

type Host

type Host interface {
	// NewWindow opens a window showing the tab bar, for file if it
	// isn't "": where file's window was last, say. The host tells the
	// App's Control when it is closing, gets files dropped on it or
	// comes to the front.
	NewWindow(file string) Window
	// WindowOf is the window a frontend call came from.
	WindowOf(ctx context.Context) (id uint, ok bool)
	// Current is the window in front, if the host knows.
	Current() (id uint, ok bool)
	// EmitAll sends an event to every window.
	EmitAll(name string, data any)
	// OnMain runs fn where the host may close windows.
	OnMain(fn func())

	// ShowError tells the user about err, over win if it isn't nil.
	ShowError(win Window, err error)
	// Ask asks a question over win with buttons and returns at once;
	// the button picked runs its Do, if it has one.
	Ask(win Window, q Question)
	// OpenFiles asks for markdown files, starting in dir.
	OpenFiles(win Window, dir string) ([]string, error)
	// SaveFile asks where to save a file, and returns "" if none was
	// picked.
	SaveFile(win Window, s SaveFile) (string, error)
	// ChooseFolder asks for a folder, with title, starting in dir, over
	// the window the call ctx is for came from, and returns "" if none
	// was picked.
	ChooseFolder(ctx context.Context, title, dir string) (string, error)
	// ChooseFile asks for a markdown file, with title, starting in dir,
	// over the window the call ctx is for came from, and returns "" if
	// none was picked.
	ChooseFile(ctx context.Context, title, dir string) (string, error)
	// Reveal shows file in the file manager.
	Reveal(file string) error
	// OpenURL opens a web address, as a link in a document gives it.
	OpenURL(url string) error
	// OpenFile opens a file that isn't markdown, as the system would.
	OpenFile(file string) error
	// CopySecret puts text, which may hold a secret, on the clipboard,
	// kept out of clipboard history where the system allows, and takes
	// it off again after clear unless something else was copied.
	CopySecret(text string, clear time.Duration) error
	// CopyGIF puts data, an animated GIF, on the clipboard. Where it
	// can't, its error says it "needs macOS", and the page copies the
	// recording's text instead.
	CopyGIF(data []byte) error
	// CLIState says where the command line tool the app carries stands;
	// the zero CLI when it carries none.
	CLIState() CLI
	// InstallCLI puts the command line tool on PATH, and returns where
	// it stands after.
	InstallCLI() (CLI, error)
	// UninstallCLI takes the command line tool off PATH, when it's the
	// app's, and returns where it stands after.
	UninstallCLI() (CLI, error)

	// ShowView says what the tab in front shows, for a View menu.
	ShowView(v View)
	// RecentChanged says the recent files changed, for an Open Recent
	// menu.
	RecentChanged()
	// Quit quits, after ShouldQuit has said yes.
	Quit()
}

Host is what an App needs from the program that shows its windows: mdsh-gui's Wails windows, say. Each window's page is web's window.html.

type Link struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

Link is a place to read more.

type NeovimInfo

type NeovimInfo struct {
	Path    string `json:"path"`
	Version string `json:"version"`
	// Error is why Neovim can't be used, or "".
	Error string `json:"error"`
}

NeovimInfo is what Settings shows about Neovim.

type NvimEvent

type NvimEvent struct {
	Name string `json:"name"`
	Data string `json:"data"`
}

NvimEvent is something the Neovim buffer reports: its name, such as "cursor" or "run", and its data as JSON.

type NvimText

type NvimText struct {
	Text    string           `json:"text"`
	Version notebook.Version `json:"version"`
	Buffer  string           `json:"buffer"`
	Seq     int              `json:"seq"`
}

NvimText is what NvimStart answers: the file's text and its version, for Edit, and Neovim's text and seq, the count of its changes it sent and edits it took. A Neovim that just started has the file's text, at seq 0; one already running has its own, typing the file doesn't have yet included.

type OutsideFiles

type OutsideFiles struct {
	// Paths are the files, as the document writes them.
	Paths []string `json:"paths"`
	// Root is the folder they are outside: the document's folder,
	// with the home folder as ~.
	Root string `json:"root"`
	// Answer is "allow" or "deny", or "" when this list hasn't been
	// answered: the page asks.
	Answer string `json:"answer"`
}

OutsideFiles are the files a document's includes and out= name outside its folder, or hidden in it, and what the user last said about them.

type Question

type Question struct {
	Title   string
	Message string
	Buttons []Button
}

Question is a question Host.Ask asks.

type ReportStart

type ReportStart struct {
	Ran   int `json:"ran"`   // runnable blocks that ran in this tab
	Total int `json:"total"` // runnable blocks
	// Dest is where a report goes unless another file is picked: beside
	// the document, named after it, without an extension.
	Dest string `json:"dest"`
	Home string `json:"home"` // for showing paths as ~/…
}

ReportStart is what the Report dialog starts with.

type SaveFile

type SaveFile struct {
	Message string
	Button  string // the button that saves, if not the usual one
	Dir     string
	Name    string
	Filter  string // the name of the files Pattern matches
	Pattern string // such as "*.md;*.markdown"
}

SaveFile is what Host.SaveFile asks.

type SourceBlocks

type SourceBlocks struct {
	Blocks  []notebook.SourceBlock `json:"blocks"`
	Version notebook.Version       `json:"version"`
}

SourceBlocks are blocks at a version of the file.

type SourceText

type SourceText struct {
	Text    string           `json:"text"`
	Version notebook.Version `json:"version"`
}

SourceText is the whole file and the version it is at, for a source pane opening on it: later changes come as line events since.

type Start

type Start struct {
	Dir         string               `json:"dir"`
	Home        string               `json:"home"` // for showing paths as ~/…
	Files       []library.File       `json:"files"`
	Collections []library.Collection `json:"collections"`
	Full        bool                 `json:"full"` // more files than listed
	Recent      []string             `json:"recent"`
	// Pinned are the pinned files that still exist, shown above Recent.
	Pinned []string `json:"pinned"`
	// LastSession is the file Last Session opens, or "" if there are no
	// sessions yet.
	LastSession string `json:"lastSession"`
	// Writable are the listed folders, by rel, whose .mdsh.yaml the
	// folder settings can save.
	Writable []string `json:"writable"`
	// Outside are the files, by absolute path, allowed to reach outside
	// their folder or repository, which the list tags.
	Outside []string `json:"outside"`
}

Start is what the start screen lists.

type Tab

type Tab struct {
	ID    int    `json:"id"`
	Title string `json:"title"`
	File  string `json:"file"`
	// URL is the address of a document the app carries inside it, such
	// as the changelog, for a tab that shows one and has no File. A tab
	// dragged out to another app gives it File, or else URL.
	URL   string `json:"url,omitempty"`
	Dirty bool   `json:"dirty"`
	// Page is the page the tab shows, if not a document's.
	Page string `json:"page,omitempty"`
	// ReadOnly is set for a page that can't be edited, such as the
	// changelog.
	ReadOnly bool `json:"readOnly,omitempty"`
}

Tab is a tab as the tab bar draws it.

type Tabs

type Tabs struct {
	Tabs   []Tab `json:"tabs"`
	Active int   `json:"active"`
}

Tabs is what a window's tab bar shows.

type Tool

type Tool struct {
	Name    string `json:"name"`
	Note    string `json:"note"`    // what it's for
	Path    string `json:"path"`    // where it was found, or ""
	Version string `json:"version"` // what --version said, or ""
	// Bundled is set when Path is the mdsh inside the app, which isn't
	// on PATH.
	Bundled bool `json:"bundled"`
}

Tool is a program the notebook uses, and whether it was found on PATH.

type View

type View struct {
	Split    bool `json:"split"`    // the source pane
	Rendered bool `json:"rendered"` // the rendered view
	Outline  bool `json:"outline"`
	Code     bool `json:"code"`
	Output   bool `json:"output"`
	History  bool `json:"history"` // the History pane
	Console  bool `json:"console"` // the Console pane
}

View is what a tab shows, for the View menu's check marks.

type Window

type Window interface {
	ID() uint
	// Emit sends an event to the window's page.
	Emit(name string, data any)
	SetTitle(title string)
	Close()
	Focus()
	// MoveTo puts the window's top left corner at x, y on the screen.
	MoveTo(x, y int)
	// Fit gives the window, which has just opened file in place of the
	// start screen, the size file's window had last, if the host
	// remembers it.
	Fit(file string)
}

Window is one of a Host's windows.

type ZshWrapper

type ZshWrapper struct {
	Path     string `json:"path"`     // the .zshrc
	BashPath string `json:"bashPath"` // the .bashrc, or "" when there is none
	Home     string `json:"home"`     // for showing Path as ~/…
	On       bool   `json:"on"`
}

ZshWrapper is whether the user's .zshrc, and .bashrc if they have one, has the mdsh function that gives blocks the calling shell's aliases and functions, and loads mdsh's completion.

Jump to

Keyboard shortcuts

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