One command a client ran in a terminal_image, as its OSC
133 semantic prompt marks describe it: the prompt (A),
the line the user edited (B), the output of running it (C)
and the end of that output (D, or the prompt after it). The
terminal builds them as the marks arrive and keeps them in terminal_block<-blocks,
oldest first. Subclass of object.
A block is what lets the window be addressed by what it was used for
rather than by row and column: terminal_block<-content
hands over the command or its output as a string, terminal_block->select
and terminal_block->copy
put either on the clipboard,
terminal_block->scroll_to
brings it back into view and terminal_block->fold
takes its output off the display.
A command can take more than one line to type. The client asks for
each of them separately -- a Prolog term is read a line at a time until
its full stop -- and marks all but the first with A;k=s,
the secondary prompt. Those lines are one command and one block,
anchored to the line it started on.
The commandline editor of SWI-Prolog emits the marks by default; see
el_set/2 prompt_marks(Boolean)
in library(editline). A client that marks nothing produces
no blocks.
terminal_block->remove
is the one thing that changes the buffer rather than reading it:
everything else here only says what is already there.
A block outlives the marks it was made from but not the text it
points at. Its positions are lines of the scrollback, so a line pushed
out of the buffer takes with it the marks that named it, and a block
with nothing left is dropped from terminal_block<-blocks
with its terminal_block<-terminal
set to
@nil. A block
still held elsewhere is then harmless: every method that needs text
fails.
terminal_block<-prompt, terminal_block<-input, terminal_block<-output
and terminal_block<-end
report positions in the flat character space of the terminal, which
composes with terminal_block<-contents,
terminal_block<-find, terminal_block->selection
and terminal_block->scroll_to
-- but see Character indices in the documentation of class terminal_image:
those indices shift as output pushes lines out of the scrollback. terminal_block<-id
is the handle that outlives them.
<-block..e.
C was seen and D was not.
command is
the line the user entered, output (the default) what it
printed, and all both with the prompt in front.<-content
rather than by the region of the screen the block covers, so a copy of
the command is what was typed: without the return that
entered it, and without the continuation prompts the client drew down
the left of a command it collected over several lines. all
keeps them, being what the window shows. Lines are separated by a single
newline, as terminal_block<-content
separates them, and not by the \r\n of
terminal_image<-selected:
what is copied here is a command to be read back, not a region of the
screen. Does not disturb the selection; terminal_block->select
is for that.<-blocks
with its terminal_block<-terminal
set to @nil.
There is no undo.
The buffer gets shorter at the end the client is writing to, so the older history is left where it is. Everything that names a line by its place in the scrollback is moved with the text: the caret, the window and the marks of every other command. The selection and a running incremental search are ended rather than followed, since what they were on may be what is going.
Fails for a command still running, for one whose output has not been marked as ended, and while an application holds the alternate screen.
->folded.
what as for terminal_block->select.
Lines are separated by a single newline, as terminal_block<-contents
does. A part that has not been reached yet -- the output of a command
still running -- reaches to where the client is writing.
command is what was typed: it stops short of the return
that entered it, and passes over the continuation prompt in front of
each line of a command the client collected over several. all
keeps both, being the text of the window.