diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-02-12 12:59:48 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-04 20:47:49 +0530 |
| commit | 6fc1a5bf921fa14209ce579348e4f1208ace81d7 (patch) | |
| tree | b0e7aed8a1bb8502e63446cceaa5aa4766dc7ef5 /src | |
| parent | remove debug log file (diff) | |
| download | sl0ppij-6fc1a5bf921fa14209ce579348e4f1208ace81d7.tar.gz sl0ppij-6fc1a5bf921fa14209ce579348e4f1208ace81d7.tar.xz sl0ppij-6fc1a5bf921fa14209ce579348e4f1208ace81d7.zip | |
another try
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/errors.rs | 2 | ||||
| -rw-r--r-- | src/common/mod.rs | 14 | ||||
| -rw-r--r-- | src/server/mod.rs | 36 |
3 files changed, 20 insertions, 32 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs index 94682ebc..a9156ae6 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -64,7 +64,7 @@ pub fn handle_panic( }; if thread == "main" { - eprintln!("{}", backtrace); + println!("{}", backtrace); process::exit(1); } else { send_app_instructions diff --git a/src/common/mod.rs b/src/common/mod.rs index 4c8ab4c0..c737a788 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -141,11 +141,8 @@ 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(); - UnixStream::connect(MOSAIC_IPC_PIPE) - .unwrap() - .write_all(&command) + self.sender.write_all(&command) } } @@ -573,11 +570,10 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) { os_input.unset_raw_mode(0); let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1); let error = format!("{}\n{}", goto_start_of_last_line, backtrace); - //let _ = os_input - // .get_stdout_writer() - // .write(error.as_bytes()) - // .unwrap(); - eprintln!("{}", error); + let _ = os_input + .get_stdout_writer() + .write(error.as_bytes()) + .unwrap(); std::process::exit(1); } AppInstruction::ToScreen(instruction) => { diff --git a/src/server/mod.rs b/src/server/mod.rs index 0ba19568..1da079eb 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -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 { - let pid = pty_bus.spawn_terminal(None); - pty_bus - .send_server_instructions - .send(ApiCommand::ToScreen(ScreenInstruction::NewTab(pid))) - .unwrap(); - //} + 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,15 +120,14 @@ pub fn start_server( .name("ipc_server".to_string()) .spawn({ move || { - let mut threads = vec![]; for stream in listener.incoming() { match stream { Ok(stream) => { let send_app_instructions = send_app_instructions.clone(); let send_pty_instructions = send_pty_instructions.clone(); - threads.push(thread::spawn(move || { + thread::spawn(move || { handle_stream(send_pty_instructions, send_app_instructions, stream); - })); + }); } Err(err) => { panic!("err {:?}", err); @@ -137,9 +136,6 @@ pub fn start_server( } let _ = pty_thread.join(); - for t in threads { - t.join(); - } } }) .unwrap() @@ -150,21 +146,17 @@ fn handle_stream( 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(); + let mut buffer = [0; 65535]; // TODO: more accurate loop { let bytes = stream - .read_to_string(&mut buffer) + .read(&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"); + bincode::deserialize(&buffer[..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); |
