-
Notifications
You must be signed in to change notification settings - Fork 0
Add introspection utilities for Reline keybindings and IRB command to… #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,90 @@ | ||||||||||||||||||||||||||
| # frozen_string_literal: true | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| module RelinePac | ||||||||||||||||||||||||||
| # Introspection provides utilities to inspect and debug Reline keybindings. | ||||||||||||||||||||||||||
| module Introspection | ||||||||||||||||||||||||||
| class << self | ||||||||||||||||||||||||||
| # Display all current keybindings in a human-readable format. | ||||||||||||||||||||||||||
| def keymap | ||||||||||||||||||||||||||
| config = Reline.core.config | ||||||||||||||||||||||||||
| bindings = {} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| config.keymap.instance_variable_get(:@key_bindings).each do |key, method| | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| config.keymap.instance_variable_get(:@key_bindings).each do |key, method| | |
| keymap = config.keymap | |
| key_bindings = | |
| if keymap.respond_to?(:key_bindings) | |
| keymap.key_bindings | |
| elsif keymap.instance_variable_defined?(:@key_bindings) | |
| keymap.instance_variable_get(:@key_bindings) | |
| else | |
| {} | |
| end | |
| key_bindings.each do |key, method| |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rubocop:disable comments for Lint/DuplicateBranch on lines 42 and 43 are suppressing legitimate warnings. These case branches do have duplicate 'Home' and 'End' return values. The duplicate branches could be combined (e.g., when "\e[F", "\eOF", "\e[4~", "\e[8~" then 'End') to eliminate the need for these suppressions and improve maintainability.
| when "\e[F", "\eOF" then 'End' | |
| when "\e[H", "\eOH" then 'Home' | |
| when "\e[1~", "\e[7~" then 'Home' # rubocop:disable Lint/DuplicateBranch | |
| when "\e[4~", "\e[8~" then 'End' # rubocop:disable Lint/DuplicateBranch | |
| when "\e[F", "\eOF", "\e[4~", "\e[8~" then 'End' | |
| when "\e[H", "\eOH", "\e[1~", "\e[7~" then 'Home' |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 78 contains Japanese text ('Control キー' meaning 'Control key'). For consistency with the rest of the codebase where English is used, this comment should be written in English.
| when 0..31 # Control キー | |
| when 0..31 # Control key |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||
| # frozen_string_literal: true | ||||||
|
|
||||||
| require 'irb' | ||||||
|
|
||||||
| module RelinePac | ||||||
| module IrbCommands | ||||||
| # IRB command to display Reline keybindings | ||||||
| class Keybinds < ::IRB::Command::Base | ||||||
| category 'Context' | ||||||
| description 'Show Reline keybindings' | ||||||
|
|
||||||
| def execute(_arg) | ||||||
| bindings = RelinePac::Introspection.keymap | ||||||
| max_key_length = bindings.keys.map(&:length).max | ||||||
|
||||||
| max_key_length = bindings.keys.map(&:length).max | |
| max_key_length = bindings.keys.map(&:length).max || 0 |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases don't cover the IrbCommands::Keybinds class, which means the execute method and command registration logic lacks test coverage. Since other modules in the repo have corresponding test files, this command should also have tests.
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 24 is in Japanese while all other code and comments in the file are in English. For consistency and to ensure all team members can understand the codebase, comments should be written in English.
| # IRB が読み込まれている場合のみ登録 | |
| # Register only if IRB has been loaded |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||||||||||||||||||||
| # frozen_string_literal: true | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| require 'spec_helper' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| RSpec.describe RelinePac::Introspection do | ||||||||||||||||||||||||
| describe '.keymap' do | ||||||||||||||||||||||||
| it 'returns a hash without errors' do | ||||||||||||||||||||||||
| expect { described_class.keymap }.not_to raise_error | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it 'returns a hash of keybindings' do | ||||||||||||||||||||||||
| result = described_class.keymap | ||||||||||||||||||||||||
| expect(result).to be_a(Hash) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it 'filters out ed_insert and ed_digit bindings' do | ||||||||||||||||||||||||
| result = described_class.keymap | ||||||||||||||||||||||||
| expect(result.values).not_to include(:ed_insert) | ||||||||||||||||||||||||
| expect(result.values).not_to include(:ed_digit) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it 'includes known keybindings' do | ||||||||||||||||||||||||
| result = described_class.keymap | ||||||||||||||||||||||||
| # Control-A should map to ed_move_to_beg | ||||||||||||||||||||||||
| expect(result).to include('⌃A' => :ed_move_to_beg) | ||||||||||||||||||||||||
|
Comment on lines
+22
to
+25
|
||||||||||||||||||||||||
| it 'includes known keybindings' do | |
| result = described_class.keymap | |
| # Control-A should map to ed_move_to_beg | |
| expect(result).to include('⌃A' => :ed_move_to_beg) | |
| it 'includes and formats movement keybindings when present' do | |
| result = described_class.keymap | |
| # If ed_move_to_beg is present, its key should be formatted as a Control key | |
| key_for_move_to_beg = result.key(:ed_move_to_beg) | |
| if key_for_move_to_beg | |
| expect(key_for_move_to_beg).to include('⌃') | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional require 'require_relative 'reline_pac/irb_commands' if defined?(IRB)' may not work as intended in all scenarios. The file itself requires 'irb' at the top (line 3 of irb_commands.rb), which means if IRB is not available when this line executes, it will raise a LoadError. The conditional should either wrap the require statement in the irb_commands.rb file or use a rescue block here to handle cases where IRB is not installed.