fixed sterr not streamed
This commit is contained in:
parent
e1dcf6748e
commit
88747a3cd8
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -570,7 +570,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "calcifer"
|
||||
version = "1.1.0"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -42,4 +42,8 @@ Max framerate => 30 fps (less cpu usage)
|
|||
|
||||
Added confirm prompt if unsaved
|
||||
Async terminal !
|
||||
Real Ui
|
||||
Real Ui
|
||||
|
||||
# 1.0.1 :
|
||||
|
||||
Fixed sterr not streamed
|
|
@ -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:");
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = "";
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,13 @@ pub struct CommandEntry {
|
|||
pub output: String,
|
||||
pub error: String,
|
||||
pub output_buffer: BufReader<std::process::ChildStdout>,
|
||||
pub error_buffer: BufReader<std::process::ChildStderr>,
|
||||
}
|
||||
|
||||
|
||||
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<std::process::ChildStdout> {
|
||||
pub fn execute(command: String) -> (BufReader<std::process::ChildStdout>, BufReader<std::process::ChildStderr>) {
|
||||
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<std::process::ChildStdout> {
|
|||
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));
|
||||
}
|
Loading…
Reference in a new issue