From 88747a3cd8e787d4cead03ccee6a8b892883659b Mon Sep 17 00:00:00 2001 From: Penwing Date: Thu, 25 Jan 2024 19:55:29 +0100 Subject: [PATCH] fixed sterr not streamed --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 6 +++++- src/calcifer.rs | 4 ++-- src/calcifer/app_base.rs | 19 ++++++++++++++----- src/main.rs | 4 ++-- src/tools/terminal.rs | 22 ++++++++++++++++++---- 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4edfff..3bb8b2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -570,7 +570,7 @@ dependencies = [ [[package]] name = "calcifer" -version = "1.1.0" +version = "1.0.0" dependencies = [ "eframe", "egui_extras", diff --git a/Cargo.toml b/Cargo.toml index 904606a..999f64c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcifer" -version = "1.0.0" +version = "1.0.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index aa3fdba..555a03d 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,8 @@ Max framerate => 30 fps (less cpu usage) Added confirm prompt if unsaved Async terminal ! -Real Ui \ No newline at end of file +Real Ui + +# 1.0.1 : + +Fixed sterr not streamed \ No newline at end of file diff --git a/src/calcifer.rs b/src/calcifer.rs index ee2d6e9..15dc4d6 100644 --- a/src/calcifer.rs +++ b/src/calcifer.rs @@ -90,7 +90,7 @@ impl Calcifer { let response = ui.add(egui::TextEdit::singleline(command).desired_width(f32::INFINITY).lock_focus(true)); if response.lost_focus() && ctx.input(|i| i.key_pressed(egui::Key::Enter)) { - self.command_history.push(tools::run_command(self.command.clone())); + self.command_history.push(tools::send_command(self.command.clone())); self.command = "".into(); response.request_focus(); } @@ -172,7 +172,7 @@ impl Calcifer { if ui.add(egui::Button::new("open in terminal")).clicked() { let mut path = self.tabs[self.selected_tab.to_index()].path.clone(); path.pop(); - tools::run_command(format!("cd {}", path.display())); + tools::send_command(format!("cd {}", path.display())); } ui.label("Picked file:"); diff --git a/src/calcifer/app_base.rs b/src/calcifer/app_base.rs index 375bde3..ac59b83 100644 --- a/src/calcifer/app_base.rs +++ b/src/calcifer/app_base.rs @@ -153,15 +153,24 @@ impl Calcifer { pub fn toggle(&self, ui: &mut egui::Ui, display : bool, title : &str) -> bool { - let color = if display.clone() { - Color32::from_hex(self.theme.functions).expect("Could not convert color to hex (functions)") + let bg_color : Color32; + let text_color : Color32; + + if display.clone() { + bg_color = Color32::from_hex(self.theme.functions).expect("Could not convert color to hex (functions)"); + text_color = Color32::from_hex(self.theme.bg).expect("Could not convert color to hex (bg)"); } else { - Color32::from_hex(self.theme.bg).expect("Could not convert color to hex (bg)") + bg_color = Color32::from_hex(self.theme.bg).expect("Could not convert color to hex (bg)"); + text_color = Color32::from_hex(self.theme.literals).expect("Could not convert color to hex (literals)"); }; - - if ui.add(egui::Button::new(title).fill(color)).clicked() { + + ui.style_mut().visuals.override_text_color = Some(text_color); + + if ui.add(egui::Button::new(title).fill(bg_color)).clicked() { return !display } + ui.style_mut().visuals.override_text_color = None; + return display } diff --git a/src/main.rs b/src/main.rs index 77c37f2..c125fff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,13 +12,13 @@ use calcifer::code_editor::themes::DEFAULT_THEMES; #[cfg(debug_assertions)] mod build { - pub const SAVE_PATH : &str = "/home/penwing/Documents/.saves/debug/calcifer_save.json"; + pub const SAVE_PATH : &str = "/var/lib/calcifer/debug/calcifer_save.json"; pub const TITLE: &str = " debug"; } #[cfg(not(debug_assertions))] mod build { - pub const SAVE_PATH : &str = "/home/penwing/Documents/.saves/calcifer_save.json"; + pub const SAVE_PATH : &str = "/var/lib/calcifer/calcifer_save.json"; pub const TITLE: &str = ""; } diff --git a/src/tools/terminal.rs b/src/tools/terminal.rs index fb19074..cb40410 100644 --- a/src/tools/terminal.rs +++ b/src/tools/terminal.rs @@ -13,12 +13,13 @@ pub struct CommandEntry { pub output: String, pub error: String, pub output_buffer: BufReader, + pub error_buffer: BufReader, } impl CommandEntry { pub fn new(command: String) -> Self { - let stdout_reader = execute(command.clone()); + let (stdout_reader, stderr_reader) = execute(command.clone()); CommandEntry { env: format_path(&env::current_dir().expect("Could not find Shell Environnment")), @@ -26,6 +27,7 @@ impl CommandEntry { output: String::new(), error: String::new(), output_buffer: stdout_reader, + error_buffer: stderr_reader, } } @@ -35,11 +37,17 @@ impl CommandEntry { if !output.is_empty() { self.output += &output; } + + let mut error = String::new(); + let _ = self.error_buffer.read_line(&mut error); + if !error.is_empty() { + self.error += &error; + } } } -pub fn run_command(command: String) -> CommandEntry { +pub fn send_command(command: String) -> CommandEntry { if command.len() < 2 { return CommandEntry::new(command); } @@ -75,11 +83,12 @@ pub fn run_command(command: String) -> CommandEntry { } -pub fn execute(command: String) -> BufReader { +pub fn execute(command: String) -> (BufReader, BufReader) { let mut child = Command::new("sh") .arg("-c") .arg(command.clone()) .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .expect("failed to execute process"); @@ -87,6 +96,11 @@ pub fn execute(command: String) -> BufReader { let stdout_fd = stdout.as_raw_fd(); fcntl(stdout_fd, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).expect("Failed to set non-blocking mode"); + + let stderr = child.stderr.take().unwrap(); + let stderr_fd = stderr.as_raw_fd(); - return BufReader::new(stdout); + fcntl(stderr_fd, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).expect("Failed to set non-blocking mode"); + + return (BufReader::new(stdout), BufReader::new(stderr)); } \ No newline at end of file