Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Commit aaffd5e

Browse files
committed
Add documents for key binding customization
1 parent 8248b85 commit aaffd5e

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

website/docs/guides/configurations.md

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Here are some supported configurations:
2020
| `filter_included` | Filter included pattern. See [filter page](/docs/guides/filter) for more information | `[]` | |
2121
| `filter_excluded` | Filter excluded pattern. See [filter page](/docs/guides/filter) for more information | `[]` | |
2222
| `alias_to_debugger` | Use `debugger` instead of `jard` when debugging. | `false` | `true`, `false`|
23+
| `key_bindings` | Key binding customization. See [key bindings page](/docs/guides/key-bindings) for more information | | |
2324

2425
This is a complete example of a configuration file:
2526

@@ -31,4 +32,10 @@ config.enabled_screens = ['backtrace', 'source']
3132
config.filter = :gems
3233
config.filter_included = ['active*', 'sidekiq']
3334
config.filter_excluded = ['acts-as-taggable-on']
35+
config.key_bindings = {
36+
RubyJard::Keys::CTRL_N => 'next',
37+
RubyJard::Keys::CTRL_U => 'up',
38+
RubyJard::Keys::CTRL_D => 'down',
39+
RubyJard::Keys::META_S => 'step'
40+
}
3441
```

website/docs/guides/key_bindings.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ id: Key bindings
33
slug: key-bindings
44
---
55

6+
import {LinkedImage} from '../../src/components/LinkedImage'
7+
68
| Key Binding | Meaning | Equivalent command |
79
| ----------- | ------- | ------------------ |
810
| F2 | Switch [filter](/docs/guides/filter) mode | [filter](/docs/commands/filter) |
@@ -14,4 +16,50 @@ slug: key-bindings
1416
| F8 | Move to the next line | [next](/docs/commands/next) |
1517
| F9, Ctrl+D | Continue the execution of your program until exit, or stop at the next break point | [continue](/docs/commands/continue) |
1618

17-
**Note**: Key binding customization is coming in a future version.
19+
You can always customize the key bindings set by putting a simple setting in the [configuration file](/docs/guides/configurations). The list of natively supported key binding is defined in [this file](https://github.com/nguyenquangminh0711/ruby_jard/blob/master/lib/ruby_jard/keys.rb).
20+
21+
```ruby
22+
config.key_bindings = {
23+
RubyJard::Keys::CTRL_N => 'jard filter switch',
24+
RubyJard::Keys::META_L => 'list',
25+
RubyJard::Keys::CTRL_F1 => 'up',
26+
RubyJard::Keys::CTRL_SHIFT_F1 => 'down',
27+
RubyJard::Keys::META_D => 'step',
28+
RubyJard::Keys::META_O => 'step-out',
29+
RubyJard::Keys::CTRL_META_N => 'next',
30+
RubyJard::Keys::META_F1 => 'continue',
31+
RubyJard::Keys::META_SHIFT_F1 => 'continue',
32+
RubyJard::Keys::CTRL_C => 'interrupt'
33+
}
34+
```
35+
36+
Jard also supports non-traditional and machine-dependent key bindings. For example, to map the `Ctrl+Home` key combination to the `next` command, you first need to get the code sequences of this combination. Let's run the following ruby program inside your terminal, press `Ctrl+Home`, copy the output, then put it into the configuration file.
37+
38+
```ruby
39+
require 'io/console'
40+
41+
STDOUT.raw!
42+
begin
43+
loop do
44+
begin
45+
data = STDIN.read_nonblock(255)
46+
exit if data == "\u0003"
47+
print data.inspect
48+
rescue IO::WaitReadable; sleep 0.1; end
49+
end
50+
ensure
51+
STDOUT.cooked!
52+
end
53+
```
54+
55+
<LinkedImage link="/img/guides/key-bindings.png" alt="Capture raw key sequences"/>
56+
57+
In my machine, the above program prints `"\e[1;5H"`. My configuration to map `Ctrl+Home` to `next` command looks like this:
58+
59+
```ruby
60+
config.key_bindings = {
61+
"\e[1;5H" => 'next'
62+
}
63+
```
64+
65+
If the above program doesn't print any output, it means the key combination is conflicted or already handled by some programs in your environment. Please pick another one.
8.14 KB
Loading

0 commit comments

Comments
 (0)