From 3622c755670e89a644a660ca4e97611b1bf0fdfa Mon Sep 17 00:00:00 2001 From: Valeria Fadeeva Date: Thu, 30 Jan 2025 13:00:09 +0500 Subject: [PATCH] Update --- Cargo.toml | 4 ++-- src/main.rs | 60 ++++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 842394a..f45af34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Valeria Fadeeva "] -name = "arch-linux-updater" +name = "melawy-linux-updater" version = "0.1.0" edition = "2021" @@ -10,6 +10,6 @@ edition = "2021" futures = "0.3" fltk = { version = "1.5", features = ["fltk-bundled"] } fltk-theme = "0.7" -tokio = { version = "1.42", features = ["full"] } +tokio = { version = "^1", features = ["full"] } # bytes = "1.9" dotenv = "0.15" diff --git a/src/main.rs b/src/main.rs index 0346dde..1672ec9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,20 +2,22 @@ extern crate dotenv; -use fltk::{prelude::*, app, terminal::Terminal, enums::Color, frame, window, /*button,*/ image}; -use fltk_theme::{/*ColorTheme, color_themes, widget_themes, */WidgetTheme, ThemeType, WidgetScheme, SchemeType}; +use fltk::{app, enums::Color, frame, /*button,*/ image, prelude::*, terminal::Terminal, window,}; +use fltk_theme::{ + SchemeType, ThemeType, WidgetScheme, + /*ColorTheme, color_themes, widget_themes, */ WidgetTheme, +}; -use tokio::io::{self, BufReader, AsyncBufReadExt}; +use tokio::io::{self, AsyncBufReadExt, BufReader}; use tokio::process::Command; use std::env; -use std::process::Stdio; use std::path::Path; - +use std::process::Stdio; async fn run_process() -> tokio::process::Child { #[cfg(not(debug_assertions))] - let env_path = Path::new("/etc/arch-linux-updater/.env"); + let env_path = Path::new("/etc/melawy-linux-updater/.env"); #[cfg(debug_assertions)] let env_path = Path::new(".env_debug"); @@ -31,48 +33,47 @@ async fn run_process() -> tokio::process::Child { println!("{cmd_line} {par}"); let child: tokio::process::Child = Command::new(cmd_line) - .args(v) - .stderr(Stdio::piped()) // don't care about stderr - .stdout(Stdio::piped()) // set up stdout so we can read it - .stdin(Stdio::piped()) // set up stdin so we can write on it - .spawn() - .expect("Could not run the command"); // finally run the command + .args(v) + .stderr(Stdio::piped()) // don't care about stderr + .stdout(Stdio::piped()) // set up stdout so we can read it + .stdin(Stdio::piped()) // set up stdin so we can write on it + .spawn() + .expect("Could not run the command"); // finally run the command child } - async fn get_stdout() -> tokio::process::ChildStdout { let mut child: tokio::process::Child = run_process().await; - let stdout: tokio::process::ChildStdout = child.stdout.take() + let stdout: tokio::process::ChildStdout = child + .stdout + .take() .expect("child did not have a handle to stdout"); stdout } - async fn get_buffer() -> BufReader { let buffer: BufReader = BufReader::new(get_stdout().await); buffer } - async fn get_lines() -> io::Lines> { let lines: io::Lines> = get_buffer().await.lines(); lines } - -async fn get_line(lines: &mut io::Lines>) -> io::Result> { +async fn get_line( + lines: &mut io::Lines>, +) -> io::Result> { let line: Result, io::Error> = lines.next_line().await; line } - async fn gui() -> io::Result<()> { let width = 1100; let height = 700; @@ -89,23 +90,22 @@ async fn gui() -> io::Result<()> { let mut wind: fltk::window::DoubleWindow = window::Window::default() .with_size(width, height) .center_screen() - .with_label("Arch Linux Updater"); + .with_label("Melawy Linux Updater"); - // let image = image::PngImage::load("assets/icons/Melawy.png").unwrap(); - // let image = image::PngImage::load("/usr/share/arch-linux-updater/assets/icons/Melawy.png").unwrap(); - let image = image::SvgImage::load("/usr/share/arch-linux-updater/assets/icons/Melawy.svg").unwrap(); - // let image = image::PngImage::load(&std::path::Path::new("assets/icons/Melawy.png")).unwrap(); + let image = + image::SvgImage::load("/usr/share/melawy-linux-updater/assets/icons/Melawy.svg").unwrap(); wind.set_icon(Some(image)); let frame = frame::Frame::default_fill() .with_size(width, height) .center_of(&wind); - let mut terminal: Terminal = Terminal::default_fill() + let mut term: Terminal = Terminal::default_fill() .with_size(width, height) .center_of(&frame); - terminal.set_color(Color::Background2); - terminal.set_text_color(Color::Light2); + term.set_color(Color::Background2); + term.set_text_color(Color::Light2); + term.set_history_rows(5000); wind.make_resizable(true); wind.end(); @@ -115,11 +115,10 @@ async fn gui() -> io::Result<()> { let mut lines: io::Lines> = get_lines().await; - // app.run().unwrap(); while app.wait() { if let Some(line) = get_line(&mut lines).await? { - terminal.append(format!("{}\n", line).as_str()); + term.append(format!("{}\n", line).as_str()); } else { if printed_close_msg == false { let lang_key = "LANG"; @@ -135,7 +134,7 @@ async fn gui() -> io::Result<()> { "Now this window may close" }; - terminal.append(format!("\n{}\n", text_to_close).as_str()); + term.append(format!("\n{}\n", text_to_close).as_str()); printed_close_msg = true; } } @@ -144,7 +143,6 @@ async fn gui() -> io::Result<()> { Ok(()) } - #[tokio::main] async fn main() -> io::Result<()> { gui().await