mirror of
https://github.com/zellij-org/zellij.git
synced 2024-11-22 13:02:12 +03:00
fix(plugins): remove protobuf duplications (#2729)
* fix(plugins): remove protobuf duplications * style(fmt): rustfmt
This commit is contained in:
parent
07433eb6dc
commit
90e93d64bd
@ -460,7 +460,7 @@ fn switch_tab_to(env: &ForeignFunctionEnv, tab_idx: u32) {
|
||||
.non_fatal();
|
||||
}
|
||||
|
||||
fn set_timeout(env: &ForeignFunctionEnv, secs: f32) {
|
||||
fn set_timeout(env: &ForeignFunctionEnv, secs: f64) {
|
||||
// There is a fancy, high-performance way to do this with zero additional threads:
|
||||
// If the plugin thread keeps a BinaryHeap of timer structs, it can manage multiple and easily `.peek()` at the
|
||||
// next time to trigger in O(1) time. Once the wake-up time is known, the `wasm` thread can use `recv_timeout()`
|
||||
@ -477,7 +477,7 @@ fn set_timeout(env: &ForeignFunctionEnv, secs: f32) {
|
||||
// TODO: we should really use an async task for this
|
||||
thread::spawn(move || {
|
||||
let start_time = Instant::now();
|
||||
thread::sleep(Duration::from_secs_f32(secs));
|
||||
thread::sleep(Duration::from_secs_f64(secs));
|
||||
// FIXME: The way that elapsed time is being calculated here is not exact; it doesn't take into account the
|
||||
// time it takes an event to actually reach the plugin after it's sent to the `wasm` thread.
|
||||
let elapsed_time = Instant::now().duration_since(start_time).as_secs_f64();
|
||||
|
@ -133,7 +133,7 @@ pub fn switch_tab_to(tab_idx: u32) {
|
||||
|
||||
/// Set a timeout in seconds (or fractions thereof) after which the plugins [update](./plugin-api-events#update) method will be called with the [`Timer`](./plugin-api-events.md#timer) event.
|
||||
pub fn set_timeout(secs: f64) {
|
||||
let plugin_command = PluginCommand::SetTimeout(secs as f32);
|
||||
let plugin_command = PluginCommand::SetTimeout(secs);
|
||||
let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
|
||||
object_to_stdout(&protobuf_plugin_command.encode_to_vec());
|
||||
unsafe { host_run_plugin_command() };
|
||||
|
@ -1005,7 +1005,7 @@ pub enum PluginCommand {
|
||||
OpenCommandPane(CommandToRun),
|
||||
OpenCommandPaneFloating(CommandToRun),
|
||||
SwitchTabTo(u32), // tab index
|
||||
SetTimeout(f32), // seconds
|
||||
SetTimeout(f64), // seconds
|
||||
ExecCmd(Vec<String>),
|
||||
PostMessageTo(PluginMessage),
|
||||
PostMessageToPlugin(PluginMessage),
|
||||
|
@ -61,7 +61,7 @@ message IdAndName {
|
||||
|
||||
message PaneIdAndShouldFloat {
|
||||
uint32 pane_id = 1;
|
||||
bool should_float_if_hidden = 2;
|
||||
bool should_float = 2;
|
||||
}
|
||||
|
||||
message NewPluginPanePayload {
|
||||
|
@ -562,7 +562,7 @@ impl TryFrom<ProtobufAction> for Action {
|
||||
match protobuf_action.optional_payload {
|
||||
Some(OptionalPayload::FocusTerminalPaneWithIdPayload(payload)) => {
|
||||
let terminal_pane_id = payload.pane_id;
|
||||
let should_float_if_hidden = payload.should_float_if_hidden;
|
||||
let should_float_if_hidden = payload.should_float;
|
||||
Ok(Action::FocusTerminalPaneWithId(
|
||||
terminal_pane_id,
|
||||
should_float_if_hidden,
|
||||
@ -575,7 +575,7 @@ impl TryFrom<ProtobufAction> for Action {
|
||||
match protobuf_action.optional_payload {
|
||||
Some(OptionalPayload::FocusPluginPaneWithIdPayload(payload)) => {
|
||||
let plugin_pane_id = payload.pane_id;
|
||||
let should_float_if_hidden = payload.should_float_if_hidden;
|
||||
let should_float_if_hidden = payload.should_float;
|
||||
Ok(Action::FocusPluginPaneWithId(
|
||||
plugin_pane_id,
|
||||
should_float_if_hidden,
|
||||
@ -1098,7 +1098,7 @@ impl TryFrom<Action> for ProtobufAction {
|
||||
optional_payload: Some(OptionalPayload::FocusTerminalPaneWithIdPayload(
|
||||
PaneIdAndShouldFloat {
|
||||
pane_id: terminal_pane_id,
|
||||
should_float_if_hidden,
|
||||
should_float: should_float_if_hidden,
|
||||
},
|
||||
)),
|
||||
})
|
||||
@ -1109,7 +1109,7 @@ impl TryFrom<Action> for ProtobufAction {
|
||||
optional_payload: Some(OptionalPayload::FocusPluginPaneWithIdPayload(
|
||||
PaneIdAndShouldFloat {
|
||||
pane_id: plugin_pane_id,
|
||||
should_float_if_hidden,
|
||||
should_float: should_float_if_hidden,
|
||||
},
|
||||
)),
|
||||
})
|
||||
|
@ -1,10 +1,10 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "action.proto";
|
||||
import "event.proto";
|
||||
import "file.proto";
|
||||
import "command.proto";
|
||||
import "message.proto";
|
||||
import "input_mode.proto";
|
||||
import "resize.proto";
|
||||
import "plugin_permission.proto";
|
||||
|
||||
@ -99,7 +99,7 @@ message PluginCommand {
|
||||
PluginMessagePayload post_message_to_payload = 14;
|
||||
PluginMessagePayload post_message_to_plugin_payload = 15;
|
||||
bool show_self_payload = 16;
|
||||
SwitchToModePayload switch_to_mode_payload = 17;
|
||||
action.SwitchToModePayload switch_to_mode_payload = 17;
|
||||
string new_tabs_with_layout_payload = 18;
|
||||
ResizePayload resize_payload = 19;
|
||||
ResizePayload resize_with_direction_payload = 20;
|
||||
@ -110,12 +110,12 @@ message PluginCommand {
|
||||
MovePayload move_pane_with_direction_payload = 25;
|
||||
string go_to_tab_name_payload = 26;
|
||||
string focus_or_create_tab_payload = 27;
|
||||
int32 go_to_tab_payload = 28;
|
||||
uint32 go_to_tab_payload = 28;
|
||||
string start_or_reload_plugin_payload = 29;
|
||||
int32 close_terminal_pane_payload = 30;
|
||||
int32 close_plugin_pane_payload = 31;
|
||||
PaneIdAndShouldFloat focus_terminal_pane_payload = 32;
|
||||
PaneIdAndShouldFloat focus_plugin_pane_payload = 33;
|
||||
uint32 close_terminal_pane_payload = 30;
|
||||
uint32 close_plugin_pane_payload = 31;
|
||||
action.PaneIdAndShouldFloat focus_terminal_pane_payload = 32;
|
||||
action.PaneIdAndShouldFloat focus_plugin_pane_payload = 33;
|
||||
IdAndNewName rename_terminal_pane_payload = 34;
|
||||
IdAndNewName rename_plugin_pane_payload = 35;
|
||||
IdAndNewName rename_tab_payload = 36;
|
||||
@ -153,11 +153,11 @@ message OpenCommandPanePayload {
|
||||
}
|
||||
|
||||
message SwitchTabToPayload {
|
||||
int32 tab_index = 1;
|
||||
uint32 tab_index = 1;
|
||||
}
|
||||
|
||||
message SetTimeoutPayload {
|
||||
float seconds = 1;
|
||||
double seconds = 1;
|
||||
}
|
||||
|
||||
message ExecCmdPayload {
|
||||
@ -168,10 +168,6 @@ message PluginMessagePayload {
|
||||
api.message.Message message = 1;
|
||||
}
|
||||
|
||||
message SwitchToModePayload {
|
||||
input_mode.InputModeMessage input_mode = 1;
|
||||
}
|
||||
|
||||
message ResizePayload {
|
||||
resize.Resize resize = 1;
|
||||
}
|
||||
@ -180,12 +176,7 @@ message MovePayload {
|
||||
resize.MoveDirection direction = 1;
|
||||
}
|
||||
|
||||
message PaneIdAndShouldFloat {
|
||||
int32 pane_id = 1;
|
||||
bool should_float = 2;
|
||||
}
|
||||
|
||||
message IdAndNewName {
|
||||
int32 id = 1; // pane id or tab index
|
||||
uint32 id = 1; // pane id or tab index
|
||||
string new_name = 2;
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
pub use super::generated_api::api::{
|
||||
action::{PaneIdAndShouldFloat, SwitchToModePayload},
|
||||
event::EventNameList as ProtobufEventNameList,
|
||||
input_mode::InputMode as ProtobufInputMode,
|
||||
plugin_command::{
|
||||
plugin_command::Payload, CommandName, ExecCmdPayload, IdAndNewName, MovePayload,
|
||||
OpenCommandPanePayload, OpenFilePayload, PaneIdAndShouldFloat,
|
||||
PluginCommand as ProtobufPluginCommand, PluginMessagePayload,
|
||||
RequestPluginPermissionPayload, ResizePayload, SetTimeoutPayload, SubscribePayload,
|
||||
SwitchSessionPayload, SwitchTabToPayload, SwitchToModePayload, UnsubscribePayload,
|
||||
OpenCommandPanePayload, OpenFilePayload, PluginCommand as ProtobufPluginCommand,
|
||||
PluginMessagePayload, RequestPluginPermissionPayload, ResizePayload, SetTimeoutPayload,
|
||||
SubscribePayload, SwitchSessionPayload, SwitchTabToPayload, UnsubscribePayload,
|
||||
},
|
||||
plugin_permission::PermissionType as ProtobufPermissionType,
|
||||
resize::ResizeAction as ProtobufResizeAction,
|
||||
@ -179,8 +180,10 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
|
||||
},
|
||||
Some(CommandName::SwitchToMode) => match protobuf_plugin_command.payload {
|
||||
Some(Payload::SwitchToModePayload(switch_to_mode_payload)) => {
|
||||
match switch_to_mode_payload.input_mode {
|
||||
Some(input_mode) => Ok(PluginCommand::SwitchToMode(input_mode.try_into()?)),
|
||||
match ProtobufInputMode::from_i32(switch_to_mode_payload.input_mode) {
|
||||
Some(protobuf_input_mode) => {
|
||||
Ok(PluginCommand::SwitchToMode(protobuf_input_mode.try_into()?))
|
||||
},
|
||||
None => Err("Malformed switch to mode payload"),
|
||||
}
|
||||
},
|
||||
@ -597,7 +600,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
|
||||
PluginCommand::SwitchTabTo(tab_index) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::SwitchTabTo as i32,
|
||||
payload: Some(Payload::SwitchTabToPayload(SwitchTabToPayload {
|
||||
tab_index: tab_index as i32,
|
||||
tab_index: tab_index,
|
||||
})),
|
||||
}),
|
||||
PluginCommand::SetTimeout(seconds) => Ok(ProtobufPluginCommand {
|
||||
@ -631,7 +634,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
|
||||
PluginCommand::SwitchToMode(input_mode) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::SwitchToMode as i32,
|
||||
payload: Some(Payload::SwitchToModePayload(SwitchToModePayload {
|
||||
input_mode: Some(input_mode.try_into()?),
|
||||
input_mode: ProtobufInputMode::try_from(input_mode)? as i32,
|
||||
})),
|
||||
}),
|
||||
PluginCommand::NewTabsWithLayout(raw_layout) => Ok(ProtobufPluginCommand {
|
||||
@ -794,7 +797,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
|
||||
}),
|
||||
PluginCommand::GoToTab(tab_index) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::GoToTab as i32,
|
||||
payload: Some(Payload::GoToTabPayload(tab_index as i32)),
|
||||
payload: Some(Payload::GoToTabPayload(tab_index)),
|
||||
}),
|
||||
PluginCommand::StartOrReloadPlugin(url) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::StartOrReloadPlugin as i32,
|
||||
@ -802,17 +805,17 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
|
||||
}),
|
||||
PluginCommand::CloseTerminalPane(pane_id) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::CloseTerminalPane as i32,
|
||||
payload: Some(Payload::CloseTerminalPanePayload(pane_id as i32)),
|
||||
payload: Some(Payload::CloseTerminalPanePayload(pane_id)),
|
||||
}),
|
||||
PluginCommand::ClosePluginPane(pane_id) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::ClosePluginPane as i32,
|
||||
payload: Some(Payload::ClosePluginPanePayload(pane_id as i32)),
|
||||
payload: Some(Payload::ClosePluginPanePayload(pane_id)),
|
||||
}),
|
||||
PluginCommand::FocusTerminalPane(pane_id, should_float_if_hidden) => {
|
||||
Ok(ProtobufPluginCommand {
|
||||
name: CommandName::FocusTerminalPane as i32,
|
||||
payload: Some(Payload::FocusTerminalPanePayload(PaneIdAndShouldFloat {
|
||||
pane_id: pane_id as i32,
|
||||
pane_id: pane_id,
|
||||
should_float: should_float_if_hidden,
|
||||
})),
|
||||
})
|
||||
@ -821,7 +824,7 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
|
||||
Ok(ProtobufPluginCommand {
|
||||
name: CommandName::FocusPluginPane as i32,
|
||||
payload: Some(Payload::FocusPluginPanePayload(PaneIdAndShouldFloat {
|
||||
pane_id: pane_id as i32,
|
||||
pane_id: pane_id,
|
||||
should_float: should_float_if_hidden,
|
||||
})),
|
||||
})
|
||||
@ -829,21 +832,21 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
|
||||
PluginCommand::RenameTerminalPane(pane_id, new_name) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::RenameTerminalPane as i32,
|
||||
payload: Some(Payload::RenameTerminalPanePayload(IdAndNewName {
|
||||
id: pane_id as i32,
|
||||
id: pane_id,
|
||||
new_name,
|
||||
})),
|
||||
}),
|
||||
PluginCommand::RenamePluginPane(pane_id, new_name) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::RenamePluginPane as i32,
|
||||
payload: Some(Payload::RenamePluginPanePayload(IdAndNewName {
|
||||
id: pane_id as i32,
|
||||
id: pane_id,
|
||||
new_name,
|
||||
})),
|
||||
}),
|
||||
PluginCommand::RenameTab(tab_index, new_name) => Ok(ProtobufPluginCommand {
|
||||
name: CommandName::RenameTab as i32,
|
||||
payload: Some(Payload::RenameTabPayload(IdAndNewName {
|
||||
id: tab_index as i32,
|
||||
id: tab_index,
|
||||
new_name,
|
||||
})),
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user