Lokyr
Documentation

Blocks

On this page

macOS · zsh, bash, fish · off by default · the lokyr/blocks plugin · [plugins.blocks] · Since 1.4

Lokyr sees each command that your shell runs as a block: its prompt, the command line you typed, and the output that the command printed. Blocks is off until you turn it on. When you scroll up through a long output, the block's prompt and command line stay at the top of the pane, so that you always know what you are reading. One click takes you back to the start of the block.

Try it

Turn Blocks on, with the Enabled switch of its section on the Settings page, in your config file, or on the Plugins page, as Turn blocks on shows. Then run this command:

seq 1 500

Scroll up into the numbers. The prompt and seq 1 500 stay at the top of the pane, with a thin line under them, over the numbers that scroll. Click them: the view moves up to the command's prompt, and the pinned rows go.

What it gives you

Copy a command or its output

Right-click anywhere in a block, on its prompt, its command line or its output, open Block, and choose:

The Block submenu holds every action on the block, its details and Run Command Again too, so that the context menu stays short. While Blocks is off, Copy Command Output and Select Command Output show in the context menu itself.

From the block's header

Right-click the prompt rows pinned at the top of the pane, or the pill with header = "pill", or ⌃-click them, for a menu of the same actions on that block alone. A click on them still takes you to the block's prompt. Block Details opens its panel at the top of the pane.

The same commands are in the Edit menu and the command palette, where they act on the last command: Copy Command takes the last command that started, even one that still runs, and the other two the last command that ended. A command that still runs has no output to copy yet, so Copy Command and Output and Select Block are dimmed in its block.

A block whose prompt has left the scrollback still copies and selects the rows that the pane holds.

See a block's details

Right-click anywhere in a block and choose Block › Block Details. A panel opens below the pointer with:

Click a line, or its copy button, to copy what it shows: the button turns into a tick. For the status, the copy is the exit status alone. Press Escape, or click outside the panel, to close it. Tab moves between the copy buttons, and Space copies.

Edit › Block Details, with no click, shows the last command that started, below the cursor. While the command runs, the panel says Running, and it shows the status and the duration as soon as the command ends.

Run a command again

Right-click a block and choose Block › Run Command Again. Lokyr types the block's command line at your shell's prompt and presses Return for you.

It runs only while your shell waits at its prompt with an empty command line. Otherwise Lokyr sends nothing, and a notice tells you why:

The command line goes in as a paste, so a command of several lines stays whole, and Lokyr doesn't ask you to confirm it, as it can for a paste of several lines. Edit › Run Command Again, with no click, runs the last command that started.

Select a block

Click a block to select it: its rows are tinted, across the pane. A click at the prompt where you type, or below the last block, selects none, and so does a click in a command that still runs, such as a remote shell or a REPL, which keeps its keys: while a running command's block is selected, ↑, ↓ and Escape go to the command.

Press ⌘↑ to select the last block from the keyboard. Press ↑ and ↓ to select the block before or after: the view follows, with the selected block's prompt at the top. Below the last block, ↓ selects none and takes you back to the prompt where you type.

When you have scrolled up, ⌘↑ and ⌘↓ jump to the prompt above or below the top of the view, as they do without Blocks, and select its block.

While a block is selected:

The tint is your theme's blocks.selected.bg, a shade of the accent by default.

Dividers and the gutter's bar

While Blocks runs, a thin line divides each block from the one before, at the top of its prompt, across the pane. The prompt where you type has one too, so the last command's output stays apart from what you type.

The gutter's bar of each command runs along its whole block, from its prompt to the end of its output: gray when the command succeeded, red when it failed, and in the accent color while it runs, as long as the output grows.

A failed block shows its red bar alone. To tint its rows too, in a faint red, turn on failed-tint:

[plugins.blocks]
dividers = true       # the line between the blocks
failed-tint = true    # a failed block's rows tinted

The colors are your theme's: blocks.divider for the line, blocks.failed for a failed block, blocks.selected.bg for the selected one, and the gutter's colors for the bars. The Theme Editor shows them in its terminal's preview.

Room between the blocks

To put a blank row between the blocks, turn on spacing:

[plugins.blocks]
spacing = true    # a blank row before each prompt that follows a command

From the next prompt, a blank row comes before each prompt that follows a command, and the line between the blocks runs through its middle. A selected block's tint, and a failed block's, reach the line, so the two blocks meet there.

Lokyr puts the blank row there itself, as your shell starts its prompt, so your shell's config needs nothing, and it works in any shell that marks its prompts with OSC 133. No blank row comes before the first prompt, after you press Return on an empty command line, or at the top of the pane after clear.

Change the header's look

By default, the header is the block's own prompt rows, in your terminal's colors, with the theme's blocks.divider line under them. To show the command line in a pill instead:

[plugins.blocks]
header = "pill"        # rows | pill

The pill's colors are tokens of your theme, so they follow the light and the dark appearance. Its keys in [plugins.blocks] name the tokens, and set the text's size and weight, the room around the text, and where the pill sits:

[plugins.blocks]
header = "pill"
border = "accent"      # the theme's accent color around the pill
font-weight = "semibold"
align = "center"       # left | center | right
max-length = 60        # characters of the command line before the ellipsis

