Skip to content

feat: rudimentary readline macro support - #880

Merged
reubeno merged 8 commits into
mainfrom
rudimentary-macros
Dec 30, 2025
Merged

reubeno merged 8 commits into
mainfrom
rudimentary-macros

Conversation

@reubeno

@reubeno reubeno commented Dec 27, 2025 •

Copy link
Copy Markdown
Owner

Very minimal -- just enough for atuin's integration script. Not (yet) enough for fzf's.

image

...

image

@github-actions

github-actions Bot commented Dec 27, 2025 •

Copy link
Copy Markdown

Test Results

    3 files     26 suites   9m 35s ⏱️
1 462 tests 1 462 ✅ 0 💤 0 ❌
4 363 runs  4 363 ✅ 0 💤 0 ❌

Results for commit e7f6fc3.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Dec 27, 2025 •

Copy link
Copy Markdown

Public API changes for crate: brush-core

Removed items

-pub brush_core::error::ErrorKind::UnknownKeyBindingFunction(alloc::string::String)
-pub struct brush_core::interfaces::KeySequence
-pub brush_core::interfaces::KeySequence::strokes: alloc::vec::Vec<brush_core::interfaces::KeyStroke>
-pub brush_core::ErrorKind::UnknownKeyBindingFunction(alloc::string::String)

Added items

+pub brush_core::interfaces::InputFunction::BashViComplete
+pub brush_core::interfaces::InputFunction::ExecuteNamedCommand
+pub brush_core::interfaces::InputFunction::ExportCompletions
+pub brush_core::interfaces::InputFunction::FetchHistory
+pub brush_core::interfaces::InputFunction::SpellCorrectWord
+pub brush_core::interfaces::InputFunction::ViEditAndExecuteCommand
+pub brush_core::interfaces::InputFunction::ViUndo
+pub enum brush_core::interfaces::KeySequence
+pub brush_core::interfaces::KeySequence::Bytes(alloc::vec::Vec<alloc::vec::Vec<u8>>)
+pub brush_core::interfaces::KeySequence::Strokes(alloc::vec::Vec<brush_core::interfaces::KeyStroke>)
+pub fn brush_core::interfaces::KeyBindings::define_macro(&mut self, seq: brush_core::interfaces::KeySequence, target: brush_core::interfaces::KeySequence) -> core::result::Result<(), std::io::error::Error>
+pub fn brush_core::interfaces::KeyBindings::get_macros(&self) -> std::collections::hash::map::HashMap<brush_core::interfaces::KeySequence, brush_core::interfaces::KeySequence>
+pub fn brush_core::interfaces::KeyBindings::get_untranslated(&self, bytes: &[u8]) -> core::option::Option<&brush_core::interfaces::KeyAction>
+pub fn brush_core::interfaces::KeyBindings::try_unbind(&mut self, seq: brush_core::interfaces::KeySequence) -> bool

Public API changes for crate: brush-parser

Removed items

-pub brush_parser::readline_binding::ReadlineTarget::Command(alloc::string::String)

Added items

+pub brush_parser::readline_binding::ReadlineTarget::Macro(alloc::string::String)
+pub fn brush_parser::readline_binding::parse_key_sequence(input: &str) -> core::result::Result<brush_parser::readline_binding::KeySequence, brush_parser::BindingParseError>

Performance Benchmark Report

