Lokyr
Documentation

Triggers

On this page

macOS · [triggers.<name>] · Since 1.7

A trigger is a pattern that Lokyr looks for in each line of your programs' output, and what it does when it finds it: highlight the text, tell you in a notification, mark the line, or run a command. A build's errors stand out as they scroll by, and a long job tells you when it is done while you work in another app.

Try it

Add this to your config file, and save it:

[triggers.errors]
pattern = 'error(\[E\d+\])?:'
action = "highlight"

Then run this command:

printf 'compiling\nerror[E0308]: mismatched types\ndone\n'

error[E0308]: shows on a yellow band. The trigger applies at once, with no restart, to every pane.

What it gives you

Highlight a pattern

[triggers.failures]
pattern = '\bFAILED\b'
action = "highlight"
color = "red"            # a theme's color, or "#rrggbb"

By default, a highlight takes your theme's trigger.highlight color, a translucent yellow, which follows the light and the dark appearance. color takes another of the theme's tokens, such as "accent" or "red", or a color of your own, such as "#ff8800".

Get a notification

[triggers.built]
pattern = '^\s*Finished .* in (\S+)'
action = "notify"
title = "Built in $1"

The notification's text is the line that matched. Its title is the trigger's name, or title, where $1 to $9 stand for the pattern's groups. A trigger notifies once a second at most.

Mark a line

[triggers.panics]
pattern = 'panicked at'
action = "mark"

The mark takes your theme's trigger.mark color. While Blocks is on, ⌘↑ and ⌘↓ select blocks instead, and stop at no mark.

Run a command

[triggers.clear]
pattern = '^clear me$'
action = "command"
command = "pane.clear"

command is a command's name, and args its arguments, as a key's binding takes them, such as args = { text = "y\r" } for pane.send-text.

Edit triggers in the settings window

Open the settings window, ⌘,, and choose Triggers in the Settings page's sidebar. Each trigger has a row: its name, its pattern, its action and the action's keys. You can add, rename, change and remove triggers there. A trigger that is wrong, such as one whose pattern doesn't compile, is refused, and the page tells you why.

The page writes each trigger as a table of its own, [triggers.<name>], and keeps the file's comments. A command's args you write in the file: the page keeps them.

The patterns

A pattern is a regular expression of Rust's regex syntax, the find bar's.

Settings

How it works

A line ends as the program moves the cursor on to the next one, with a line feed. As each line ends, Lokyr matches it against every trigger at once, in one pass, and most lines match none.

For lines that stream at the bottom of the screen, as a build's or cat's do, Lokyr keeps the line's text as it prints it, and matches it on a thread of its own, so that reading the program's output never waits for the matching. Other lines, such as one that a program drew with the cursor moved, Lokyr reads from the screen's cells as they end.

Without triggers, Lokyr keeps no line's text and starts no thread: triggers cost nothing until you add one.

What triggers cost

Printing 1 GiB of text with cat, of no trigger, of one and of ten, the patterns of a build's errors, warnings, URLs and the like, Lokyr printed 307.0, 306.4 and 309.2 MiB a second: the same, within the measure's noise. The measurement tells more.

Limits

Troubleshooting

A trigger matches nothing

Why: the trigger is wrong and ignored, or its pattern doesn't match what the program prints.

Fix: look for the card "A trigger is ignored" at the window's top right, which tells the trigger's line in the file and why, or run lokyr +validate-config. Try the pattern in the find bar, with its regex option on: what the find bar finds, the trigger matches.

Check: print a line that the pattern matches with printf, as in Try it.

A command trigger doesn't run

Why: its pane doesn't have the keyboard, or the trigger paused after it ran its command too often.

Fix: click the pane first. If the card says that the trigger is paused, save the config file to start it again.