history

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 12 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 history is what a History terminal needs, as mdsh-gui's History pane and mdsh -i have: a terminal where a command typed runs in the document's shell and is added to the end of the document as a block, #history-N, with its output, and a note, lines starting with #, is added as prose.

It asks the shell through an Asker, such as a *run.Session, so what it sees is what blocks left there: the directory, variables and prompts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNote

func AddNote(d *doc.Document, text string, carry bool) error

AddNote adds text to the end of d as prose. With carry, it carries on the paragraph that ends d, as a note added just before does; else it starts a paragraph. It fails, leaving d as it was, if text would change d's blocks, as it would inside a fence left open.

func Background

func Background(input string) (string, bool)

Background reports whether input ends in a lone &, as a command run in the background does, and returns it without the &.

func Info

func Info(lang, id string, background bool) string

Info is the info string a command is added with: lang and id, and background if it was typed with a trailing &.

func Lang

func Lang(shell string) string

Lang is the language commands are added as: zsh if the blocks run in shell zsh, else sh.

func NextID

func NextID(d *doc.Document) string

NextID is the id for the next command in d: one past the highest history-N there. A history block that moved has an id of its own, but its output can still link to a file saved under its old one, so those count too: a new block of that number would write over the file.

func Note

func Note(input string) (string, bool)

Note returns the text of input if it is a note: every line starts with #, which is taken off along with a space after it.

func RCScript

func RCScript(path string) string

RCScript reads the file at path, if there is one, in the shell, as an interactive shell reads its rc file. A leading ~/ is the home folder. What it prints is dropped, along with any errors, since an rc file often does things only an interactive shell can.

func Shell

func Shell(d *doc.Document, override string) string

Shell is the shell blocks of d run in: override if set, else what d asks for, else /bin/sh.

func Whole

func Whole(shell, input string) bool

Whole reports whether input is a whole command, or a note, so pressing enter runs it rather than starting another line. Input ending in \, |, && or ||, or inside a quote, an if, a loop or a here-document, isn't. shell checks what the simple rules don't.

Types

type Asker

type Asker interface {
	Ask(ctx context.Context, script string) (string, error)
}

Asker runs script in the shell blocks run in and returns what it printed. *run.Session is one.

type Completion

type Completion struct {
	Word  string   `json:"word"`
	Items []string `json:"items"`
}

Completion is what Tab offers for the word before the cursor: each of Items replaces Word, the end of what was typed.

func Complete

func Complete(ctx context.Context, a Asker, before string, zsh bool) Completion

Complete completes the word at the end of before, what is typed up to the cursor, asking the shell, so it sees the directory and variables blocks left there: a $ word is a variable, the first word of a command is a command, and any other word, or one with a /, a file. A directory ends in /. Items are quoted for the shell, as they would be typed. zsh says the shell is zsh.

type Prompt

type Prompt struct {
	PS1 string `json:"ps1"`
	PS2 string `json:"ps2"`
}

Prompt is the shell's prompts, PS1 and PS2, expanded as the shell would show them, with their colors as ANSI escapes. Empty means the shell has none.

func AskPrompt

func AskPrompt(ctx context.Context, a Asker, zsh bool) (Prompt, error)

AskPrompt asks the shell for its prompts. zsh says the shell is zsh.

Jump to

Keyboard shortcuts

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