try fixes

This commit is contained in:
Kunal Mohan 2021-02-12 11:39:02 +05:30
parent 685e2eef0c
commit 7beb246250
6 changed files with 12333 additions and 84 deletions

12228
abc.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -64,7 +64,7 @@ pub fn handle_panic(
};
if thread == "main" {
println!("{}", backtrace);
eprintln!("{}", backtrace);
process::exit(1);
} else {
send_app_instructions

View File

@ -24,6 +24,7 @@ use std::{
};
use crate::cli::CliArgs;
use crate::layout::Layout;
use crate::server::start_server;
use command_is_executing::CommandIsExecuting;
use errors::{AppContext, ContextType, ErrorContext, PluginContext, ScreenContext};
@ -140,8 +141,11 @@ impl IpcSenderWithContext {
}
pub fn send(&mut self, msg: ApiCommand) -> std::io::Result<()> {
eprintln!("Ipcsender sending {:?}", msg);
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::CloseTab => screen.close_tab(),
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();
}
ScreenInstruction::GoToTab(tab_index) => {
@ -560,22 +564,20 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
}
AppInstruction::Error(backtrace) => {
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 _ = screen_thread.join();
let _ = send_plugin_instructions.send(PluginInstruction::Quit);
let _ = wasm_thread.join();
os_input.unset_raw_mode(0);
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, restore_snapshot, backtrace
);
let _ = os_input
.get_stdout_writer()
.write(error.as_bytes())
.unwrap();
let error = format!("{}\n{}", goto_start_of_last_line, backtrace);
//let _ = os_input
// .get_stdout_writer()
// .write(error.as_bytes())
// .unwrap();
eprintln!("{}", error);
std::process::exit(1);
}
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 _ = ipc_thread.join().unwrap();
//let _ = ipc_thread.join().unwrap();
//IpcSenderWithContext::new().send(ApiCommand::Quit);
let _ = send_screen_instructions.send(ScreenInstruction::Quit);
screen_thread.join().unwrap();
let _ = send_plugin_instructions.send(PluginInstruction::Quit);

View File

@ -292,7 +292,8 @@ impl PtyBus {
self.id_to_child_pid.insert(pid_primary, pid_secondary);
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 mut new_pane_pids = vec![];
for _ in 0..total_panes {
@ -302,7 +303,7 @@ impl PtyBus {
}
self.send_server_instructions
.send(ApiCommand::ToScreen(ScreenInstruction::ApplyLayout((
layout,
layout_path,
new_pane_pids.clone(),
))))
.unwrap();

View File

@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::os::unix::io::RawFd;
use std::str;
use std::path::PathBuf;
use std::sync::mpsc::Receiver;
use super::{AppInstruction, SenderWithContext};
@ -48,7 +48,7 @@ pub enum ScreenInstruction {
SetMaxHeight(PaneId, usize),
SetInvisibleBorders(PaneId, bool),
ClosePane(PaneId),
ApplyLayout((Layout, Vec<RawFd>)),
ApplyLayout((PathBuf, Vec<RawFd>)),
NewTab(RawFd),
SwitchTabNext,
SwitchTabPrev,

View File

@ -39,7 +39,7 @@ pub fn start_server(
let default_layout = Some(PathBuf::from("default"));
#[cfg(test)]
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();
@ -90,15 +90,15 @@ pub fn start_server(
.unwrap();
}
PtyInstruction::NewTab => {
if let Some(layout) = maybe_layout.clone() {
pty_bus.spawn_terminals_for_layout(layout, err_ctx);
} else {
//if let Some(layout) = maybe_layout.clone() {
// pty_bus.spawn_terminals_for_layout(layout, err_ctx);
//} else {
let pid = pty_bus.spawn_terminal(None);
pty_bus
.send_server_instructions
.send(ApiCommand::ToScreen(ScreenInstruction::NewTab(pid)))
.unwrap();
}
//}
}
PtyInstruction::ClosePane(id) => {
pty_bus.close_pane(id, err_ctx);
@ -120,20 +120,51 @@ pub fn start_server(
.name("ipc_server".to_string())
.spawn({
move || {
let mut threads = vec![];
for stream in listener.incoming() {
match stream {
Ok(mut stream) => {
let mut buffer = [0; 65535]; // TODO: more accurate
let _ = stream
.read(&mut buffer)
Ok(stream) => {
let send_app_instructions = send_app_instructions.clone();
let send_pty_instructions = send_pty_instructions.clone();
threads.push(thread::spawn(move || {
handle_stream(send_pty_instructions, send_app_instructions, stream);
}));
}
Err(err) => {
panic!("err {:?}", err);
}
}
}
let _ = pty_thread.join();
for t in threads {
t.join();
}
}
})
.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)
.expect("failed to deserialize ipc message");
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);
@ -153,9 +184,7 @@ pub fn start_server(
}
ApiCommand::MoveFocus => {
send_app_instructions
.send(AppInstruction::ToScreen(
ScreenInstruction::MoveFocus,
))
.send(AppInstruction::ToScreen(ScreenInstruction::MoveFocus))
.unwrap();
}
ApiCommand::ToPty(instruction) => {
@ -168,25 +197,13 @@ pub fn start_server(
}
ApiCommand::ClosePluginPane(pid) => {
send_app_instructions
.send(AppInstruction::ToPlugin(PluginInstruction::Unload(
pid,
)))
.send(AppInstruction::ToPlugin(PluginInstruction::Unload(pid)))
.unwrap();
}
ApiCommand::Quit => {
send_pty_instructions.send(PtyInstruction::Quit).unwrap();
let _ = send_pty_instructions.send(PtyInstruction::Quit);
break;
}
}
}
Err(err) => {
panic!("err {:?}", err);
}
}
}
let _ = pty_thread.join();
}
})
.unwrap()
}