The changes apply as you save the file, to a header that shows too.

Tip

If you changed the command header's look before Blocks came, move its keys from [plugins.command-header] to [plugins.blocks]: the command header's keys apply only while Blocks is off.

Keep the header while a command runs

While a command runs and you are at the bottom of the pane, its prompt rows stay pinned as its output scrolls, such as a build's, and go when the program draws at the top of the screen or reads your keys, such as a pager. To choose otherwise:

[plugins.blocks]
header-while-running = "always"    # auto | always | never

It applies as you save the file · Since 1.7.

Turn blocks on

Blocks is off by default, and Lokyr shows the plain command header in its place: the same pill, without the arrow, whose keys are in [plugins.command-header]. To turn Blocks on:

[plugins.blocks]
enabled = true

You can also turn on the Enabled switch at the top of the Blocks section of the settings window's Settings page, or click Enable next to Blocks on its Plugins page: both write the same key. While Blocks is off, its settings on the Settings page are dimmed, and apply once you turn it on. Remove the key, turn the switch off, or click Disable, to turn Blocks off again: the command header comes back.

Settings

On the settings window's Settings page, the pill's keys are dimmed while header is rows, and header-while-running while it is pill, each with a note of the value that it applies with · Since 1.7.

Commands and keys

CommandMenuDefault keysWhat it does
blocks.copy-commandEdit › Copy CommandCopies the command line of the block under the pointer, from the pane's context menu, or of the last command that started
blocks.copy-blockEdit › Copy Command and OutputCopies the command line and the output of the block under the pointer, or of the last command that ended, its wrapped rows joined, 100 000 rows at most
blocks.select-blockEdit › Select BlockSelects that block, from its prompt to the end of its output
blocks.select-previousView › Select Previous Block⌘↑, and ↑ while a block is selectedSelects the block before the selected one, or the last block, or, of a view scrolled up, the block of the prompt above its top
blocks.select-nextView › Select Next Block⌘↓, and ↓ while a block is selectedSelects the block after the selected one, or none past the last, or, of a view scrolled up, the block of the prompt below its top
blocks.deselectView › Deselect BlockEscape, while a block is selectedSelects no block
blocks.rerunEdit › Run Command AgainRuns the command line of the block under the pointer, or of the last command that started, at the shell's prompt, while its command line is empty
blocks.detailsEdit › Block DetailsShows the details of the block under the pointer, or of the last command that started: its command line, exit status, start, duration and folder, each copied by a click

The commands of the Edit menu have no default keys: bind them in [keys], such as "cmd+alt+shift+b" = "blocks.copy-block". They act on the selected block when you run them with no click. ⌘↑ and ⌘↓ jump between the prompts again while Blocks is off.

How it works

Your shell marks each command with OSC 133, the shell integration's sequences: where the prompt starts, where the command line starts, where the output starts, and where the command ended. Lokyr keeps the marks with the rows of the scrollback, and the Blocks plugin reads them as the view moves.

Lokyr draws the dividers, the bars and the tints from the same marks, for the blocks that the pane shows: they cost nothing for the commands kept in the scrollback. It pins the prompt rows of the block at the pane's top from the same marks too, copying them again only when another block reaches the top.

With spacing, the blank row comes when your shell marks the start of its prompt after a command that ended: Lokyr moves the cursor down a row, so that the prompt starts a row lower than where the shell began to draw it. Shells draw their prompts from where the cursor is, and move within them from there, so they draw the command line and redraw the prompt in the right place. The blank row is part of no block.

When a command's output starts, Lokyr notes the time and the folder that your shell reported last with OSC 7, which the shell integration sends before each prompt. When the command ends, Lokyr notes the time again. The duration is the time between the two, by the Mac's clock.

The header lies over the pane's first row, and takes none of the grid's rows, so the program's grid keeps its size as the header comes and goes. A scroll over the header scrolls the pane, and the header takes no keys.

Blocks replaces the command header: while Blocks runs, the command header is off, and it comes back when you turn Blocks off. Keys that you left in [plugins.command-header] apply only then. While Blocks runs, the settings window shows a note above them, naming Blocks.

Limits

Troubleshooting

The header never shows

Why: your shell doesn't mark its commands. Shell integration is off, or the shell is one that Lokyr doesn't set up.

Fix: turn shell integration on, or set it up by hand, as shell integration explains.

Check: run seq 1 500 and scroll up. The header with seq 1 500 appears at the pane's top.

Block Details shows no folder

Why: your shell doesn't report its folder with OSC 7, which Lokyr's shell integration does for zsh, bash and fish.

Fix: turn shell integration on, or set it up by hand, as shell integration explains.

Check: run ls, then right-click its output and choose Block › Block Details. The Folder line shows the folder where you ran it.

The arrow isn't there

Why: the arrow belongs to the pill, which shows only with header = "pill"; by default the header is the prompt's pinned rows, which have none. With the pill, the arrow shows only while the end of the block is below the view: when the output's last row is on the pane, you are already at the block's end.

Fix: set header = "pill" in [plugins.blocks], or scroll up further into the output, and the arrow comes back.

See also