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 ¶
- func AddBlock(d *doc.Document, info, body string) (*doc.Block, error)
- func AddNote(d *doc.Document, text string, carry bool) error
- func Background(input string) (string, bool)
- func Block(input string) (info, body string, ok bool)
- func BlockPrompt(info string) string
- func InBlock(input string) (info string, ok bool)
- func Info(lang, id string, background bool) string
- func KeepRuns(d *doc.Document, b *doc.Block) error
- func Lang(shell string) string
- func NextID(d *doc.Document) string
- func Note(input string) (string, bool)
- func OpenBlock(line string) (fence, info string, ok bool)
- func RCScript(path string) string
- func Reuse(d *doc.Document, lang, body string, bg bool) *doc.Block
- func Shell(d *doc.Document, override string) string
- func Tilde(dir string) string
- func Whole(shell, input string) bool
- type Asker
- type Completion
- type Prompt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddBlock ¶ added in v1.7.0
AddBlock adds a block typed in the terminal, with info and body, to the end of d, as it was typed. It fails, leaving d as it was, for a block with no body or one d can't take.
func AddNote ¶
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 ¶
Background reports whether input ends in a lone &, as a command run in the background does, and returns it without the &.
func Block ¶ added in v1.7.0
Block returns the info string and body of input if it is a whole block typed in the terminal: an opening line, its body, and a closing fence.
func BlockPrompt ¶ added in v1.7.0
BlockPrompt is the prompt on the lines of a block being typed, in place of PS2, so it is plain the lines are kept, not run: the opening fence and the block's language, as "```bash> ".
func InBlock ¶ added in v1.7.0
InBlock reports whether input opens a block and doesn't close it yet, so enter starts another line of it. It returns the info string the block opened with.
func Info ¶
Info is the info string a command is added with: lang and id; skip, so running the whole file doesn't run it again, though it still runs by hand; links, so the web addresses it prints are clickable; and background if it was typed with a trailing &.
func KeepRuns ¶ added in v1.7.0
KeepRuns adds history to b's attributes, unless it has history= already, so that running it again keeps the output it has as an earlier run, as many as the front matter's history: says, else 10.
func Lang ¶
Lang is the language commands are added as: zsh if the blocks run in shell zsh, else sh.
func NextID ¶
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 ¶
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 OpenBlock ¶ added in v1.7.0
OpenBlock returns the fence and info string of line if it opens a block typed in the terminal.
func RCScript ¶
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 Reuse ¶ added in v1.7.0
Reuse is the #history-N block in d that a command, body typed in lang, repeats: the last whose language and code are body's, and that runs in the background only if bg says the command does. It is nil for a command not typed before. With History's reuse setting on, the command runs that block again rather than adding another.
func Shell ¶
Shell is the shell blocks of d run in: override if set, else what d asks for, else /bin/sh.
func Whole ¶
Whole reports whether input is a whole command, a note or a block, so pressing enter runs or adds it rather than starting another line. Input ending in \, |, && or ||, inside a quote, an if, a loop or a here-document, or inside a block it opens, isn't. shell checks what the simple rules don't.
Types ¶
type Asker ¶
Asker runs script in the shell blocks run in and returns what it printed. *run.Session is one.
type Completion ¶
Completion is what Tab offers for the word before the cursor: each of Items replaces Word, the end of what was typed.
func Complete ¶
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"`
// Dir is the shell's working directory, with the home folder as ~,
// shown on the pane's separator.
Dir string `json:"dir"`
}
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 ParsePrompt ¶ added in v1.7.0
ParsePrompt reads what a prompt script printed: PS1, then PS2 and the working directory, each after its mark. bash's \[ and \], which mark where escapes start and end, are taken out.