summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/pty.rs
diff options
context:
space:
mode:
authorCosmin Popescu <cosminadrianpopescu@gmail.com>2022-06-06 09:20:07 +0200
committerGitHub <noreply@github.com>2022-06-06 09:20:07 +0200
commite1fcf3a6dbc7a65a341127fab2fca7b4fb2d081b (patch)
treeec1061b57347348f081d64c532f7fc12ff21c4dd /zellij-server/src/pty.rs
parent58cc8fb2e1a091dca72fdbaf9150b200e130fa73 (diff)
feat(scroll): edit scrollback with default editor (#1456)
* initial commit for opening the current buffer in an editor * fix(editor): take hidden panes into consideration when manipulating tiled grid * when closing an edit buffer, take the geometry of the replaced buffer from the closed buffer * if the floating panels are displayed, don't add to hidden panels the current buffer * strategy changing - put the panels inside a suppressed_panels HashMap instead of hidden_panels * Revert "strategy changing - put the panels inside a suppressed_panels HashMap instead of hidden_panels" This reverts commit c52a203a20cf4c87c147be8b9c193ed6458c1038. * remove the floating panes by moving them to the tiled_panes in hidden_panels * feat(edit): open editor to correct line and don't crash when none is set * formatting * feat(edit): use suppressed panes * style(fmt): rustfmt and logs * style(fmt): clean up unused code * test(editor): integration test for suppressing/closing suppressed pane * test(e2e): editor e2e test * style(fmt): rustfmt * feat(edit): update ui and setup * style(fmt): rustfmt * feat(config): allow configuring scrollback_editor explicitly * style(fmt): rustfmt * chore(repo): build after merging Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'zellij-server/src/pty.rs')
-rw-r--r--zellij-server/src/pty.rs55
1 files changed, 44 insertions, 11 deletions
diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs
index 327347cb5..6abcd6671 100644
--- a/zellij-server/src/pty.rs
+++ b/zellij-server/src/pty.rs
@@ -41,6 +41,7 @@ pub enum ClientOrTabIndex {
#[derive(Clone, Debug)]
pub(crate) enum PtyInstruction {
SpawnTerminal(Option<TerminalAction>, ClientOrTabIndex),
+ OpenInPlaceEditor(PathBuf, Option<usize>, ClientId), // Option<usize> is the optional line number
SpawnTerminalVertically(Option<TerminalAction>, ClientId),
SpawnTerminalHorizontally(Option<TerminalAction>, ClientId),
UpdateActivePane(Option<PaneId>, ClientId),
@@ -55,6 +56,7 @@ impl From<&PtyInstruction> for PtyContext {
fn from(pty_instruction: &PtyInstruction) -> Self {
match *pty_instruction {
PtyInstruction::SpawnTerminal(..) => PtyContext::SpawnTerminal,
+ PtyInstruction::OpenInPlaceEditor(..) => PtyContext::OpenInPlaceEditor,
PtyInstruction::SpawnTerminalVertically(..) => PtyContext::SpawnTerminalVertically,
PtyInstruction::SpawnTerminalHorizontally(..) => PtyContext::SpawnTerminalHorizontally,
PtyInstruction::UpdateActivePane(..) => PtyContext::UpdateActivePane,
@@ -73,6 +75,7 @@ pub(crate) struct Pty {
pub id_to_child_pid: HashMap<RawFd, RawFd>, // pty_primary => child raw fd
debug_to_file: bool,
task_handles: HashMap<RawFd, JoinHandle<()>>,
+ default_editor: Option<PathBuf>,
}
use std::convert::TryFrom;
@@ -83,7 +86,9 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<LayoutFromYaml>) {
err_ctx.add_call(ContextType::Pty((&event).into()));
match event {
PtyInstruction::SpawnTerminal(terminal_action, client_or_tab_index) => {
- let pid = pty.spawn_terminal(terminal_action, client_or_tab_index);
+ let pid = pty
+ .spawn_terminal(terminal_action, client_or_tab_index)
+ .unwrap(); // TODO: handle error here
pty.bus
.senders
.send_to_screen(ScreenInstruction::NewPane(
@@ -92,9 +97,29 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<LayoutFromYaml>) {
))
.unwrap();
}
+ PtyInstruction::OpenInPlaceEditor(temp_file, line_number, client_id) => {
+ match pty.spawn_terminal(
+ Some(TerminalAction::OpenFile(temp_file, line_number)),
+ ClientOrTabIndex::ClientId(client_id),
+ ) {
+ Ok(pid) => {
+ pty.bus
+ .senders
+ .send_to_screen(ScreenInstruction::OpenInPlaceEditor(
+ PaneId::Terminal(pid),
+ client_id,
+ ))
+ .unwrap();
+ }
+ Err(e) => {
+ log::error!("Failed to open editor: {}", e);
+ }
+ }
+ }
PtyInstruction::SpawnTerminalVertically(terminal_action, client_id) => {
- let pid =
- pty.spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id));
+ let pid = pty
+ .spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id))
+ .unwrap(); // TODO: handle error here
pty.bus
.senders
.send_to_screen(ScreenInstruction::VerticalSplit(
@@ -104,8 +129,9 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<LayoutFromYaml>) {
.unwrap();
}
PtyInstruction::SpawnTerminalHorizontally(terminal_action, client_id) => {
- let pid =
- pty.spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id));
+ let pid = pty
+ .spawn_terminal(terminal_action, ClientOrTabIndex::ClientId(client_id))
+ .unwrap(); // TODO: handle error here
pty.bus
.senders
.send_to_screen(ScreenInstruction::HorizontalSplit(
@@ -267,13 +293,18 @@ fn stream_terminal_bytes(
}
impl Pty {
- pub fn new(bus: Bus<PtyInstruction>, debug_to_file: bool) -> Self {
+ pub fn new(
+ bus: Bus<PtyInstruction>,
+ debug_to_file: bool,
+ default_editor: Option<PathBuf>,
+ ) -> Self {
Pty {
active_panes: HashMap::new(),
bus,
id_to_child_pid: HashMap::new(),
debug_to_file,
task_handles: HashMap::new(),
+ default_editor,
}
}
pub fn get_default_terminal(&self) -> TerminalAction {
@@ -306,7 +337,7 @@ impl Pty {
&mut self,
terminal_action: Option<TerminalAction>,
client_or_tab_index: ClientOrTabIndex,
- ) -> RawFd {
+ ) -> Result<RawFd, &'static str> {
let terminal_action = match client_or_tab_index {
ClientOrTabIndex::ClientId(client_id) => {
let mut terminal_action =
@@ -329,7 +360,7 @@ impl Pty {
.os_input
.as_mut()
.unwrap()
- .spawn_terminal(terminal_action, quit_cb);
+ .spawn_terminal(terminal_action, quit_cb, self.default_editor.clone())?;
let task_handle = stream_terminal_bytes(
pid_primary,
self.bus.senders.clone(),
@@ -338,7 +369,7 @@ impl Pty {
);
self.task_handles.insert(pid_primary, task_handle);
self.id_to_child_pid.insert(pid_primary, child_fd);
- pid_primary
+ Ok(pid_primary)
}
pub fn spawn_terminals_for_layout(
&mut self,
@@ -365,7 +396,8 @@ impl Pty {
.os_input
.as_mut()
.unwrap()
- .spawn_terminal(cmd, quit_cb);
+ .spawn_terminal(cmd, quit_cb, self.default_editor.clone())
+ .unwrap(); // TODO: handle error here
self.id_to_child_pid.insert(pid_primary, child_fd);
new_pane_pids.push(pid_primary);
}
@@ -375,7 +407,8 @@ impl Pty {
.os_input
.as_mut()
.unwrap()
- .spawn_terminal(default_shell.clone(), quit_cb);
+ .spawn_terminal(default_shell.clone(), quit_cb, self.default_editor.clone())
+ .unwrap(); // TODO: handle error here
self.id_to_child_pid.insert(pid_primary, child_fd);
new_pane_pids.push(pid_primary);
}