Skip to content
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

feat(plugins): rebind keys at runtime #3422

Merged
merged 8 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor(server): interpret keys on server so they can be rebound
  • Loading branch information
imsnif committed Jun 10, 2024
commit 5a437b79aac5be0d628b63883f296f46b93779b5
27 changes: 5 additions & 22 deletions zellij-client/src/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ impl InputHandler {
)) => {
self.handle_key(&key_with_modifier, raw_bytes, true);
},
Ok((InputInstruction::SwitchToMode(input_mode), _error_context)) => {
self.mode = input_mode;
},
Ok((
InputInstruction::AnsiStdinInstructions(ansi_stdin_instructions),
_error_context,
Expand Down Expand Up @@ -180,18 +177,10 @@ impl InputHandler {
raw_bytes: Vec<u8>,
is_kitty_keyboard_protocol: bool,
) {
let keybinds = &self.config.keybinds;
for action in keybinds.get_actions_for_key_in_mode_or_default_action(
&self.mode,
key,
raw_bytes,
is_kitty_keyboard_protocol,
) {
let should_exit = self.dispatch_action(action, None);
if should_exit {
self.should_exit = true;
}
}
// we interpret the keys into actions on the server side so that we can change the
// keybinds at runtime
self.os_input
.send_to_server(ClientToServerMsg::Key(key.clone(), raw_bytes, is_kitty_keyboard_protocol));
}
fn handle_stdin_ansi_instruction(&mut self, ansi_stdin_instructions: AnsiStdinInstruction) {
match ansi_stdin_instructions {
Expand Down Expand Up @@ -316,14 +305,8 @@ impl InputHandler {
self.exit(ExitReason::NormalDetached);
should_break = true;
},
Action::SwitchToMode(mode) => {
// this is an optimistic update, we should get a SwitchMode instruction from the
// server later that atomically changes the mode as well
self.mode = mode;
self.os_input
.send_to_server(ClientToServerMsg::Action(action, None, None));
},
Action::CloseFocus
| Action::SwitchToMode(..)
| Action::ClearScreen
| Action::NewPane(..)
| Action::Run(_)
Expand Down
15 changes: 0 additions & 15 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub(crate) enum ClientInstruction {
Render(String),
UnblockInputThread,
Exit(ExitReason),
SwitchToMode(InputMode),
Connected,
ActiveClients(Vec<ClientId>),
StartedParsingStdinQuery,
Expand All @@ -62,9 +61,6 @@ impl From<ServerToClientMsg> for ClientInstruction {
ServerToClientMsg::Exit(e) => ClientInstruction::Exit(e),
ServerToClientMsg::Render(buffer) => ClientInstruction::Render(buffer),
ServerToClientMsg::UnblockInputThread => ClientInstruction::UnblockInputThread,
ServerToClientMsg::SwitchToMode(input_mode) => {
ClientInstruction::SwitchToMode(input_mode)
},
ServerToClientMsg::Connected => ClientInstruction::Connected,
ServerToClientMsg::ActiveClients(clients) => ClientInstruction::ActiveClients(clients),
ServerToClientMsg::Log(log_lines) => ClientInstruction::Log(log_lines),
Expand All @@ -90,7 +86,6 @@ impl From<&ClientInstruction> for ClientContext {
ClientInstruction::Error(_) => ClientContext::Error,
ClientInstruction::Render(_) => ClientContext::Render,
ClientInstruction::UnblockInputThread => ClientContext::UnblockInputThread,
ClientInstruction::SwitchToMode(_) => ClientContext::SwitchToMode,
ClientInstruction::Connected => ClientContext::Connected,
ClientInstruction::ActiveClients(_) => ClientContext::ActiveClients,
ClientInstruction::Log(_) => ClientContext::Log,
Expand Down Expand Up @@ -154,7 +149,6 @@ impl ClientInfo {
pub(crate) enum InputInstruction {
KeyEvent(InputEvent, Vec<u8>),
KeyWithModifierEvent(KeyWithModifier, Vec<u8>),
SwitchToMode(InputMode),
AnsiStdinInstructions(Vec<AnsiStdinInstruction>),
StartedParsing,
DoneParsing,
Expand Down Expand Up @@ -505,11 +499,6 @@ pub fn start_client(
ClientInstruction::UnblockInputThread => {
command_is_executing.unblock_input_thread();
},
ClientInstruction::SwitchToMode(input_mode) => {
send_input_instructions
.send(InputInstruction::SwitchToMode(input_mode))
.unwrap();
},
ClientInstruction::Log(lines_to_log) => {
for line in lines_to_log {
log::info!("{line}");
Expand Down Expand Up @@ -634,7 +623,3 @@ pub fn start_server_detached(
os_input.connect_to_server(&*ipc_pipe);
os_input.send_to_server(first_msg);
}

#[cfg(test)]
#[path = "./unit/stdin_tests.rs"]
mod stdin_tests;

This file was deleted.

This file was deleted.

Loading