SHA256
Wrapping UI rework and rollback progress addition.
This commit is contained in:
1 parent
e4febb1e60
commit
63cb87888b
4 files changed
+300
-201
No files matched your search
+49
-30
@@ -74,27 +74,29 @@ const CURRENT_BOOT_LIST_TEXT: &str = "bzz current";
|
||||
// ExitCode::SUCCESS
|
||||
// }
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct RollbackState {
|
||||
progress: f64,
|
||||
progress_text: String,
|
||||
snapshot_date_time: String,
|
||||
}
|
||||
impl RollbackState {
|
||||
// Constructor function
|
||||
pub fn new(snap_date_time: String) -> Self {
|
||||
RollbackState {
|
||||
progress: 0.0,
|
||||
progress_text: "".into(),
|
||||
snapshot_date_time: snap_date_time,
|
||||
}
|
||||
}
|
||||
}
|
||||
// #[derive(Debug, PartialEq)]
|
||||
// struct RollbackState {
|
||||
// progress: f64,
|
||||
// progress_text: String,
|
||||
// snapshot_date_time: String,
|
||||
// roll_iter: nyan_system::RollBackIterator,
|
||||
// }
|
||||
// impl RollbackState {
|
||||
// // Constructor function
|
||||
// pub fn new(snaps_list: Vec<String>, snap_date_time: String) -> Self {
|
||||
// RollbackState {
|
||||
// progress: 0.0,
|
||||
// progress_text: "".into(),
|
||||
// snapshot_date_time: snap_date_time.clone(),
|
||||
// roll_iter: nyan_system::RollBackIterator::new(snaps_list, snap_date_time)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum NyanitState {
|
||||
Init,
|
||||
RollBack(RollbackState),
|
||||
RollBack,
|
||||
ConfirmRollback(String),
|
||||
WaitForF2,
|
||||
/// list of snapshoots
|
||||
@@ -138,6 +140,7 @@ struct NyanitTUI<'a> {
|
||||
time_counter_sec: u64,
|
||||
textarea: Option<TextArea<'a>>,
|
||||
snaps_list: Vec<String>,
|
||||
roll_state: Option<nyan_system::RollBackIterator>,
|
||||
}
|
||||
|
||||
impl NyanitTUI<'_> {
|
||||
@@ -151,6 +154,7 @@ impl NyanitTUI<'_> {
|
||||
time_counter_sec: 0,
|
||||
textarea: None,
|
||||
snaps_list: Vec::new(),
|
||||
roll_state: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -351,7 +355,7 @@ impl NyanitTUI<'_> {
|
||||
let par1 = gen_conf_par(snap_dt.clone());
|
||||
frame.render_widget(par1, vertical_chunks[1]);
|
||||
}
|
||||
NyanitState::RollBack(roll_state) => {
|
||||
NyanitState::RollBack => {
|
||||
let centered = vertical_chunks[1].centered_vertically(Constraint::Length(9));
|
||||
// 1. Create the outer block
|
||||
let block = Block::default()
|
||||
@@ -374,10 +378,11 @@ impl NyanitTUI<'_> {
|
||||
.split(block_inner_area);
|
||||
let gauge = Gauge::default()
|
||||
.gauge_style(Style::default().fg(Color::LightRed))
|
||||
.ratio(roll_state.progress);
|
||||
.ratio(self.roll_state.as_ref().unwrap().progress);
|
||||
frame.render_widget(gauge, chunks[0]);
|
||||
|
||||
let text = Paragraph::new(roll_state.progress_text.clone()).centered();
|
||||
let text = Paragraph::new(self.roll_state.as_ref().unwrap().progress_text.clone())
|
||||
.centered();
|
||||
frame.render_widget(text, chunks[2]);
|
||||
}
|
||||
NyanitState::EnterPassword => {
|
||||
@@ -489,8 +494,11 @@ impl NyanitTUI<'_> {
|
||||
}
|
||||
NyanitState::ConfirmRollback(snap_dt) => match e {
|
||||
Key::Char('Y') | Key::Char('y') => {
|
||||
let roll_state = RollbackState::new(snap_dt.clone());
|
||||
self.state = NyanitState::RollBack(roll_state);
|
||||
self.roll_state = Some(nyan_system::RollBackIterator::new(
|
||||
self.snaps_list.clone(),
|
||||
snap_dt.clone(),
|
||||
));
|
||||
self.state = NyanitState::RollBack;
|
||||
}
|
||||
Key::Char(_) => self.state = NyanitState::ChooseSnapshot,
|
||||
_ => (),
|
||||
@@ -500,15 +508,26 @@ impl NyanitTUI<'_> {
|
||||
} else {
|
||||
// Tick time
|
||||
thread::sleep(Duration::from_millis(TICK_TIME_MILLS));
|
||||
|
||||
if let NyanitState::WaitForF2 = self.state {
|
||||
self.time_counter = self.time_counter.wrapping_add(TICK_TIME_MILLS);
|
||||
self.time_counter_sec = self.time_counter / 1000;
|
||||
// wait for F2
|
||||
if self.time_counter_sec > WAIT_FOR_F2_SEC {
|
||||
// boot from root
|
||||
self.state = NyanitState::HandOff;
|
||||
match self.state {
|
||||
NyanitState::WaitForF2 => {
|
||||
self.time_counter = self.time_counter.wrapping_add(TICK_TIME_MILLS);
|
||||
self.time_counter_sec = self.time_counter / 1000;
|
||||
// wait for F2
|
||||
if self.time_counter_sec > WAIT_FOR_F2_SEC {
|
||||
// boot from root
|
||||
self.state = NyanitState::HandOff;
|
||||
}
|
||||
}
|
||||
NyanitState::RollBack => match self.roll_state.as_mut().unwrap().next() {
|
||||
Some(Err(ex)) => {
|
||||
self.state = NyanitState::Error(format!("ROLL BACK ERROR!: {}", ex));
|
||||
}
|
||||
None => {
|
||||
self.state = NyanitState::HandOff;
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user