Skip to content

Commit

Permalink
refact: use time crate
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 committed Nov 1, 2024
1 parent 0409a3d commit a429ab2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
72 changes: 68 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ portable-pty = "0.8.1"
ratatui = "0.29.0"
tui-term = "0.2.0"
temp-dir = "0.1.14"
time = { version = "0.3.36", features = ["local-offset", "macros", "formatting"] }
unicode-width = "0.2.0"
rand = { version = "0.8.5", optional = true }
linutil_core = { path = "../core", version = "24.9.28" }
Expand Down
8 changes: 6 additions & 2 deletions tui/src/running_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use std::{
sync::{Arc, Mutex},
thread::JoinHandle,
};
use time::{macros::format_description, OffsetDateTime};
use tui_term::{
vt100::{self, Screen},
widget::PseudoTerminal,
};

pub struct RunningCommand {
/// A buffer to save all the command output (accumulates, until the command exits)
buffer: Arc<Mutex<Vec<u8>>>,
Expand Down Expand Up @@ -301,9 +301,13 @@ impl RunningCommand {

fn save_log(&self) -> std::io::Result<String> {
let mut log_path = std::env::temp_dir();
let format = format_description!("[year]-[month]-[day]-[hour]-[minute]-[second]");
log_path.push(format!(
"linutil_log_{}.log",
chrono::Local::now().format("%Y%m%d_%H%M%S")
OffsetDateTime::now_local()
.unwrap()
.format(&format)
.unwrap()
));

let mut file = std::fs::File::create(&log_path)?;
Expand Down

0 comments on commit a429ab2

Please sign in to comment.