Skip to content

Commit

Permalink
style(fmt): rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
imsnif committed Jul 22, 2024
1 parent d4b1565 commit 0ca71bc
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 85 deletions.
13 changes: 8 additions & 5 deletions default-plugins/fixture-plugin-for-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ impl ZellijPlugin for State {
);
},
BareKey::Char('m') if key.has_modifiers(&[KeyModifier::Ctrl]) => {
open_command_pane(CommandToRun {
path: std::path::PathBuf::from("/path/to/my/file.rs"),
args: vec!["arg1".to_owned(), "arg2".to_owned()],
..Default::default()
}, BTreeMap::new());
open_command_pane(
CommandToRun {
path: std::path::PathBuf::from("/path/to/my/file.rs"),
args: vec!["arg1".to_owned(), "arg2".to_owned()],
..Default::default()
},
BTreeMap::new(),
);
},
BareKey::Char('n') if key.has_modifiers(&[KeyModifier::Ctrl]) => {
open_command_pane_floating(
Expand Down
55 changes: 41 additions & 14 deletions zellij-server/src/plugins/zellij_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::{
use wasmtime::{Caller, Linker};
use zellij_utils::data::{
CommandType, ConnectToSession, FloatingPaneCoordinates, HttpVerb, LayoutInfo, MessageToPlugin,
PermissionStatus, PermissionType, PluginPermission, OriginatingPlugin,
OriginatingPlugin, PermissionStatus, PermissionType, PluginPermission,
};
use zellij_utils::input::permission::PermissionCache;
use zellij_utils::{
Expand Down Expand Up @@ -106,7 +106,12 @@ fn host_run_plugin_command(caller: Caller<'_, PluginEnv>) {
command_to_run,
floating_pane_coordinates,
context,
) => open_command_pane_floating(env, command_to_run, floating_pane_coordinates, context),
) => open_command_pane_floating(
env,
command_to_run,
floating_pane_coordinates,
context,
),
PluginCommand::SwitchTabTo(tab_index) => switch_tab_to(env, tab_index),
PluginCommand::SetTimeout(seconds) => set_timeout(env, seconds),
PluginCommand::ExecCmd(command_line) => exec_cmd(env, command_line),
Expand Down Expand Up @@ -247,8 +252,12 @@ fn host_run_plugin_command(caller: Caller<'_, PluginEnv>) {
PluginCommand::DumpSessionLayout => dump_session_layout(env),
PluginCommand::CloseSelf => close_self(env),
PluginCommand::Reconfigure(new_config) => reconfigure(env, new_config)?,
PluginCommand::HidePaneWithId(pane_id) => hide_pane_with_id(env, pane_id.into())?,
PluginCommand::ShowPaneWithId(pane_id, should_float_if_hidden) => show_pane_with_id(env, pane_id.into(), should_float_if_hidden),
PluginCommand::HidePaneWithId(pane_id) => {
hide_pane_with_id(env, pane_id.into())?
},
PluginCommand::ShowPaneWithId(pane_id, should_float_if_hidden) => {
show_pane_with_id(env, pane_id.into(), should_float_if_hidden)
},
},
(PermissionStatus::Denied, permission) => {
log::error!(
Expand Down Expand Up @@ -533,7 +542,11 @@ fn open_terminal_in_place(env: &PluginEnv, cwd: PathBuf) {
apply_action!(action, error_msg, env);
}

fn open_command_pane(env: &PluginEnv, command_to_run: CommandToRun, context: BTreeMap<String, String>) {
fn open_command_pane(
env: &PluginEnv,
command_to_run: CommandToRun,
context: BTreeMap<String, String>,
) {
let error_msg = || format!("failed to open command in plugin {}", env.name());
let command = command_to_run.path;
let cwd = command_to_run.cwd.map(|cwd| env.plugin_cwd.join(cwd));
Expand All @@ -549,7 +562,11 @@ fn open_command_pane(env: &PluginEnv, command_to_run: CommandToRun, context: BTr
direction,
hold_on_close,
hold_on_start,
originating_plugin: Some(OriginatingPlugin::new(env.plugin_id, env.client_id, context)),
originating_plugin: Some(OriginatingPlugin::new(
env.plugin_id,
env.client_id,
context,
)),
};
let action = Action::NewTiledPane(direction, Some(run_command_action), name);
apply_action!(action, error_msg, env);
Expand All @@ -576,13 +593,21 @@ fn open_command_pane_floating(
direction,
hold_on_close,
hold_on_start,
originating_plugin: Some(OriginatingPlugin::new(env.plugin_id, env.client_id, context)),
originating_plugin: Some(OriginatingPlugin::new(
env.plugin_id,
env.client_id,
context,
)),
};
let action = Action::NewFloatingPane(Some(run_command_action), name, floating_pane_coordinates);
apply_action!(action, error_msg, env);
}

fn open_command_pane_in_place(env: &PluginEnv, command_to_run: CommandToRun, context: BTreeMap<String, String>) {
fn open_command_pane_in_place(
env: &PluginEnv,
command_to_run: CommandToRun,
context: BTreeMap<String, String>,
) {
let error_msg = || format!("failed to open command in plugin {}", env.name());
let command = command_to_run.path;
let cwd = command_to_run.cwd.map(|cwd| env.plugin_cwd.join(cwd));
Expand All @@ -598,7 +623,11 @@ fn open_command_pane_in_place(env: &PluginEnv, command_to_run: CommandToRun, con
direction,
hold_on_close,
hold_on_start,
originating_plugin: Some(OriginatingPlugin::new(env.plugin_id, env.client_id, context)),
originating_plugin: Some(OriginatingPlugin::new(
env.plugin_id,
env.client_id,
context,
)),
};
let action = Action::NewInPlacePane(Some(run_command_action), name);
apply_action!(action, error_msg, env);
Expand Down Expand Up @@ -771,10 +800,7 @@ fn hide_self(env: &PluginEnv) -> Result<()> {

fn hide_pane_with_id(env: &PluginEnv, pane_id: PaneId) -> Result<()> {
env.senders
.send_to_screen(ScreenInstruction::SuppressPane(
pane_id,
env.client_id,
))
.send_to_screen(ScreenInstruction::SuppressPane(pane_id, env.client_id))
.with_context(|| format!("failed to hide self"))
}

Expand All @@ -785,7 +811,8 @@ fn show_self(env: &PluginEnv, should_float_if_hidden: bool) {
}

fn show_pane_with_id(env: &PluginEnv, pane_id: PaneId, should_float_if_hidden: bool) {
let _ = env.senders
let _ = env
.senders
.send_to_screen(ScreenInstruction::FocusPaneWithId(
pane_id,
should_float_if_hidden,
Expand Down
44 changes: 27 additions & 17 deletions zellij-server/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::{
ClientId, ServerInstruction,
};
use async_std::task::{self, JoinHandle};
use std::{collections::HashMap, os::unix::io::RawFd, path::PathBuf};
use std::sync::Arc;
use std::{collections::HashMap, os::unix::io::RawFd, path::PathBuf};
use zellij_utils::nix::unistd::Pid;
use zellij_utils::{
async_std,
data::{FloatingPaneCoordinates, Event},
data::{Event, FloatingPaneCoordinates},
errors::prelude::*,
errors::{ContextType, PtyContext},
input::{
Expand Down Expand Up @@ -177,13 +177,18 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {

// if this command originated in a plugin, we send the plugin back an event
// to let it know the command started and which pane_id it has
if let Some(originating_plugin) = run_command.and_then(|r| r.originating_plugin) {
let update_event = Event::CommandPaneOpened(pid, originating_plugin.context.clone());
if let Some(originating_plugin) =
run_command.and_then(|r| r.originating_plugin)
{
let update_event =
Event::CommandPaneOpened(pid, originating_plugin.context.clone());
pty.bus
.senders
.send_to_plugin(PluginInstruction::Update(
vec![(Some(originating_plugin.plugin_id), Some(originating_plugin.client_id), update_event)]
))
.send_to_plugin(PluginInstruction::Update(vec![(
Some(originating_plugin.plugin_id),
Some(originating_plugin.client_id),
update_event,
)]))
.with_context(err_context)?;
}

Expand Down Expand Up @@ -843,9 +848,11 @@ impl Pty {
},
};
let (hold_on_start, hold_on_close, originating_plugin) = match &terminal_action {
TerminalAction::RunCommand(run_command) => {
(run_command.hold_on_start, run_command.hold_on_close, run_command.originating_plugin.clone())
},
TerminalAction::RunCommand(run_command) => (
run_command.hold_on_start,
run_command.hold_on_close,
run_command.originating_plugin.clone(),
),
_ => (false, false, None),
};

Expand All @@ -870,16 +877,19 @@ impl Pty {
// know the command exited and some other useful information
if let PaneId::Terminal(pane_id) = pane_id {
if let Some(originating_plugin) = originating_plugin.as_ref() {
let update_event = Event::CommandPaneExited(pane_id, exit_status, originating_plugin.context.clone());
let _ = senders
.send_to_plugin(PluginInstruction::Update(
vec![(Some(originating_plugin.plugin_id), Some(originating_plugin.client_id), update_event)]
));
let update_event = Event::CommandPaneExited(
pane_id,
exit_status,
originating_plugin.context.clone(),
);
let _ = senders.send_to_plugin(PluginInstruction::Update(vec![(
Some(originating_plugin.plugin_id),
Some(originating_plugin.client_id),
update_event,
)]));
}
}



if hold_on_close {
let _ = senders.send_to_screen(ScreenInstruction::HoldPane(
pane_id,
Expand Down
3 changes: 2 additions & 1 deletion zellij-tile/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ pub fn open_command_pane_floating(
coordinates: Option<FloatingPaneCoordinates>,
context: BTreeMap<String, String>,
) {
let plugin_command = PluginCommand::OpenCommandPaneFloating(command_to_run, coordinates, context);
let plugin_command =
PluginCommand::OpenCommandPaneFloating(command_to_run, coordinates, context);
let protobuf_plugin_command: ProtobufPluginCommand = plugin_command.try_into().unwrap();
object_to_stdout(&protobuf_plugin_command.encode_to_vec());
unsafe { host_run_plugin_command() };
Expand Down
8 changes: 4 additions & 4 deletions zellij-utils/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,12 +910,12 @@ pub enum Event {
Vec<u8>,
BTreeMap<String, String>,
), // status,
// headers,
// body,
// context
// headers,
// body,
// context
CommandPaneOpened(u32, Context), // u32 - terminal_pane_id
CommandPaneExited(u32, Option<i32>, Context), // u32 - terminal_pane_id, Option<i32> -
// exit_code
// exit_code
}

#[derive(
Expand Down
50 changes: 25 additions & 25 deletions zellij-utils/src/plugin_api/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,32 +236,32 @@ impl TryFrom<ProtobufEvent> for Event {
_ => Err("Malformed payload for the WebRequestResult Event"),
},
Some(ProtobufEventType::CommandPaneOpened) => match protobuf_event.payload {
Some(ProtobufEventPayload::CommandPaneOpenedPayload(command_pane_opened_payload)) => {
Ok(Event::CommandPaneOpened(
command_pane_opened_payload.terminal_pane_id,
command_pane_opened_payload
.context
.into_iter()
.map(|c_i| (c_i.name, c_i.value))
.collect(),
))
},
Some(ProtobufEventPayload::CommandPaneOpenedPayload(
command_pane_opened_payload,
)) => Ok(Event::CommandPaneOpened(
command_pane_opened_payload.terminal_pane_id,
command_pane_opened_payload
.context
.into_iter()
.map(|c_i| (c_i.name, c_i.value))
.collect(),
)),
_ => Err("Malformed payload for the CommandPaneOpened Event"),
}
},
Some(ProtobufEventType::CommandPaneExited) => match protobuf_event.payload {
Some(ProtobufEventPayload::CommandPaneExitedPayload(command_pane_exited_payload)) => {
Ok(Event::CommandPaneExited(
command_pane_exited_payload.terminal_pane_id,
command_pane_exited_payload.exit_code,
command_pane_exited_payload
.context
.into_iter()
.map(|c_i| (c_i.name, c_i.value))
.collect(),
))
},
Some(ProtobufEventPayload::CommandPaneExitedPayload(
command_pane_exited_payload,
)) => Ok(Event::CommandPaneExited(
command_pane_exited_payload.terminal_pane_id,
command_pane_exited_payload.exit_code,
command_pane_exited_payload
.context
.into_iter()
.map(|c_i| (c_i.name, c_i.value))
.collect(),
)),
_ => Err("Malformed payload for the CommandPaneExited Event"),
}
},
None => Err("Unknown Protobuf Event"),
}
}
Expand Down Expand Up @@ -498,7 +498,7 @@ impl TryFrom<Event> for ProtobufEvent {
Ok(ProtobufEvent {
name: ProtobufEventType::CommandPaneOpened as i32,
payload: Some(event::Payload::CommandPaneOpenedPayload(
command_pane_opened_payload
command_pane_opened_payload,
)),
})
},
Expand All @@ -514,7 +514,7 @@ impl TryFrom<Event> for ProtobufEvent {
Ok(ProtobufEvent {
name: ProtobufEventType::CommandPaneExited as i32,
payload: Some(event::Payload::CommandPaneExitedPayload(
command_pane_exited_payload
command_pane_exited_payload,
)),
})
},
Expand Down
Loading

0 comments on commit 0ca71bc

Please sign in to comment.