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: the text that the pattern matches shows on a band of color, which stays with it as it scrolls into the scrollback.
- Notify: a notification tells you the line that matched, while Lokyr's window is behind. When Lokyr is behind another app, its icon in the Dock bounces once, and its badge counts the notifications until you come back. While the window is in front, the card at its top right tells it instead.
- Mark: the line gets a mark in the gutter, and ⌘↑ and ⌘↓ stop at it, as they stop at your prompts.
- Run a command: a command of Lokyr's, the ones that the command palette lists, runs with its arguments, as a key bound to it would.
- Each line once: a trigger looks at each line as it ends. A line that a program draws again with the same text is not matched again.
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.
- The command runs only while the pane that matched has the keyboard, in the window in front, so that output in a pane behind never acts on another.
- It runs once a second at most. A command whose effect prints a line that its trigger matches again at once, such as
pane.send-textof a text that your shell echoes, runs once. - A trigger that runs its command 10 times within 10 seconds pauses, and the card at the window's top right tells you why. Save the config file to start it again.
- The pattern's groups never go into the arguments, so that a program's output never chooses what runs.
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.
\dis a digit,\wa letter, a digit or_,\sa space, and\bthe edge of a word.^and$are the line's start and end.(...)is a group, which$1names in a notification's title.- Write patterns between single quotes, as TOML keeps their backslashes as they are:
'error\[E\d+\]'. Between double quotes, each backslash is doubled. - Case counts only where the pattern has a capital letter, as in the find bar:
errormatchesErrorandERROR.case = "sensitive"orcase = "insensitive"chooses otherwise.
Settings
[triggers.<name>]: each trigger, ofpattern,action,case,enabled, and the keys of its action,color,title,commandandargs· Since 1.7.trigger.highlightandtrigger.mark: the theme's colors of a highlight and of a mark · Since 1.7.
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
- A line that a program writes over again within the same moment of output, before it ends it, is matched as it ends: the earlier text is not.
- A program that scrolls only part of the screen, such as one that keeps a status line at the bottom, can push lines out of that part faster than Lokyr looks: in a large burst, those lines are not matched.
- The screen of a full-screen program, such as less, vim or htop, isn't matched: its lines are drawn as the program likes, a page at a time or by moving the cursor. To act on a log's lines, follow it, as with
tail -f, rather than open it in a pager. - A trigger looks at the first 4096 characters of a line. A very long line, of more than some 250,000 characters wrapped over the window, isn't matched when it holds other characters than plain text, such as colors or accented letters, or when the program moved the cursor while it wrote it.
- A command runs only from the pane that has the keyboard: a trigger can't act on a pane behind another.
- Lokyr takes 128 triggers at most. Their patterns are matched together, in one pass over each line: patterns that are each fine but too large together, such as several of
\w{64}, can't all be taken, and the first one past the limit is ignored, as a card tells.
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.