mirror of
https://github.com/zellij-org/zellij.git
synced 2024-12-18 14:41:46 +03:00
try fixes
This commit is contained in:
parent
685e2eef0c
commit
7beb246250
@ -64,7 +64,7 @@ pub fn handle_panic(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if thread == "main" {
|
if thread == "main" {
|
||||||
println!("{}", backtrace);
|
eprintln!("{}", backtrace);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
} else {
|
} else {
|
||||||
send_app_instructions
|
send_app_instructions
|
||||||
|
@ -24,6 +24,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::cli::CliArgs;
|
use crate::cli::CliArgs;
|
||||||
|
use crate::layout::Layout;
|
||||||
use crate::server::start_server;
|
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};
|
||||||
@ -140,8 +141,11 @@ impl IpcSenderWithContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&mut self, msg: ApiCommand) -> std::io::Result<()> {
|
pub fn send(&mut self, msg: ApiCommand) -> std::io::Result<()> {
|
||||||
|
eprintln!("Ipcsender sending {:?}", msg);
|
||||||
let command = bincode::serialize(&(self.err_ctx, msg)).unwrap();
|
let command = bincode::serialize(&(self.err_ctx, msg)).unwrap();
|
||||||
self.sender.write_all(&command)
|
UnixStream::connect(MOSAIC_IPC_PIPE)
|
||||||
|
.unwrap()
|
||||||
|
.write_all(&command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +399,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
|
|||||||
ScreenInstruction::SwitchTabPrev => screen.switch_tab_prev(),
|
ScreenInstruction::SwitchTabPrev => screen.switch_tab_prev(),
|
||||||
ScreenInstruction::CloseTab => screen.close_tab(),
|
ScreenInstruction::CloseTab => screen.close_tab(),
|
||||||
ScreenInstruction::ApplyLayout((layout, new_pane_pids)) => {
|
ScreenInstruction::ApplyLayout((layout, new_pane_pids)) => {
|
||||||
screen.apply_layout(layout, new_pane_pids);
|
screen.apply_layout(Layout::new(layout), new_pane_pids);
|
||||||
command_is_executing.done_opening_new_pane();
|
command_is_executing.done_opening_new_pane();
|
||||||
}
|
}
|
||||||
ScreenInstruction::GoToTab(tab_index) => {
|
ScreenInstruction::GoToTab(tab_index) => {
|
||||||
@ -560,22 +564,20 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
|
|||||||
}
|
}
|
||||||
AppInstruction::Error(backtrace) => {
|
AppInstruction::Error(backtrace) => {
|
||||||
let _ = send_server_instructions.send(ApiCommand::Quit);
|
let _ = send_server_instructions.send(ApiCommand::Quit);
|
||||||
let _ = ipc_thread.join();
|
//let _ = ipc_thread.join();
|
||||||
|
//IpcSenderWithContext::new().send(ApiCommand::Quit);
|
||||||
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
|
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
|
||||||
let _ = screen_thread.join();
|
let _ = screen_thread.join();
|
||||||
let _ = send_plugin_instructions.send(PluginInstruction::Quit);
|
let _ = send_plugin_instructions.send(PluginInstruction::Quit);
|
||||||
let _ = wasm_thread.join();
|
let _ = wasm_thread.join();
|
||||||
os_input.unset_raw_mode(0);
|
os_input.unset_raw_mode(0);
|
||||||
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1);
|
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1);
|
||||||
let restore_snapshot = "\u{1b}[?1049l";
|
let error = format!("{}\n{}", goto_start_of_last_line, backtrace);
|
||||||
let error = format!(
|
//let _ = os_input
|
||||||
"{}\n{}{}",
|
// .get_stdout_writer()
|
||||||
goto_start_of_last_line, restore_snapshot, backtrace
|
// .write(error.as_bytes())
|
||||||
);
|
// .unwrap();
|
||||||
let _ = os_input
|
eprintln!("{}", error);
|
||||||
.get_stdout_writer()
|
|
||||||
.write(error.as_bytes())
|
|
||||||
.unwrap();
|
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
AppInstruction::ToScreen(instruction) => {
|
AppInstruction::ToScreen(instruction) => {
|
||||||
@ -591,7 +593,8 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let _ = send_server_instructions.send(ApiCommand::Quit);
|
let _ = send_server_instructions.send(ApiCommand::Quit);
|
||||||
let _ = ipc_thread.join().unwrap();
|
//let _ = ipc_thread.join().unwrap();
|
||||||
|
//IpcSenderWithContext::new().send(ApiCommand::Quit);
|
||||||
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
|
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
|
||||||
screen_thread.join().unwrap();
|
screen_thread.join().unwrap();
|
||||||
let _ = send_plugin_instructions.send(PluginInstruction::Quit);
|
let _ = send_plugin_instructions.send(PluginInstruction::Quit);
|
||||||
|
@ -292,7 +292,8 @@ impl PtyBus {
|
|||||||
self.id_to_child_pid.insert(pid_primary, pid_secondary);
|
self.id_to_child_pid.insert(pid_primary, pid_secondary);
|
||||||
pid_primary
|
pid_primary
|
||||||
}
|
}
|
||||||
pub fn spawn_terminals_for_layout(&mut self, layout: Layout, err_ctx: ErrorContext) {
|
pub fn spawn_terminals_for_layout(&mut self, layout_path: PathBuf, err_ctx: ErrorContext) {
|
||||||
|
let layout = Layout::new(layout_path.clone());
|
||||||
let total_panes = layout.total_terminal_panes();
|
let total_panes = layout.total_terminal_panes();
|
||||||
let mut new_pane_pids = vec![];
|
let mut new_pane_pids = vec![];
|
||||||
for _ in 0..total_panes {
|
for _ in 0..total_panes {
|
||||||
@ -302,7 +303,7 @@ impl PtyBus {
|
|||||||
}
|
}
|
||||||
self.send_server_instructions
|
self.send_server_instructions
|
||||||
.send(ApiCommand::ToScreen(ScreenInstruction::ApplyLayout((
|
.send(ApiCommand::ToScreen(ScreenInstruction::ApplyLayout((
|
||||||
layout,
|
layout_path,
|
||||||
new_pane_pids.clone(),
|
new_pane_pids.clone(),
|
||||||
))))
|
))))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use std::str;
|
use std::path::PathBuf;
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
|
|
||||||
use super::{AppInstruction, SenderWithContext};
|
use super::{AppInstruction, SenderWithContext};
|
||||||
@ -48,7 +48,7 @@ pub enum ScreenInstruction {
|
|||||||
SetMaxHeight(PaneId, usize),
|
SetMaxHeight(PaneId, usize),
|
||||||
SetInvisibleBorders(PaneId, bool),
|
SetInvisibleBorders(PaneId, bool),
|
||||||
ClosePane(PaneId),
|
ClosePane(PaneId),
|
||||||
ApplyLayout((Layout, Vec<RawFd>)),
|
ApplyLayout((PathBuf, Vec<RawFd>)),
|
||||||
NewTab(RawFd),
|
NewTab(RawFd),
|
||||||
SwitchTabNext,
|
SwitchTabNext,
|
||||||
SwitchTabPrev,
|
SwitchTabPrev,
|
||||||
|
@ -39,7 +39,7 @@ pub fn start_server(
|
|||||||
let default_layout = Some(PathBuf::from("default"));
|
let default_layout = Some(PathBuf::from("default"));
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
let default_layout = None;
|
let default_layout = None;
|
||||||
let maybe_layout = opts.layout.or(default_layout).map(Layout::new);
|
let maybe_layout = opts.layout.or(default_layout);
|
||||||
|
|
||||||
let send_server_instructions = IpcSenderWithContext::new();
|
let send_server_instructions = IpcSenderWithContext::new();
|
||||||
|
|
||||||
@ -90,15 +90,15 @@ pub fn start_server(
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
PtyInstruction::NewTab => {
|
PtyInstruction::NewTab => {
|
||||||
if let Some(layout) = maybe_layout.clone() {
|
//if let Some(layout) = maybe_layout.clone() {
|
||||||
pty_bus.spawn_terminals_for_layout(layout, err_ctx);
|
// pty_bus.spawn_terminals_for_layout(layout, err_ctx);
|
||||||
} else {
|
//} else {
|
||||||
let pid = pty_bus.spawn_terminal(None);
|
let pid = pty_bus.spawn_terminal(None);
|
||||||
pty_bus
|
pty_bus
|
||||||
.send_server_instructions
|
.send_server_instructions
|
||||||
.send(ApiCommand::ToScreen(ScreenInstruction::NewTab(pid)))
|
.send(ApiCommand::ToScreen(ScreenInstruction::NewTab(pid)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
PtyInstruction::ClosePane(id) => {
|
PtyInstruction::ClosePane(id) => {
|
||||||
pty_bus.close_pane(id, err_ctx);
|
pty_bus.close_pane(id, err_ctx);
|
||||||
@ -120,64 +120,15 @@ pub fn start_server(
|
|||||||
.name("ipc_server".to_string())
|
.name("ipc_server".to_string())
|
||||||
.spawn({
|
.spawn({
|
||||||
move || {
|
move || {
|
||||||
|
let mut threads = vec![];
|
||||||
for stream in listener.incoming() {
|
for stream in listener.incoming() {
|
||||||
match stream {
|
match stream {
|
||||||
Ok(mut stream) => {
|
Ok(stream) => {
|
||||||
let mut buffer = [0; 65535]; // TODO: more accurate
|
let send_app_instructions = send_app_instructions.clone();
|
||||||
let _ = stream
|
let send_pty_instructions = send_pty_instructions.clone();
|
||||||
.read(&mut buffer)
|
threads.push(thread::spawn(move || {
|
||||||
.expect("failed to parse ipc message");
|
handle_stream(send_pty_instructions, send_app_instructions, stream);
|
||||||
let (mut err_ctx, decoded): (ErrorContext, ApiCommand) =
|
}));
|
||||||
bincode::deserialize(&buffer)
|
|
||||||
.expect("failed to deserialize ipc message");
|
|
||||||
err_ctx.add_call(ContextType::IPCServer);
|
|
||||||
send_pty_instructions.update(err_ctx);
|
|
||||||
send_app_instructions.update(err_ctx);
|
|
||||||
|
|
||||||
match decoded {
|
|
||||||
ApiCommand::OpenFile(file_name) => {
|
|
||||||
let path = PathBuf::from(file_name);
|
|
||||||
send_pty_instructions
|
|
||||||
.send(PtyInstruction::SpawnTerminal(Some(path)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
ApiCommand::SplitHorizontally => {
|
|
||||||
send_pty_instructions
|
|
||||||
.send(PtyInstruction::SpawnTerminalHorizontally(None))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
ApiCommand::SplitVertically => {
|
|
||||||
send_pty_instructions
|
|
||||||
.send(PtyInstruction::SpawnTerminalVertically(None))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
ApiCommand::MoveFocus => {
|
|
||||||
send_app_instructions
|
|
||||||
.send(AppInstruction::ToScreen(
|
|
||||||
ScreenInstruction::MoveFocus,
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
ApiCommand::ToPty(instruction) => {
|
|
||||||
send_pty_instructions.send(instruction).unwrap();
|
|
||||||
}
|
|
||||||
ApiCommand::ToScreen(instruction) => {
|
|
||||||
send_app_instructions
|
|
||||||
.send(AppInstruction::ToScreen(instruction))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
ApiCommand::ClosePluginPane(pid) => {
|
|
||||||
send_app_instructions
|
|
||||||
.send(AppInstruction::ToPlugin(PluginInstruction::Unload(
|
|
||||||
pid,
|
|
||||||
)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
ApiCommand::Quit => {
|
|
||||||
send_pty_instructions.send(PtyInstruction::Quit).unwrap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
panic!("err {:?}", err);
|
panic!("err {:?}", err);
|
||||||
@ -186,7 +137,73 @@ pub fn start_server(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let _ = pty_thread.join();
|
let _ = pty_thread.join();
|
||||||
|
for t in threads {
|
||||||
|
t.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_stream(
|
||||||
|
mut send_pty_instructions: SenderWithContext<PtyInstruction>,
|
||||||
|
mut send_app_instructions: SenderWithContext<AppInstruction>,
|
||||||
|
mut stream: std::os::unix::net::UnixStream,
|
||||||
|
) {
|
||||||
|
//let mut buffer = [0; 65535]; // TODO: more accurate
|
||||||
|
let mut buffer = String::new();
|
||||||
|
loop {
|
||||||
|
let bytes = stream
|
||||||
|
.read_to_string(&mut buffer)
|
||||||
|
.expect("failed to parse ipc message");
|
||||||
|
//let astream = stream.try_clone().unwrap();
|
||||||
|
let (mut err_ctx, decoded): (ErrorContext, ApiCommand) =
|
||||||
|
bincode::deserialize(buffer.as_bytes()).expect("failed to deserialize ipc message");
|
||||||
|
err_ctx.add_call(ContextType::IPCServer);
|
||||||
|
send_pty_instructions.update(err_ctx);
|
||||||
|
send_app_instructions.update(err_ctx);
|
||||||
|
|
||||||
|
eprintln!("Server received {:?}", decoded);
|
||||||
|
|
||||||
|
match decoded {
|
||||||
|
ApiCommand::OpenFile(file_name) => {
|
||||||
|
let path = PathBuf::from(file_name);
|
||||||
|
send_pty_instructions
|
||||||
|
.send(PtyInstruction::SpawnTerminal(Some(path)))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
ApiCommand::SplitHorizontally => {
|
||||||
|
send_pty_instructions
|
||||||
|
.send(PtyInstruction::SpawnTerminalHorizontally(None))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
ApiCommand::SplitVertically => {
|
||||||
|
send_pty_instructions
|
||||||
|
.send(PtyInstruction::SpawnTerminalVertically(None))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
ApiCommand::MoveFocus => {
|
||||||
|
send_app_instructions
|
||||||
|
.send(AppInstruction::ToScreen(ScreenInstruction::MoveFocus))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
ApiCommand::ToPty(instruction) => {
|
||||||
|
send_pty_instructions.send(instruction).unwrap();
|
||||||
|
}
|
||||||
|
ApiCommand::ToScreen(instruction) => {
|
||||||
|
send_app_instructions
|
||||||
|
.send(AppInstruction::ToScreen(instruction))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
ApiCommand::ClosePluginPane(pid) => {
|
||||||
|
send_app_instructions
|
||||||
|
.send(AppInstruction::ToPlugin(PluginInstruction::Unload(pid)))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
ApiCommand::Quit => {
|
||||||
|
let _ = send_pty_instructions.send(PtyInstruction::Quit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user