Divide OsApi into ClientOsApi and ServerOsApi and move calls to os thread
This commit is contained in:
parent
70d8be0741
commit
0d814ebcde
10 changed files with 420 additions and 269 deletions
|
|
@ -10,7 +10,11 @@ use crate::pty_bus::{PtyInstruction, VteBytes};
|
||||||
use crate::utils::shared::adjust_to_size;
|
use crate::utils::shared::adjust_to_size;
|
||||||
use crate::wasm_vm::PluginInstruction;
|
use crate::wasm_vm::PluginInstruction;
|
||||||
use crate::{boundaries::Boundaries, panes::PluginPane};
|
use crate::{boundaries::Boundaries, panes::PluginPane};
|
||||||
use serde::{Deserialize, Serialize};
|
use crate::{layout::Layout, wasm_vm::PluginInstruction};
|
||||||
|
use crate::{
|
||||||
|
os_input_output::{ClientOsApi, ServerOsApiInstruction},
|
||||||
|
utils::shared::pad_to_size,
|
||||||
|
};
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -67,8 +71,7 @@ pub struct Tab {
|
||||||
max_panes: Option<usize>,
|
max_panes: Option<usize>,
|
||||||
full_screen_ws: PositionAndSize,
|
full_screen_ws: PositionAndSize,
|
||||||
fullscreen_is_active: bool,
|
fullscreen_is_active: bool,
|
||||||
synchronize_is_active: bool,
|
os_api: Box<dyn ClientOsApi>,
|
||||||
os_api: Box<dyn OsApi>,
|
|
||||||
pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
||||||
pub send_app_instructions: SenderWithContext<AppInstruction>,
|
pub send_app_instructions: SenderWithContext<AppInstruction>,
|
||||||
should_clear_display_before_rendering: bool,
|
should_clear_display_before_rendering: bool,
|
||||||
|
|
@ -224,7 +227,7 @@ impl Tab {
|
||||||
position: usize,
|
position: usize,
|
||||||
name: String,
|
name: String,
|
||||||
full_screen_ws: &PositionAndSize,
|
full_screen_ws: &PositionAndSize,
|
||||||
mut os_api: Box<dyn OsApi>,
|
os_api: Box<dyn ClientOsApi>,
|
||||||
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
||||||
send_app_instructions: SenderWithContext<AppInstruction>,
|
send_app_instructions: SenderWithContext<AppInstruction>,
|
||||||
max_panes: Option<usize>,
|
max_panes: Option<usize>,
|
||||||
|
|
@ -235,11 +238,15 @@ impl Tab {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let panes = if let Some(PaneId::Terminal(pid)) = pane_id {
|
let panes = if let Some(PaneId::Terminal(pid)) = pane_id {
|
||||||
let new_terminal = TerminalPane::new(pid, *full_screen_ws);
|
let new_terminal = TerminalPane::new(pid, *full_screen_ws);
|
||||||
os_api.set_terminal_size_using_fd(
|
send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
new_terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
new_terminal.rows() as u16,
|
new_terminal.pid,
|
||||||
);
|
new_terminal.columns() as u16,
|
||||||
|
new_terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
let mut panes: BTreeMap<PaneId, Box<dyn Pane>> = BTreeMap::new();
|
let mut panes: BTreeMap<PaneId, Box<dyn Pane>> = BTreeMap::new();
|
||||||
panes.insert(PaneId::Terminal(pid), Box::new(new_terminal));
|
panes.insert(PaneId::Terminal(pid), Box::new(new_terminal));
|
||||||
panes
|
panes
|
||||||
|
|
@ -292,11 +299,15 @@ impl Tab {
|
||||||
terminal_pane.set_max_width(max_columns);
|
terminal_pane.set_max_width(max_columns);
|
||||||
}
|
}
|
||||||
terminal_pane.change_pos_and_size(&position_and_size);
|
terminal_pane.change_pos_and_size(&position_and_size);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
*pid,
|
.send(AppInstruction::OsApi(
|
||||||
position_and_size.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
position_and_size.rows as u16,
|
*pid,
|
||||||
);
|
position_and_size.columns as u16,
|
||||||
|
position_and_size.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// we filled the entire layout, no room for this pane
|
// we filled the entire layout, no room for this pane
|
||||||
|
|
@ -338,11 +349,15 @@ impl Tab {
|
||||||
// there are still panes left to fill, use the pids we received in this method
|
// there are still panes left to fill, use the pids we received in this method
|
||||||
let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
|
let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
|
||||||
let new_terminal = TerminalPane::new(*pid, *position_and_size);
|
let new_terminal = TerminalPane::new(*pid, *position_and_size);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
new_terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
new_terminal.rows() as u16,
|
new_terminal.pid,
|
||||||
);
|
new_terminal.columns() as u16,
|
||||||
|
new_terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
self.panes
|
self.panes
|
||||||
.insert(PaneId::Terminal(*pid), Box::new(new_terminal));
|
.insert(PaneId::Terminal(*pid), Box::new(new_terminal));
|
||||||
}
|
}
|
||||||
|
|
@ -368,11 +383,15 @@ impl Tab {
|
||||||
if !self.has_panes() {
|
if !self.has_panes() {
|
||||||
if let PaneId::Terminal(term_pid) = pid {
|
if let PaneId::Terminal(term_pid) = pid {
|
||||||
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
|
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
new_terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
new_terminal.rows() as u16,
|
new_terminal.pid,
|
||||||
);
|
new_terminal.columns() as u16,
|
||||||
|
new_terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
self.panes.insert(pid, Box::new(new_terminal));
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
}
|
}
|
||||||
|
|
@ -418,19 +437,27 @@ impl Tab {
|
||||||
if let PaneId::Terminal(term_pid) = pid {
|
if let PaneId::Terminal(term_pid) = pid {
|
||||||
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
|
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
|
||||||
let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
|
let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
bottom_winsize.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
bottom_winsize.rows as u16,
|
new_terminal.pid,
|
||||||
);
|
bottom_winsize.columns as u16,
|
||||||
|
bottom_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
terminal_to_split.change_pos_and_size(&top_winsize);
|
terminal_to_split.change_pos_and_size(&top_winsize);
|
||||||
self.panes.insert(pid, Box::new(new_terminal));
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
if let PaneId::Terminal(terminal_id_to_split) = terminal_id_to_split {
|
if let PaneId::Terminal(terminal_id_to_split) = terminal_id_to_split {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
terminal_id_to_split,
|
.send(AppInstruction::OsApi(
|
||||||
top_winsize.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
top_winsize.rows as u16,
|
terminal_id_to_split,
|
||||||
);
|
top_winsize.columns as u16,
|
||||||
|
top_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
}
|
}
|
||||||
|
|
@ -438,19 +465,27 @@ impl Tab {
|
||||||
if let PaneId::Terminal(term_pid) = pid {
|
if let PaneId::Terminal(term_pid) = pid {
|
||||||
let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);
|
let (left_winsize, right_winsize) = split_vertically_with_gap(&terminal_ws);
|
||||||
let new_terminal = TerminalPane::new(term_pid, right_winsize);
|
let new_terminal = TerminalPane::new(term_pid, right_winsize);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
right_winsize.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
right_winsize.rows as u16,
|
new_terminal.pid,
|
||||||
);
|
right_winsize.columns as u16,
|
||||||
|
right_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
terminal_to_split.change_pos_and_size(&left_winsize);
|
terminal_to_split.change_pos_and_size(&left_winsize);
|
||||||
self.panes.insert(pid, Box::new(new_terminal));
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
if let PaneId::Terminal(terminal_id_to_split) = terminal_id_to_split {
|
if let PaneId::Terminal(terminal_id_to_split) = terminal_id_to_split {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
terminal_id_to_split,
|
.send(AppInstruction::OsApi(
|
||||||
left_winsize.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
left_winsize.rows as u16,
|
terminal_id_to_split,
|
||||||
);
|
left_winsize.columns as u16,
|
||||||
|
left_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -466,11 +501,15 @@ impl Tab {
|
||||||
if !self.has_panes() {
|
if !self.has_panes() {
|
||||||
if let PaneId::Terminal(term_pid) = pid {
|
if let PaneId::Terminal(term_pid) = pid {
|
||||||
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
|
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
new_terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
new_terminal.rows() as u16,
|
new_terminal.pid,
|
||||||
);
|
new_terminal.columns() as u16,
|
||||||
|
new_terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
self.panes.insert(pid, Box::new(new_terminal));
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
}
|
}
|
||||||
|
|
@ -496,20 +535,32 @@ impl Tab {
|
||||||
|
|
||||||
active_pane.change_pos_and_size(&top_winsize);
|
active_pane.change_pos_and_size(&top_winsize);
|
||||||
|
|
||||||
let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
|
let new_terminal = TerminalPane::new(term_pid, bottom_winsize);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
bottom_winsize.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
bottom_winsize.rows as u16,
|
new_terminal.pid,
|
||||||
);
|
bottom_winsize.columns as u16,
|
||||||
self.panes.insert(pid, Box::new(new_terminal));
|
bottom_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
|
|
||||||
if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
|
if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
*active_terminal_pid,
|
.send(AppInstruction::OsApi(
|
||||||
top_winsize.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
top_winsize.rows as u16,
|
*active_terminal_pid,
|
||||||
);
|
top_winsize.columns as u16,
|
||||||
|
top_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.active_terminal = Some(pid);
|
||||||
|
self.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
|
|
@ -524,11 +575,15 @@ impl Tab {
|
||||||
if !self.has_panes() {
|
if !self.has_panes() {
|
||||||
if let PaneId::Terminal(term_pid) = pid {
|
if let PaneId::Terminal(term_pid) = pid {
|
||||||
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
|
let new_terminal = TerminalPane::new(term_pid, self.full_screen_ws);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
new_terminal.pid,
|
.send(AppInstruction::OsApi(
|
||||||
new_terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
new_terminal.rows() as u16,
|
new_terminal.pid,
|
||||||
);
|
new_terminal.columns() as u16,
|
||||||
|
new_terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
self.panes.insert(pid, Box::new(new_terminal));
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
}
|
}
|
||||||
|
|
@ -560,12 +615,32 @@ impl Tab {
|
||||||
);
|
);
|
||||||
self.panes.insert(pid, Box::new(new_terminal));
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
|
|
||||||
if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
|
let new_terminal = TerminalPane::new(term_pid, right_winsize);
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
*active_terminal_pid,
|
.send(AppInstruction::OsApi(
|
||||||
left_winsize.columns as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
left_winsize.rows as u16,
|
new_terminal.pid,
|
||||||
);
|
right_winsize.columns as u16,
|
||||||
|
right_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
self.panes.insert(pid, Box::new(new_terminal));
|
||||||
|
|
||||||
|
if let PaneId::Terminal(active_terminal_pid) = active_pane_id {
|
||||||
|
self.send_app_instructions
|
||||||
|
.send(AppInstruction::OsApi(
|
||||||
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
|
*active_terminal_pid,
|
||||||
|
left_winsize.columns as u16,
|
||||||
|
left_winsize.rows as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.active_terminal = Some(pid);
|
||||||
|
self.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.active_terminal = Some(pid);
|
self.active_terminal = Some(pid);
|
||||||
|
|
@ -622,13 +697,17 @@ impl Tab {
|
||||||
match self.get_active_pane_id() {
|
match self.get_active_pane_id() {
|
||||||
Some(PaneId::Terminal(active_terminal_id)) => {
|
Some(PaneId::Terminal(active_terminal_id)) => {
|
||||||
let active_terminal = self.get_active_pane().unwrap();
|
let active_terminal = self.get_active_pane().unwrap();
|
||||||
let mut adjusted_input = active_terminal.adjust_input_to_terminal(input_bytes);
|
let adjusted_input = active_terminal.adjust_input_to_terminal(input_bytes);
|
||||||
self.os_api
|
self.send_app_instructions
|
||||||
.write_to_tty_stdin(active_terminal_id, &mut adjusted_input)
|
.send(AppInstruction::OsApi(
|
||||||
.expect("failed to write to terminal");
|
ServerOsApiInstruction::WriteToTtyStdin(active_terminal_id, adjusted_input),
|
||||||
self.os_api
|
))
|
||||||
.tcdrain(active_terminal_id)
|
.unwrap();
|
||||||
.expect("failed to drain terminal");
|
self.send_app_instructions
|
||||||
|
.send(AppInstruction::OsApi(ServerOsApiInstruction::TcDrain(
|
||||||
|
active_terminal_id,
|
||||||
|
)))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
Some(PaneId::Plugin(pid)) => {
|
Some(PaneId::Plugin(pid)) => {
|
||||||
for key in parse_keys(&input_bytes) {
|
for key in parse_keys(&input_bytes) {
|
||||||
|
|
@ -690,11 +769,15 @@ impl Tab {
|
||||||
}
|
}
|
||||||
let active_terminal = self.panes.get(&active_pane_id).unwrap();
|
let active_terminal = self.panes.get(&active_pane_id).unwrap();
|
||||||
if let PaneId::Terminal(active_pid) = active_pane_id {
|
if let PaneId::Terminal(active_pid) = active_pane_id {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
active_pid,
|
.send(AppInstruction::OsApi(
|
||||||
active_terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
active_terminal.rows() as u16,
|
active_pid,
|
||||||
);
|
active_terminal.columns() as u16,
|
||||||
|
active_terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
self.render();
|
self.render();
|
||||||
self.toggle_fullscreen_is_active();
|
self.toggle_fullscreen_is_active();
|
||||||
|
|
@ -1254,88 +1337,120 @@ impl Tab {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.reduce_height_down(count);
|
terminal.reduce_height_down(count);
|
||||||
if let PaneId::Terminal(pid) = id {
|
if let PaneId::Terminal(pid) = id {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
*pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
*pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn reduce_pane_height_up(&mut self, id: &PaneId, count: usize) {
|
fn reduce_pane_height_up(&mut self, id: &PaneId, count: usize) {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.reduce_height_up(count);
|
terminal.reduce_height_up(count);
|
||||||
if let PaneId::Terminal(pid) = id {
|
if let PaneId::Terminal(pid) = id {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
*pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
*pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn increase_pane_height_down(&mut self, id: &PaneId, count: usize) {
|
fn increase_pane_height_down(&mut self, id: &PaneId, count: usize) {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.increase_height_down(count);
|
terminal.increase_height_down(count);
|
||||||
if let PaneId::Terminal(pid) = terminal.pid() {
|
if let PaneId::Terminal(pid) = terminal.pid() {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn increase_pane_height_up(&mut self, id: &PaneId, count: usize) {
|
fn increase_pane_height_up(&mut self, id: &PaneId, count: usize) {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.increase_height_up(count);
|
terminal.increase_height_up(count);
|
||||||
if let PaneId::Terminal(pid) = terminal.pid() {
|
if let PaneId::Terminal(pid) = terminal.pid() {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn increase_pane_width_right(&mut self, id: &PaneId, count: usize) {
|
fn increase_pane_width_right(&mut self, id: &PaneId, count: usize) {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.increase_width_right(count);
|
terminal.increase_width_right(count);
|
||||||
if let PaneId::Terminal(pid) = terminal.pid() {
|
if let PaneId::Terminal(pid) = terminal.pid() {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn increase_pane_width_left(&mut self, id: &PaneId, count: usize) {
|
fn increase_pane_width_left(&mut self, id: &PaneId, count: usize) {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.increase_width_left(count);
|
terminal.increase_width_left(count);
|
||||||
if let PaneId::Terminal(pid) = terminal.pid() {
|
if let PaneId::Terminal(pid) = terminal.pid() {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn reduce_pane_width_right(&mut self, id: &PaneId, count: usize) {
|
fn reduce_pane_width_right(&mut self, id: &PaneId, count: usize) {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.reduce_width_right(count);
|
terminal.reduce_width_right(count);
|
||||||
if let PaneId::Terminal(pid) = terminal.pid() {
|
if let PaneId::Terminal(pid) = terminal.pid() {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn reduce_pane_width_left(&mut self, id: &PaneId, count: usize) {
|
fn reduce_pane_width_left(&mut self, id: &PaneId, count: usize) {
|
||||||
let terminal = self.panes.get_mut(id).unwrap();
|
let terminal = self.panes.get_mut(id).unwrap();
|
||||||
terminal.reduce_width_left(count);
|
terminal.reduce_width_left(count);
|
||||||
if let PaneId::Terminal(pid) = terminal.pid() {
|
if let PaneId::Terminal(pid) = terminal.pid() {
|
||||||
self.os_api.set_terminal_size_using_fd(
|
self.send_app_instructions
|
||||||
pid,
|
.send(AppInstruction::OsApi(
|
||||||
terminal.columns() as u16,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(
|
||||||
terminal.rows() as u16,
|
pid,
|
||||||
);
|
terminal.columns() as u16,
|
||||||
|
terminal.rows() as u16,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn pane_is_between_vertical_borders(
|
fn pane_is_between_vertical_borders(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Error context system based on a thread-local representation of the call stack, itself based on
|
//! Error context system based on a thread-local representation of the call stack, itself based on
|
||||||
//! the instructions that are sent between threads.
|
//! the instructions that are sent between threads.
|
||||||
|
|
||||||
use super::{os_input_output::OsApiInstruction, AppInstruction, OPENCALLS};
|
use super::{os_input_output::ServerOsApiInstruction, AppInstruction, OPENCALLS};
|
||||||
use crate::pty_bus::PtyInstruction;
|
use crate::pty_bus::PtyInstruction;
|
||||||
use crate::screen::ScreenInstruction;
|
use crate::screen::ScreenInstruction;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -297,26 +297,21 @@ impl From<&PtyInstruction> for PtyContext {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum OsContext {
|
pub enum OsContext {
|
||||||
SpawnTerminal,
|
|
||||||
GetTerminalSizeUsingFd,
|
|
||||||
SetTerminalSizeUsingFd,
|
SetTerminalSizeUsingFd,
|
||||||
SetRawMode,
|
|
||||||
UnsetRawMode,
|
|
||||||
ReadFromTtyStdout,
|
|
||||||
WriteToTtyStdin,
|
WriteToTtyStdin,
|
||||||
TcDrain,
|
TcDrain,
|
||||||
Kill,
|
Exit,
|
||||||
ReadFromStdin,
|
|
||||||
GetStdoutWriter,
|
|
||||||
BoxClone,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&OsApiInstruction> for OsContext {
|
impl From<&ServerOsApiInstruction> for OsContext {
|
||||||
fn from(os_instruction: &OsApiInstruction) -> Self {
|
fn from(os_instruction: &ServerOsApiInstruction) -> Self {
|
||||||
match *os_instruction {
|
match *os_instruction {
|
||||||
OsApiInstruction::SetTerminalSizeUsingFd(_, _, _) => OsContext::SetTerminalSizeUsingFd,
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(_, _, _) => {
|
||||||
OsApiInstruction::WriteToTtyStdin(_, _) => OsContext::WriteToTtyStdin,
|
OsContext::SetTerminalSizeUsingFd
|
||||||
OsApiInstruction::TcDrain(_) => OsContext::TcDrain,
|
}
|
||||||
|
ServerOsApiInstruction::WriteToTtyStdin(_, _) => OsContext::WriteToTtyStdin,
|
||||||
|
ServerOsApiInstruction::TcDrain(_) => OsContext::TcDrain,
|
||||||
|
ServerOsApiInstruction::Exit => OsContext::Exit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -356,6 +351,7 @@ pub enum AppContext {
|
||||||
ToPlugin,
|
ToPlugin,
|
||||||
ToScreen,
|
ToScreen,
|
||||||
DoneClosingPane,
|
DoneClosingPane,
|
||||||
|
OsApi,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&AppInstruction> for AppContext {
|
impl From<&AppInstruction> for AppContext {
|
||||||
|
|
@ -364,6 +360,7 @@ impl From<&AppInstruction> for AppContext {
|
||||||
AppInstruction::Exit => AppContext::Exit,
|
AppInstruction::Exit => AppContext::Exit,
|
||||||
AppInstruction::Error(_) => AppContext::Error,
|
AppInstruction::Error(_) => AppContext::Error,
|
||||||
AppInstruction::ToPty(_) => AppContext::ToPty,
|
AppInstruction::ToPty(_) => AppContext::ToPty,
|
||||||
|
AppInstruction::OsApi(_) => AppContext::OsApi,
|
||||||
AppInstruction::ToPlugin(_) => AppContext::ToPlugin,
|
AppInstruction::ToPlugin(_) => AppContext::ToPlugin,
|
||||||
AppInstruction::ToScreen(_) => AppContext::ToScreen,
|
AppInstruction::ToScreen(_) => AppContext::ToScreen,
|
||||||
AppInstruction::DoneClosingPane => AppContext::DoneClosingPane,
|
AppInstruction::DoneClosingPane => AppContext::DoneClosingPane,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use super::keybinds::Keybinds;
|
||||||
use crate::common::input::config::Config;
|
use crate::common::input::config::Config;
|
||||||
use crate::common::{AppInstruction, SenderWithContext, OPENCALLS};
|
use crate::common::{AppInstruction, SenderWithContext, OPENCALLS};
|
||||||
use crate::errors::ContextType;
|
use crate::errors::ContextType;
|
||||||
use crate::os_input_output::OsApi;
|
use crate::os_input_output::ClientOsApi;
|
||||||
use crate::pty_bus::PtyInstruction;
|
use crate::pty_bus::PtyInstruction;
|
||||||
use crate::screen::ScreenInstruction;
|
use crate::screen::ScreenInstruction;
|
||||||
use crate::wasm_vm::PluginInstruction;
|
use crate::wasm_vm::PluginInstruction;
|
||||||
|
|
@ -19,8 +19,7 @@ use zellij_tile::data::{Event, InputMode, Key, ModeInfo, Palette};
|
||||||
struct InputHandler {
|
struct InputHandler {
|
||||||
/// The current input mode
|
/// The current input mode
|
||||||
mode: InputMode,
|
mode: InputMode,
|
||||||
os_input: Box<dyn OsApi>,
|
os_input: Box<dyn ClientOsApi>,
|
||||||
config: Config,
|
|
||||||
command_is_executing: CommandIsExecuting,
|
command_is_executing: CommandIsExecuting,
|
||||||
send_screen_instructions: SenderWithContext<ScreenInstruction>,
|
send_screen_instructions: SenderWithContext<ScreenInstruction>,
|
||||||
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
||||||
|
|
@ -31,7 +30,7 @@ struct InputHandler {
|
||||||
impl InputHandler {
|
impl InputHandler {
|
||||||
/// Returns a new [`InputHandler`] with the attributes specified as arguments.
|
/// Returns a new [`InputHandler`] with the attributes specified as arguments.
|
||||||
fn new(
|
fn new(
|
||||||
os_input: Box<dyn OsApi>,
|
os_input: Box<dyn ClientOsApi>,
|
||||||
command_is_executing: CommandIsExecuting,
|
command_is_executing: CommandIsExecuting,
|
||||||
config: Config,
|
config: Config,
|
||||||
send_screen_instructions: SenderWithContext<ScreenInstruction>,
|
send_screen_instructions: SenderWithContext<ScreenInstruction>,
|
||||||
|
|
@ -336,8 +335,7 @@ pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo {
|
||||||
/// Entry point to the module. Instantiates an [`InputHandler`] and starts
|
/// Entry point to the module. Instantiates an [`InputHandler`] and starts
|
||||||
/// its [`InputHandler::handle_input()`] loop.
|
/// its [`InputHandler::handle_input()`] loop.
|
||||||
pub fn input_loop(
|
pub fn input_loop(
|
||||||
os_input: Box<dyn OsApi>,
|
os_input: Box<dyn ClientOsApi>,
|
||||||
config: Config,
|
|
||||||
command_is_executing: CommandIsExecuting,
|
command_is_executing: CommandIsExecuting,
|
||||||
send_screen_instructions: SenderWithContext<ScreenInstruction>,
|
send_screen_instructions: SenderWithContext<ScreenInstruction>,
|
||||||
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ use crate::server::start_server;
|
||||||
use command_is_executing::CommandIsExecuting;
|
use command_is_executing::CommandIsExecuting;
|
||||||
use errors::{AppContext, ContextType, ErrorContext, PluginContext, ScreenContext};
|
use errors::{AppContext, ContextType, ErrorContext, PluginContext, ScreenContext};
|
||||||
use input::handler::input_loop;
|
use input::handler::input_loop;
|
||||||
use os_input_output::{OsApi, OsApiInstruction};
|
use os_input_output::{ClientOsApi, ServerOsApiInstruction};
|
||||||
use pty_bus::PtyInstruction;
|
use pty_bus::PtyInstruction;
|
||||||
use screen::{Screen, ScreenInstruction};
|
use screen::{Screen, ScreenInstruction};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -51,7 +51,7 @@ pub enum ServerInstruction {
|
||||||
NewClient(String),
|
NewClient(String),
|
||||||
ToPty(PtyInstruction),
|
ToPty(PtyInstruction),
|
||||||
ToScreen(ScreenInstruction),
|
ToScreen(ScreenInstruction),
|
||||||
OsApi(OsApiInstruction),
|
OsApi(ServerOsApiInstruction),
|
||||||
DoneClosingPane,
|
DoneClosingPane,
|
||||||
ClosePluginPane(u32),
|
ClosePluginPane(u32),
|
||||||
Exit,
|
Exit,
|
||||||
|
|
@ -180,6 +180,7 @@ pub enum AppInstruction {
|
||||||
ToPty(PtyInstruction),
|
ToPty(PtyInstruction),
|
||||||
ToScreen(ScreenInstruction),
|
ToScreen(ScreenInstruction),
|
||||||
ToPlugin(PluginInstruction),
|
ToPlugin(PluginInstruction),
|
||||||
|
OsApi(ServerOsApiInstruction),
|
||||||
DoneClosingPane,
|
DoneClosingPane,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,7 +200,9 @@ impl From<ClientInstruction> for AppInstruction {
|
||||||
|
|
||||||
/// Start Zellij with the specified [`OsApi`] and command-line arguments.
|
/// Start Zellij with the specified [`OsApi`] and command-line arguments.
|
||||||
// FIXME this should definitely be modularized and split into different functions.
|
// FIXME this should definitely be modularized and split into different functions.
|
||||||
pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
|
pub fn start(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs) {
|
||||||
|
let (ipc_thread, server_name) = start_server(opts.clone());
|
||||||
|
|
||||||
let take_snapshot = "\u{1b}[?1049h";
|
let take_snapshot = "\u{1b}[?1049h";
|
||||||
os_input.unset_raw_mode(0);
|
os_input.unset_raw_mode(0);
|
||||||
let _ = os_input
|
let _ = os_input
|
||||||
|
|
@ -228,8 +231,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
|
||||||
let mut send_app_instructions =
|
let mut send_app_instructions =
|
||||||
SenderWithContext::new(err_ctx, SenderType::SyncSender(send_app_instructions));
|
SenderWithContext::new(err_ctx, SenderType::SyncSender(send_app_instructions));
|
||||||
|
|
||||||
let (ipc_thread, server_name) = start_server(os_input.clone(), opts.clone());
|
|
||||||
|
|
||||||
let (client_buffer_path, client_buffer) = SharedRingBuffer::create_temp(8192).unwrap();
|
let (client_buffer_path, client_buffer) = SharedRingBuffer::create_temp(8192).unwrap();
|
||||||
let mut send_server_instructions =
|
let mut send_server_instructions =
|
||||||
IpcSenderWithContext::new(SharedRingBuffer::open(&server_name).unwrap());
|
IpcSenderWithContext::new(SharedRingBuffer::open(&server_name).unwrap());
|
||||||
|
|
@ -612,7 +613,14 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
|
||||||
send_plugin_instructions.send(instruction).unwrap();
|
send_plugin_instructions.send(instruction).unwrap();
|
||||||
}
|
}
|
||||||
AppInstruction::ToPty(instruction) => {
|
AppInstruction::ToPty(instruction) => {
|
||||||
let _ = send_server_instructions.send(ServerInstruction::ToPty(instruction));
|
let _ = send_server_instructions
|
||||||
|
.send(ServerInstruction::ToPty(instruction))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
AppInstruction::OsApi(instruction) => {
|
||||||
|
let _ = send_server_instructions
|
||||||
|
.send(ServerInstruction::OsApi(instruction))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
AppInstruction::DoneClosingPane => command_is_executing.done_closing_pane(),
|
AppInstruction::DoneClosingPane => command_is_executing.done_closing_pane(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ use nix::sys::termios;
|
||||||
use nix::sys::wait::waitpid;
|
use nix::sys::wait::waitpid;
|
||||||
use nix::unistd;
|
use nix::unistd;
|
||||||
use nix::unistd::{ForkResult, Pid};
|
use nix::unistd::{ForkResult, Pid};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, Command};
|
use std::process::{Child, Command};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use signal_hook::{consts::signal::*, iterator::Signals};
|
use signal_hook::{consts::signal::*, iterator::Signals};
|
||||||
|
|
||||||
|
|
@ -156,23 +156,15 @@ fn spawn_terminal(file_to_open: Option<PathBuf>, orig_termios: termios::Termios)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct OsInputOutput {
|
pub struct ServerOsInputOutput {
|
||||||
orig_termios: Arc<Mutex<termios::Termios>>,
|
orig_termios: Arc<Mutex<termios::Termios>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The `OsApi` trait represents an abstract interface to the features of an operating system that
|
/// The `OsApi` trait represents an abstract interface to the features of an operating system that
|
||||||
/// Zellij requires.
|
/// Zellij requires.
|
||||||
pub trait OsApi: Send + Sync {
|
pub trait ServerOsApi: Send + Sync {
|
||||||
/// Returns the size of the terminal associated to file descriptor `fd`.
|
|
||||||
fn get_terminal_size_using_fd(&self, fd: RawFd) -> PositionAndSize;
|
|
||||||
/// Sets the size of the terminal associated to file descriptor `fd`.
|
/// Sets the size of the terminal associated to file descriptor `fd`.
|
||||||
fn set_terminal_size_using_fd(&mut self, fd: RawFd, cols: u16, rows: u16);
|
fn set_terminal_size_using_fd(&mut self, fd: RawFd, cols: u16, rows: u16);
|
||||||
/// Set the terminal associated to file descriptor `fd` to
|
|
||||||
/// [raw mode](https://en.wikipedia.org/wiki/Terminal_mode).
|
|
||||||
fn set_raw_mode(&mut self, fd: RawFd);
|
|
||||||
/// Set the terminal associated to file descriptor `fd` to
|
|
||||||
/// [cooked mode](https://en.wikipedia.org/wiki/Terminal_mode).
|
|
||||||
fn unset_raw_mode(&mut self, fd: RawFd);
|
|
||||||
/// Spawn a new terminal, with an optional file to open in a terminal program.
|
/// Spawn a new terminal, with an optional file to open in a terminal program.
|
||||||
fn spawn_terminal(&mut self, file_to_open: Option<PathBuf>) -> (RawFd, RawFd);
|
fn spawn_terminal(&mut self, file_to_open: Option<PathBuf>) -> (RawFd, RawFd);
|
||||||
/// Read bytes from the standard output of the virtual terminal referred to by `fd`.
|
/// Read bytes from the standard output of the virtual terminal referred to by `fd`.
|
||||||
|
|
@ -186,30 +178,14 @@ pub trait OsApi: Send + Sync {
|
||||||
// or a nix::unistd::Pid. See `man kill.3`, nix::sys::signal::kill (both take an argument
|
// or a nix::unistd::Pid. See `man kill.3`, nix::sys::signal::kill (both take an argument
|
||||||
// called `pid` and of type `pid_t`, and not `fd`)
|
// called `pid` and of type `pid_t`, and not `fd`)
|
||||||
fn kill(&mut self, pid: RawFd) -> Result<(), nix::Error>;
|
fn kill(&mut self, pid: RawFd) -> Result<(), nix::Error>;
|
||||||
/// Returns the raw contents of standard input.
|
|
||||||
fn read_from_stdin(&self) -> Vec<u8>;
|
|
||||||
/// Returns the writer that allows writing to standard output.
|
|
||||||
fn get_stdout_writer(&self) -> Box<dyn io::Write>;
|
|
||||||
/// Returns a [`Box`] pointer to this [`OsApi`] struct.
|
/// Returns a [`Box`] pointer to this [`OsApi`] struct.
|
||||||
fn box_clone(&self) -> Box<dyn OsApi>;
|
fn box_clone(&self) -> Box<dyn ServerOsApi>;
|
||||||
fn receive_sigwinch(&self, cb: Box<dyn Fn()>);
|
|
||||||
fn load_palette(&self) -> Palette;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OsApi for OsInputOutput {
|
impl ServerOsApi for ServerOsInputOutput {
|
||||||
fn get_terminal_size_using_fd(&self, fd: RawFd) -> PositionAndSize {
|
|
||||||
get_terminal_size_using_fd(fd)
|
|
||||||
}
|
|
||||||
fn set_terminal_size_using_fd(&mut self, fd: RawFd, cols: u16, rows: u16) {
|
fn set_terminal_size_using_fd(&mut self, fd: RawFd, cols: u16, rows: u16) {
|
||||||
set_terminal_size_using_fd(fd, cols, rows);
|
set_terminal_size_using_fd(fd, cols, rows);
|
||||||
}
|
}
|
||||||
fn set_raw_mode(&mut self, fd: RawFd) {
|
|
||||||
into_raw_mode(fd);
|
|
||||||
}
|
|
||||||
fn unset_raw_mode(&mut self, fd: RawFd) {
|
|
||||||
let orig_termios = self.orig_termios.lock().unwrap();
|
|
||||||
unset_raw_mode(fd, orig_termios.clone());
|
|
||||||
}
|
|
||||||
fn spawn_terminal(&mut self, file_to_open: Option<PathBuf>) -> (RawFd, RawFd) {
|
fn spawn_terminal(&mut self, file_to_open: Option<PathBuf>) -> (RawFd, RawFd) {
|
||||||
let orig_termios = self.orig_termios.lock().unwrap();
|
let orig_termios = self.orig_termios.lock().unwrap();
|
||||||
spawn_terminal(file_to_open, orig_termios.clone())
|
spawn_terminal(file_to_open, orig_termios.clone())
|
||||||
|
|
@ -223,7 +199,72 @@ impl OsApi for OsInputOutput {
|
||||||
fn tcdrain(&mut self, fd: RawFd) -> Result<(), nix::Error> {
|
fn tcdrain(&mut self, fd: RawFd) -> Result<(), nix::Error> {
|
||||||
termios::tcdrain(fd)
|
termios::tcdrain(fd)
|
||||||
}
|
}
|
||||||
fn box_clone(&self) -> Box<dyn OsApi> {
|
fn box_clone(&self) -> Box<dyn ServerOsApi> {
|
||||||
|
Box::new((*self).clone())
|
||||||
|
}
|
||||||
|
fn kill(&mut self, pid: RawFd) -> Result<(), nix::Error> {
|
||||||
|
kill(Pid::from_raw(pid), Some(Signal::SIGINT)).unwrap();
|
||||||
|
waitpid(Pid::from_raw(pid), None).unwrap();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for Box<dyn ServerOsApi> {
|
||||||
|
fn clone(&self) -> Box<dyn ServerOsApi> {
|
||||||
|
self.box_clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_server_os_input() -> ServerOsInputOutput {
|
||||||
|
let current_termios = termios::tcgetattr(0).unwrap();
|
||||||
|
let orig_termios = Arc::new(Mutex::new(current_termios));
|
||||||
|
ServerOsInputOutput { orig_termios }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub enum ServerOsApiInstruction {
|
||||||
|
SetTerminalSizeUsingFd(RawFd, u16, u16),
|
||||||
|
WriteToTtyStdin(RawFd, Vec<u8>),
|
||||||
|
TcDrain(RawFd),
|
||||||
|
Exit,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ClientOsInputOutput {
|
||||||
|
orig_termios: Arc<Mutex<termios::Termios>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `OsApi` trait represents an abstract interface to the features of an operating system that
|
||||||
|
/// Zellij requires.
|
||||||
|
pub trait ClientOsApi: Send + Sync {
|
||||||
|
/// Returns the size of the terminal associated to file descriptor `fd`.
|
||||||
|
fn get_terminal_size_using_fd(&self, fd: RawFd) -> PositionAndSize;
|
||||||
|
/// Set the terminal associated to file descriptor `fd` to
|
||||||
|
/// [raw mode](https://en.wikipedia.org/wiki/Terminal_mode).
|
||||||
|
fn set_raw_mode(&mut self, fd: RawFd);
|
||||||
|
/// Set the terminal associated to file descriptor `fd` to
|
||||||
|
/// [cooked mode](https://en.wikipedia.org/wiki/Terminal_mode).
|
||||||
|
fn unset_raw_mode(&mut self, fd: RawFd);
|
||||||
|
/// Returns the writer that allows writing to standard output.
|
||||||
|
fn get_stdout_writer(&self) -> Box<dyn io::Write>;
|
||||||
|
/// Returns the raw contents of standard input.
|
||||||
|
fn read_from_stdin(&self) -> Vec<u8>;
|
||||||
|
/// Returns a [`Box`] pointer to this [`OsApi`] struct.
|
||||||
|
fn box_clone(&self) -> Box<dyn ClientOsApi>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ClientOsApi for ClientOsInputOutput {
|
||||||
|
fn get_terminal_size_using_fd(&self, fd: RawFd) -> PositionAndSize {
|
||||||
|
get_terminal_size_using_fd(fd)
|
||||||
|
}
|
||||||
|
fn set_raw_mode(&mut self, fd: RawFd) {
|
||||||
|
into_raw_mode(fd);
|
||||||
|
}
|
||||||
|
fn unset_raw_mode(&mut self, fd: RawFd) {
|
||||||
|
let orig_termios = self.orig_termios.lock().unwrap();
|
||||||
|
unset_raw_mode(fd, orig_termios.clone());
|
||||||
|
}
|
||||||
|
fn box_clone(&self) -> Box<dyn ClientOsApi> {
|
||||||
Box::new((*self).clone())
|
Box::new((*self).clone())
|
||||||
}
|
}
|
||||||
fn read_from_stdin(&self) -> Vec<u8> {
|
fn read_from_stdin(&self) -> Vec<u8> {
|
||||||
|
|
@ -239,51 +280,16 @@ impl OsApi for OsInputOutput {
|
||||||
let stdout = ::std::io::stdout();
|
let stdout = ::std::io::stdout();
|
||||||
Box::new(stdout)
|
Box::new(stdout)
|
||||||
}
|
}
|
||||||
fn kill(&mut self, pid: RawFd) -> Result<(), nix::Error> {
|
|
||||||
// TODO:
|
|
||||||
// Ideally, we should be using SIGINT rather than SIGKILL here, but there are cases in which
|
|
||||||
// the terminal we're trying to kill hangs on SIGINT and so all the app gets stuck
|
|
||||||
// that's why we're sending SIGKILL here
|
|
||||||
// A better solution would be to send SIGINT here and not wait for it, and then have
|
|
||||||
// a background thread do the waitpid stuff and send SIGKILL if the process is stuck
|
|
||||||
kill(Pid::from_raw(pid), Some(Signal::SIGKILL)).unwrap();
|
|
||||||
waitpid(Pid::from_raw(pid), None).unwrap();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn receive_sigwinch(&self, cb: Box<dyn Fn()>) {
|
|
||||||
let mut signals = Signals::new(&[SIGWINCH, SIGTERM, SIGINT, SIGQUIT]).unwrap();
|
|
||||||
for signal in signals.forever() {
|
|
||||||
match signal {
|
|
||||||
SIGWINCH => {
|
|
||||||
cb();
|
|
||||||
}
|
|
||||||
SIGTERM | SIGINT | SIGQUIT => {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn load_palette(&self) -> Palette {
|
|
||||||
default_palette()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
impl Clone for Box<dyn ClientOsApi> {
|
||||||
pub enum OsApiInstruction {
|
fn clone(&self) -> Box<dyn ClientOsApi> {
|
||||||
SetTerminalSizeUsingFd(RawFd, u16, u16),
|
|
||||||
WriteToTtyStdin(RawFd, Vec<u8>),
|
|
||||||
TcDrain(RawFd),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for Box<dyn OsApi> {
|
|
||||||
fn clone(&self) -> Box<dyn OsApi> {
|
|
||||||
self.box_clone()
|
self.box_clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_os_input() -> OsInputOutput {
|
pub fn get_client_os_input() -> ClientOsInputOutput {
|
||||||
let current_termios = termios::tcgetattr(0).unwrap();
|
let current_termios = termios::tcgetattr(0).unwrap();
|
||||||
let orig_termios = Arc::new(Mutex::new(current_termios));
|
let orig_termios = Arc::new(Mutex::new(current_termios));
|
||||||
OsInputOutput { orig_termios }
|
ClientOsInputOutput { orig_termios }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use super::{IpcSenderWithContext, ScreenInstruction, OPENCALLS};
|
use super::{IpcSenderWithContext, ScreenInstruction, OPENCALLS};
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
use crate::os_input_output::OsApi;
|
use crate::os_input_output::ServerOsApi;
|
||||||
use crate::utils::logging::debug_to_file;
|
use crate::utils::logging::debug_to_file;
|
||||||
use crate::{
|
use crate::{
|
||||||
common::ServerInstruction,
|
common::ServerInstruction,
|
||||||
|
|
@ -22,11 +22,11 @@ use crate::{
|
||||||
|
|
||||||
pub struct ReadFromPid {
|
pub struct ReadFromPid {
|
||||||
pid: RawFd,
|
pid: RawFd,
|
||||||
os_input: Box<dyn OsApi>,
|
os_input: Box<dyn ServerOsApi>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadFromPid {
|
impl ReadFromPid {
|
||||||
pub fn new(pid: &RawFd, os_input: Box<dyn OsApi>) -> ReadFromPid {
|
pub fn new(pid: &RawFd, os_input: Box<dyn ServerOsApi>) -> ReadFromPid {
|
||||||
ReadFromPid {
|
ReadFromPid {
|
||||||
pid: *pid,
|
pid: *pid,
|
||||||
os_input,
|
os_input,
|
||||||
|
|
@ -187,7 +187,7 @@ pub enum PtyInstruction {
|
||||||
pub struct PtyBus {
|
pub struct PtyBus {
|
||||||
pub receive_pty_instructions: Receiver<(PtyInstruction, ErrorContext)>,
|
pub receive_pty_instructions: Receiver<(PtyInstruction, ErrorContext)>,
|
||||||
pub id_to_child_pid: HashMap<RawFd, RawFd>,
|
pub id_to_child_pid: HashMap<RawFd, RawFd>,
|
||||||
os_input: Box<dyn OsApi>,
|
os_input: Box<dyn ServerOsApi>,
|
||||||
debug_to_file: bool,
|
debug_to_file: bool,
|
||||||
task_handles: HashMap<RawFd, JoinHandle<()>>,
|
task_handles: HashMap<RawFd, JoinHandle<()>>,
|
||||||
pub send_server_instructions: IpcSenderWithContext,
|
pub send_server_instructions: IpcSenderWithContext,
|
||||||
|
|
@ -195,7 +195,7 @@ pub struct PtyBus {
|
||||||
|
|
||||||
fn stream_terminal_bytes(
|
fn stream_terminal_bytes(
|
||||||
pid: RawFd,
|
pid: RawFd,
|
||||||
os_input: Box<dyn OsApi>,
|
os_input: Box<dyn ServerOsApi>,
|
||||||
mut send_server_instructions: IpcSenderWithContext,
|
mut send_server_instructions: IpcSenderWithContext,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
) -> JoinHandle<()> {
|
) -> JoinHandle<()> {
|
||||||
|
|
@ -274,7 +274,7 @@ fn stream_terminal_bytes(
|
||||||
impl PtyBus {
|
impl PtyBus {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
receive_pty_instructions: Receiver<(PtyInstruction, ErrorContext)>,
|
receive_pty_instructions: Receiver<(PtyInstruction, ErrorContext)>,
|
||||||
os_input: Box<dyn OsApi>,
|
os_input: Box<dyn ServerOsApi>,
|
||||||
send_server_instructions: IpcSenderWithContext,
|
send_server_instructions: IpcSenderWithContext,
|
||||||
debug_to_file: bool,
|
debug_to_file: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use std::path::PathBuf;
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
|
|
||||||
use super::{AppInstruction, SenderWithContext};
|
use super::{AppInstruction, SenderWithContext};
|
||||||
use crate::os_input_output::OsApi;
|
use crate::os_input_output::ClientOsApi;
|
||||||
use crate::panes::PositionAndSize;
|
use crate::panes::PositionAndSize;
|
||||||
use crate::pty_bus::{PtyInstruction, VteBytes};
|
use crate::pty_bus::{PtyInstruction, VteBytes};
|
||||||
use crate::tab::Tab;
|
use crate::tab::Tab;
|
||||||
|
|
@ -78,10 +78,7 @@ pub struct Screen {
|
||||||
/// The index of this [`Screen`]'s active [`Tab`].
|
/// The index of this [`Screen`]'s active [`Tab`].
|
||||||
active_tab_index: Option<usize>,
|
active_tab_index: Option<usize>,
|
||||||
/// The [`OsApi`] this [`Screen`] uses.
|
/// The [`OsApi`] this [`Screen`] uses.
|
||||||
os_api: Box<dyn OsApi>,
|
os_api: Box<dyn ClientOsApi>,
|
||||||
mode_info: ModeInfo,
|
|
||||||
input_mode: InputMode,
|
|
||||||
colors: Palette,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen {
|
impl Screen {
|
||||||
|
|
@ -93,7 +90,7 @@ impl Screen {
|
||||||
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
send_plugin_instructions: SenderWithContext<PluginInstruction>,
|
||||||
send_app_instructions: SenderWithContext<AppInstruction>,
|
send_app_instructions: SenderWithContext<AppInstruction>,
|
||||||
full_screen_ws: &PositionAndSize,
|
full_screen_ws: &PositionAndSize,
|
||||||
os_api: Box<dyn OsApi>,
|
os_api: Box<dyn ClientOsApi>,
|
||||||
max_panes: Option<usize>,
|
max_panes: Option<usize>,
|
||||||
mode_info: ModeInfo,
|
mode_info: ModeInfo,
|
||||||
input_mode: InputMode,
|
input_mode: InputMode,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ use structopt::StructOpt;
|
||||||
|
|
||||||
use crate::cli::CliArgs;
|
use crate::cli::CliArgs;
|
||||||
use crate::command_is_executing::CommandIsExecuting;
|
use crate::command_is_executing::CommandIsExecuting;
|
||||||
use crate::os_input_output::get_os_input;
|
use crate::os_input_output::get_client_os_input;
|
||||||
|
use crate::pty_bus::VteEvent;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
|
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
|
||||||
logging::*,
|
logging::*,
|
||||||
|
|
@ -86,7 +87,7 @@ pub fn main() {
|
||||||
.send(ServerInstruction::OpenFile(file_to_open))
|
.send(ServerInstruction::OpenFile(file_to_open))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else {
|
} else {
|
||||||
let os_input = get_os_input();
|
let os_input = get_client_os_input();
|
||||||
atomic_create_dir(ZELLIJ_TMP_DIR).unwrap();
|
atomic_create_dir(ZELLIJ_TMP_DIR).unwrap();
|
||||||
atomic_create_dir(ZELLIJ_TMP_LOG_DIR).unwrap();
|
atomic_create_dir(ZELLIJ_TMP_LOG_DIR).unwrap();
|
||||||
start(Box::new(os_input), opts, config);
|
start(Box::new(os_input), opts, config);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::common::{
|
||||||
ServerInstruction,
|
ServerInstruction,
|
||||||
};
|
};
|
||||||
use crate::errors::{ContextType, ErrorContext, OsContext, PtyContext};
|
use crate::errors::{ContextType, ErrorContext, OsContext, PtyContext};
|
||||||
use crate::os_input_output::{OsApi, OsApiInstruction};
|
use crate::os_input_output::{get_server_os_input, ServerOsApi, ServerOsApiInstruction};
|
||||||
use crate::panes::PaneId;
|
use crate::panes::PaneId;
|
||||||
use crate::pty_bus::{PtyBus, PtyInstruction};
|
use crate::pty_bus::{PtyBus, PtyInstruction};
|
||||||
use crate::screen::ScreenInstruction;
|
use crate::screen::ScreenInstruction;
|
||||||
|
|
@ -14,9 +14,10 @@ use std::path::PathBuf;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHandle<()>, String) {
|
pub fn start_server(opts: CliArgs) -> (thread::JoinHandle<()>, String) {
|
||||||
let (send_pty_instructions, receive_pty_instructions): ChannelWithContext<PtyInstruction> =
|
let (send_pty_instructions, receive_pty_instructions): ChannelWithContext<PtyInstruction> =
|
||||||
channel();
|
channel();
|
||||||
|
let os_input = Box::new(get_server_os_input());
|
||||||
let mut send_pty_instructions = SenderWithContext::new(
|
let mut send_pty_instructions = SenderWithContext::new(
|
||||||
ErrorContext::new(),
|
ErrorContext::new(),
|
||||||
SenderType::Sender(send_pty_instructions),
|
SenderType::Sender(send_pty_instructions),
|
||||||
|
|
@ -30,8 +31,9 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
let (server_name, server_buffer) = SharedRingBuffer::create_temp(8192).unwrap();
|
let (server_name, server_buffer) = SharedRingBuffer::create_temp(8192).unwrap();
|
||||||
|
|
||||||
let (send_os_instructions, receive_os_instructions): ChannelWithContext<OsApiInstruction> =
|
let (send_os_instructions, receive_os_instructions): ChannelWithContext<
|
||||||
channel();
|
ServerOsApiInstruction,
|
||||||
|
> = channel();
|
||||||
let mut send_os_instructions = SenderWithContext::new(
|
let mut send_os_instructions = SenderWithContext::new(
|
||||||
ErrorContext::new(),
|
ErrorContext::new(),
|
||||||
SenderType::Sender(send_os_instructions),
|
SenderType::Sender(send_os_instructions),
|
||||||
|
|
@ -131,22 +133,23 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
|
||||||
.expect("failed to receive an event on the channel");
|
.expect("failed to receive an event on the channel");
|
||||||
err_ctx.add_call(ContextType::Os(OsContext::from(&event)));
|
err_ctx.add_call(ContextType::Os(OsContext::from(&event)));
|
||||||
match event {
|
match event {
|
||||||
OsApiInstruction::SetTerminalSizeUsingFd(fd, cols, rows) => {
|
ServerOsApiInstruction::SetTerminalSizeUsingFd(fd, cols, rows) => {
|
||||||
os_input.set_terminal_size_using_fd(fd, cols, rows);
|
os_input.set_terminal_size_using_fd(fd, cols, rows);
|
||||||
}
|
}
|
||||||
OsApiInstruction::WriteToTtyStdin(fd, mut buf) => {
|
ServerOsApiInstruction::WriteToTtyStdin(fd, mut buf) => {
|
||||||
let slice = buf.as_mut_slice();
|
let slice = buf.as_mut_slice();
|
||||||
os_input.write_to_tty_stdin(fd, slice).unwrap();
|
os_input.write_to_tty_stdin(fd, slice).unwrap();
|
||||||
}
|
}
|
||||||
OsApiInstruction::TcDrain(fd) => {
|
ServerOsApiInstruction::TcDrain(fd) => {
|
||||||
os_input.tcdrain(fd).unwrap();
|
os_input.tcdrain(fd).unwrap();
|
||||||
}
|
}
|
||||||
|
ServerOsApiInstruction::Exit => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let join_handle = thread::Builder::new()
|
let server_handle = thread::Builder::new()
|
||||||
.name("ipc_server".to_string())
|
.name("ipc_server".to_string())
|
||||||
.spawn({
|
.spawn({
|
||||||
let recv_server_instructions = IpcReceiver::new(server_buffer);
|
let recv_server_instructions = IpcReceiver::new(server_buffer);
|
||||||
|
|
@ -158,6 +161,7 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
|
||||||
recv_server_instructions.recv().unwrap();
|
recv_server_instructions.recv().unwrap();
|
||||||
err_ctx.add_call(ContextType::IPCServer);
|
err_ctx.add_call(ContextType::IPCServer);
|
||||||
send_pty_instructions.update(err_ctx);
|
send_pty_instructions.update(err_ctx);
|
||||||
|
send_os_instructions.update(err_ctx);
|
||||||
if send_client_instructions.len() == 1 {
|
if send_client_instructions.len() == 1 {
|
||||||
send_client_instructions[0].update(err_ctx);
|
send_client_instructions[0].update(err_ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -213,6 +217,7 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
|
||||||
}
|
}
|
||||||
ServerInstruction::Exit => {
|
ServerInstruction::Exit => {
|
||||||
let _ = send_pty_instructions.send(PtyInstruction::Exit);
|
let _ = send_pty_instructions.send(PtyInstruction::Exit);
|
||||||
|
let _ = send_os_instructions.send(ServerOsApiInstruction::Exit);
|
||||||
let _ = pty_thread.join();
|
let _ = pty_thread.join();
|
||||||
let _ = os_thread.join();
|
let _ = os_thread.join();
|
||||||
let _ = send_client_instructions[0].send(ClientInstruction::Exit);
|
let _ = send_client_instructions[0].send(ClientInstruction::Exit);
|
||||||
|
|
@ -222,5 +227,5 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> (thread::JoinHan
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
(join_handle, server_name)
|
(server_handle, server_name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use std::path::PathBuf;
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use crate::os_input_output::OsApi;
|
use crate::os_input_output::{ClientOsApi, ServerOsApi};
|
||||||
use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes};
|
use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes};
|
||||||
use crate::utils::shared::default_palette;
|
use crate::utils::shared::default_palette;
|
||||||
use zellij_tile::data::Palette;
|
use zellij_tile::data::Palette;
|
||||||
|
|
@ -116,7 +116,7 @@ impl FakeInputOutput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OsApi for FakeInputOutput {
|
impl ClientOsApi for FakeInputOutput {
|
||||||
fn get_terminal_size_using_fd(&self, pid: RawFd) -> PositionAndSize {
|
fn get_terminal_size_using_fd(&self, pid: RawFd) -> PositionAndSize {
|
||||||
if let Some(new_position_and_size) = self.sigwinch_event {
|
if let Some(new_position_and_size) = self.sigwinch_event {
|
||||||
let (lock, _cvar) = &*self.should_trigger_sigwinch;
|
let (lock, _cvar) = &*self.should_trigger_sigwinch;
|
||||||
|
|
@ -129,6 +129,42 @@ impl OsApi for FakeInputOutput {
|
||||||
let winsize = win_sizes.get(&pid).unwrap();
|
let winsize = win_sizes.get(&pid).unwrap();
|
||||||
*winsize
|
*winsize
|
||||||
}
|
}
|
||||||
|
fn set_raw_mode(&mut self, pid: RawFd) {
|
||||||
|
self.io_events
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.push(IoEvent::IntoRawMode(pid));
|
||||||
|
}
|
||||||
|
fn unset_raw_mode(&mut self, pid: RawFd) {
|
||||||
|
self.io_events
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.push(IoEvent::UnsetRawMode(pid));
|
||||||
|
}
|
||||||
|
fn box_clone(&self) -> Box<dyn ClientOsApi> {
|
||||||
|
Box::new((*self).clone())
|
||||||
|
}
|
||||||
|
fn read_from_stdin(&self) -> Vec<u8> {
|
||||||
|
loop {
|
||||||
|
let last_snapshot_time = { *self.last_snapshot_time.lock().unwrap() };
|
||||||
|
if last_snapshot_time.elapsed() > MIN_TIME_BETWEEN_SNAPSHOTS {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
::std::thread::sleep(MIN_TIME_BETWEEN_SNAPSHOTS - last_snapshot_time.elapsed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.stdin_commands
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.pop_front()
|
||||||
|
.unwrap_or(vec![])
|
||||||
|
}
|
||||||
|
fn get_stdout_writer(&self) -> Box<dyn Write> {
|
||||||
|
Box::new(self.stdout_writer.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ServerOsApi for FakeInputOutput {
|
||||||
fn set_terminal_size_using_fd(&mut self, pid: RawFd, cols: u16, rows: u16) {
|
fn set_terminal_size_using_fd(&mut self, pid: RawFd, cols: u16, rows: u16) {
|
||||||
let terminal_input = self
|
let terminal_input = self
|
||||||
.possible_tty_inputs
|
.possible_tty_inputs
|
||||||
|
|
@ -143,23 +179,21 @@ impl OsApi for FakeInputOutput {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.push(IoEvent::SetTerminalSizeUsingFd(pid, cols, rows));
|
.push(IoEvent::SetTerminalSizeUsingFd(pid, cols, rows));
|
||||||
}
|
}
|
||||||
fn set_raw_mode(&mut self, pid: RawFd) {
|
|
||||||
self.io_events
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.push(IoEvent::IntoRawMode(pid));
|
|
||||||
}
|
|
||||||
fn unset_raw_mode(&mut self, pid: RawFd) {
|
|
||||||
self.io_events
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.push(IoEvent::UnsetRawMode(pid));
|
|
||||||
}
|
|
||||||
fn spawn_terminal(&mut self, _file_to_open: Option<PathBuf>) -> (RawFd, RawFd) {
|
fn spawn_terminal(&mut self, _file_to_open: Option<PathBuf>) -> (RawFd, RawFd) {
|
||||||
let next_terminal_id = self.stdin_writes.lock().unwrap().keys().len() as RawFd + 1;
|
let next_terminal_id = self.stdin_writes.lock().unwrap().keys().len() as RawFd + 1;
|
||||||
self.add_terminal(next_terminal_id);
|
self.add_terminal(next_terminal_id);
|
||||||
(next_terminal_id as i32, next_terminal_id + 1000) // secondary number is arbitrary here
|
(next_terminal_id as i32, next_terminal_id + 1000) // secondary number is arbitrary here
|
||||||
}
|
}
|
||||||
|
fn write_to_tty_stdin(&mut self, pid: RawFd, buf: &mut [u8]) -> Result<usize, nix::Error> {
|
||||||
|
let mut stdin_writes = self.stdin_writes.lock().unwrap();
|
||||||
|
let write_buffer = stdin_writes.get_mut(&pid).unwrap();
|
||||||
|
let mut bytes_written = 0;
|
||||||
|
for byte in buf {
|
||||||
|
bytes_written += 1;
|
||||||
|
write_buffer.push(*byte);
|
||||||
|
}
|
||||||
|
Ok(bytes_written)
|
||||||
|
}
|
||||||
fn read_from_tty_stdout(&mut self, pid: RawFd, buf: &mut [u8]) -> Result<usize, nix::Error> {
|
fn read_from_tty_stdout(&mut self, pid: RawFd, buf: &mut [u8]) -> Result<usize, nix::Error> {
|
||||||
let mut read_buffers = self.read_buffers.lock().unwrap();
|
let mut read_buffers = self.read_buffers.lock().unwrap();
|
||||||
let mut bytes_read = 0;
|
let mut bytes_read = 0;
|
||||||
|
|
@ -177,21 +211,11 @@ impl OsApi for FakeInputOutput {
|
||||||
None => Err(nix::Error::Sys(nix::errno::Errno::EAGAIN)),
|
None => Err(nix::Error::Sys(nix::errno::Errno::EAGAIN)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn write_to_tty_stdin(&mut self, pid: RawFd, buf: &mut [u8]) -> Result<usize, nix::Error> {
|
|
||||||
let mut stdin_writes = self.stdin_writes.lock().unwrap();
|
|
||||||
let write_buffer = stdin_writes.get_mut(&pid).unwrap();
|
|
||||||
let mut bytes_written = 0;
|
|
||||||
for byte in buf {
|
|
||||||
bytes_written += 1;
|
|
||||||
write_buffer.push(*byte);
|
|
||||||
}
|
|
||||||
Ok(bytes_written)
|
|
||||||
}
|
|
||||||
fn tcdrain(&mut self, pid: RawFd) -> Result<(), nix::Error> {
|
fn tcdrain(&mut self, pid: RawFd) -> Result<(), nix::Error> {
|
||||||
self.io_events.lock().unwrap().push(IoEvent::TcDrain(pid));
|
self.io_events.lock().unwrap().push(IoEvent::TcDrain(pid));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn box_clone(&self) -> Box<dyn OsApi> {
|
fn box_clone(&self) -> Box<dyn ServerOsApi> {
|
||||||
Box::new((*self).clone())
|
Box::new((*self).clone())
|
||||||
}
|
}
|
||||||
fn read_from_stdin(&self) -> Vec<u8> {
|
fn read_from_stdin(&self) -> Vec<u8> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue