work on stuff
This commit is contained in:
70
src/main.rs
70
src/main.rs
@@ -1,7 +1,7 @@
|
|||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
use indicatif::{MultiProgress, ProgressBar, ProgressStyle, TermLike};
|
||||||
|
|
||||||
use crate::action::StartFields;
|
use crate::action::StartFields;
|
||||||
use crate::state_manager::{BuildEnumState, BuildState, State, StateManager};
|
use crate::state_manager::{BuildEnumState, BuildState, State, StateManager};
|
||||||
@@ -10,11 +10,77 @@ pub mod action;
|
|||||||
pub mod action_raw;
|
pub mod action_raw;
|
||||||
pub mod nix_path;
|
pub mod nix_path;
|
||||||
pub mod state_manager;
|
pub mod state_manager;
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
struct TextTerm;
|
||||||
|
|
||||||
|
impl TermLike for TextTerm {
|
||||||
|
fn width(&self) -> u16 {
|
||||||
|
50
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_up(&self, n: usize) -> std::io::Result<()> {
|
||||||
|
println!("Move cursor up by {n}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_down(&self, n: usize) -> std::io::Result<()> {
|
||||||
|
println!("Move cursor down by {n}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_right(&self, n: usize) -> std::io::Result<()> {
|
||||||
|
println!("Move cursor right by {n}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_cursor_left(&self, n: usize) -> std::io::Result<()> {
|
||||||
|
println!("Move cursor left by {n}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_line(&self, s: &str) -> std::io::Result<()> {
|
||||||
|
println!("write_line: {s:?}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_str(&self, s: &str) -> std::io::Result<()> {
|
||||||
|
println!("write_str: {s:?}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear_line(&self) -> std::io::Result<()> {
|
||||||
|
println!("Clear line");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&self) -> std::io::Result<()> {
|
||||||
|
println!("Flush");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), color_eyre::Report> {
|
fn main() -> Result<(), color_eyre::Report> {
|
||||||
color_eyre::install().unwrap();
|
color_eyre::install().unwrap();
|
||||||
|
|
||||||
|
let pb = ProgressBar::new(100);
|
||||||
|
pb.set_draw_target(indicatif::ProgressDrawTarget::term_like(Box::new(TextTerm)));
|
||||||
|
|
||||||
|
pb.set_style(
|
||||||
|
ProgressStyle::default_bar()
|
||||||
|
.template("{msg} [{bar:40.cyan/blue}] {pos:>3}%")
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
pb.set_message("Example Progress Bar");
|
||||||
|
for i in 0..=5 {
|
||||||
|
pb.set_position(i);
|
||||||
|
sleep(Duration::from_millis(50));
|
||||||
|
}
|
||||||
|
pb.finish_and_clear();
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
|
||||||
let lines = std::fs::read_to_string("build.log")?;
|
let lines = std::fs::read_to_string("build.log")?;
|
||||||
// let lines = lines.lines().take(1000).collect::<Vec<_>>().join("\n");
|
let lines = lines.lines().take(0).collect::<Vec<_>>().join("\n");
|
||||||
|
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
progress: MultiProgress::new(),
|
progress: MultiProgress::new(),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||||
use std::{borrow::Cow, collections::HashMap};
|
use std::{borrow::Cow, collections::HashMap};
|
||||||
|
|
||||||
use crate::action::StartFields;
|
use crate::{action::StartFields, nix_path};
|
||||||
|
|
||||||
pub struct State<'a> {
|
pub struct State<'a> {
|
||||||
pub progress: MultiProgress,
|
pub progress: MultiProgress,
|
||||||
@@ -100,7 +100,8 @@ impl<'a> BuildState<'a> {
|
|||||||
self.progress_bar = Some(pb);
|
self.progress_bar = Some(pb);
|
||||||
}
|
}
|
||||||
BuildEnumState::SubstituteFetch { path, bar } => {
|
BuildEnumState::SubstituteFetch { path, bar } => {
|
||||||
bar.set_message(format!("Fetching substitute for {}", path));
|
let name = nix_path::extract_package_name(path).unwrap_or("unknown".to_string());
|
||||||
|
bar.set_message(format!("Fetching substitute for {}", name));
|
||||||
bar.set_style(
|
bar.set_style(
|
||||||
ProgressStyle::default_bar()
|
ProgressStyle::default_bar()
|
||||||
.template("{msg} [{bar:40.cyan/blue}] {pos:>3}%")
|
.template("{msg} [{bar:40.cyan/blue}] {pos:>3}%")
|
||||||
|
|||||||
Reference in New Issue
Block a user