Benchmark name Baseline (μs) Test/PR (μs) Delta (μs) Delta %
clone_shell_object 17.45 μs 17.87 μs 0.42 μs 🟠 +2.41%
eval_arithmetic 0.15 μs 0.14 μs -0.00 μs ⚪ Unchanged
expand_one_string 1.58 μs 1.57 μs -0.00 μs ⚪ Unchanged
for_loop 22.36 μs 22.64 μs 0.29 μs ⚪ Unchanged
function_call 2.41 μs 2.33 μs -0.08 μs ⚪ Unchanged
instantiate_shell 53.06 μs 54.58 μs 1.52 μs 🟠 +2.87%
instantiate_shell_with_init_scripts 25027.96 μs 26397.43 μs 1369.47 μs 🟠 +5.47%
parse_bash_completion 1995.66 μs 2031.07 μs 35.41 μs 🟠 +1.77%
parse_sample_script 1.90 μs 1.92 μs 0.02 μs ⚪ Unchanged
run_echo_builtin_command 15.54 μs 15.61 μs 0.07 μs ⚪ Unchanged
tokenize_sample_script 3.44 μs 3.45 μs 0.00 μs ⚪ Unchanged

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
brush-builtins/src/bind.rs 🔴 31.25% 🟢 81.76% 🟢 50.51%
brush-core/src/completion.rs 🔴 42.08% 🔴 45.16% 🟢 3.08%
brush-core/src/expansion.rs 🟢 94.44% 🟢 94.42% 🔴 -0.02%
brush-core/src/interfaces/keybindings.rs 🔴 0% 🟢 79.1% 🟢 79.1%
brush-core/src/jobs.rs 🔴 47.25% 🟠 51.38% 🟢 4.13%
brush-core/src/shell.rs 🟢 80.7% 🟢 80.5% 🔴 -0.2%
brush-interactive/src/reedline/edit_mode.rs 🔴 0% 🟠 63.43% 🟢 63.43%
brush-interactive/src/reedline/input_backend.rs 🔴 0% 🟠 66.94% 🟢 66.94%
brush-parser/src/readline_binding.rs 🟠 74.12% 🟢 82.11% 🟢 7.99%
brush-shell/src/entry.rs 🟢 85.39% 🟢 86.52% 🟢 1.13%
Overall Coverage 🟢 72.65% 🟢 74.76% 🟢 2.11%

Minimum allowed coverage is 70%, this run produced 74.76%

Test Summary: bash-completion test suite

Outcome Count Percentage
✅ Pass 1558 73.87
❗️ Error 18 0.85
❌ Fail 179 8.49
⏩ Skip 339 16.07
❎ Expected Fail 13 0.62
✔️ Unexpected Pass 2 0.09
📊 Total 2109 100.00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements rudimentary readline macro support, specifically targeting compatibility with atuin's integration script. The implementation is intentionally minimal, supporting only byte-based macros (uninterpretable key sequences) rather than full stroke-based macro functionality.

Key changes:

  • Renamed ReadlineTarget::Command to ReadlineTarget::Macro to better reflect its purpose
  • Converted KeySequence from a struct with a public strokes field to an enum with Strokes and Bytes variants to support both interpretable and raw key sequences
  • Added new methods to the KeyBindings trait: get_untranslated, try_unbind, and define_macro to support macro functionality

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
brush-parser/src/readline_binding.rs Renames ReadlineTarget::Command to Macro, adds public parse_key_sequence function, and updates key sequence parsing to handle escape bytes as stroke boundaries
brush-core/src/interfaces/keybindings.rs Converts KeySequence from struct to enum (breaking change), adds Clone derives to support macro storage, extends KeyBindings trait with macro-related methods
brush-interactive/src/reedline/edit_mode.rs Implements macro storage and resolution logic, adds raw byte sequence mappings, and provides limited macro binding support (currently only supports byte-based macros with single actions)
brush-builtins/src/bind.rs Updates bind builtin to parse and handle macro bindings, changes key sequence parsing to return enum variants, and routes macro definitions to the new define_macro trait method

Comment thread brush-parser/src/readline_binding.rs Resolved
Comment thread brush-builtins/src/bind.rs Resolved
@reubeno
reubeno marked this pull request as ready for review December 30, 2025 20:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.

Comment thread brush-builtins/src/bind.rs Resolved
Comment thread brush-builtins/src/bind.rs Resolved
Comment thread brush-builtins/src/bind.rs Resolved
@reubeno
reubeno merged commit 8220add into main Dec 30, 2025
43 checks passed
@reubeno
reubeno deleted the rudimentary-macros branch December 30, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants