|
1 |
| -use clap::Parser; |
| 1 | +use clap::{Parser, ValueEnum}; |
2 | 2 | use std::io::Write;
|
3 | 3 |
|
4 | 4 | use crate::{builtins, commands, error};
|
5 | 5 |
|
| 6 | +/// Identifier for a keymap |
| 7 | +#[derive(Clone, ValueEnum)] |
| 8 | +enum BindKeyMap { |
| 9 | + #[clap(name = "emacs-standard", alias = "emacs")] |
| 10 | + EmacsStandard, |
| 11 | + #[clap(name = "emacs-meta")] |
| 12 | + EmacsMeta, |
| 13 | + #[clap(name = "emacs-ctlx")] |
| 14 | + EmacsCtlx, |
| 15 | + #[clap(name = "vi-command", aliases = &["vi", "vi-move"])] |
| 16 | + ViCommand, |
| 17 | + #[clap(name = "vi-insert")] |
| 18 | + ViInsert, |
| 19 | +} |
| 20 | + |
6 | 21 | /// Inspect and modify key bindings and other input configuration.
|
7 | 22 | #[derive(Parser)]
|
8 | 23 | pub(crate) struct BindCommand {
|
9 | 24 | /// Name of key map to use.
|
10 | 25 | #[arg(short = 'm')]
|
11 |
| - keymap: Option<String>, |
| 26 | + keymap: Option<BindKeyMap>, |
12 | 27 | /// List functions.
|
13 | 28 | #[arg(short = 'l')]
|
14 | 29 | list_funcs: bool,
|
@@ -48,17 +63,15 @@ pub(crate) struct BindCommand {
|
48 | 63 | /// List key sequence bindings.
|
49 | 64 | #[arg(short = 'X')]
|
50 | 65 | list_key_seq_bindings: bool,
|
| 66 | + /// Key sequence binding to readline function or command. |
| 67 | + key_sequence: Option<String>, |
51 | 68 | }
|
52 | 69 |
|
53 | 70 | impl builtins::Command for BindCommand {
|
54 | 71 | async fn execute(
|
55 | 72 | &self,
|
56 | 73 | context: commands::ExecutionContext<'_>,
|
57 | 74 | ) -> Result<crate::builtins::ExitCode, crate::error::Error> {
|
58 |
| - if self.keymap.is_some() { |
59 |
| - return error::unimp("bind -m is not yet implemented"); |
60 |
| - } |
61 |
| - |
62 | 75 | if self.list_funcs {
|
63 | 76 | return error::unimp("bind -l is not yet implemented");
|
64 | 77 | }
|
@@ -113,6 +126,14 @@ impl builtins::Command for BindCommand {
|
113 | 126 | return error::unimp("bind -X is not yet implemented");
|
114 | 127 | }
|
115 | 128 |
|
| 129 | + if let Some(key_sequence) = &self.key_sequence { |
| 130 | + writeln!( |
| 131 | + context.stderr(), |
| 132 | + "bind: key seq not implemented: {key_sequence}" |
| 133 | + )?; |
| 134 | + return Ok(builtins::ExitCode::Unimplemented); |
| 135 | + } |
| 136 | + |
116 | 137 | Ok(builtins::ExitCode::Success)
|
117 | 138 | }
|
118 | 139 | }
|
0 commit comments