Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Dec 4, 2024
1 parent 36ded40 commit 024b336
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 25 deletions.
2 changes: 1 addition & 1 deletion nvrs.tape
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Output nvrs.gif

Require echo
Require nvrs

Set Shell "zsh"
Set FontSize 32
Expand Down
101 changes: 77 additions & 24 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use anyhow::Result;
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
use nvrs::*;
use ratatui::{
layout::Alignment,
style::{Style, Stylize},
widgets::{Block, BorderType, List, ListItem},
layout::{Constraint, Layout},
style::{Color, Style},
text::{Line, Span},
widgets::{Block, BorderType, List},
Frame,
};
use tachyonfx::{fx, Duration as FxDuration, Effect, EffectRenderer, Shader};
Expand All @@ -14,6 +15,7 @@ const KEYBINDS: &str = " [q] Quit [s] Sync ";
struct AppState {
is_running: bool,
is_syncing: bool,
is_comparing: bool,
effect: Effect,

// nvrs data
Expand All @@ -32,6 +34,7 @@ impl AppState {
Ok(Self {
is_running: true,
is_syncing: false,
is_comparing: true,
effect: fx::coalesce(800),

// nvrs data
Expand All @@ -43,38 +46,88 @@ impl AppState {
}

fn draw(&mut self, frame: &mut Frame) {
let new_names = self.verfiles.1.data.data.keys().collect::<Vec<_>>();

let list = List::new(
new_names
.iter()
.map(|p| ListItem::new(format!("📦️ {}", p)).style(Style::default().blue())),
)
.block(
Block::bordered()
.title_top(if self.is_syncing {
" Synchronizing... "
} else {
" nvrs "
})
.title_bottom(KEYBINDS)
.title_alignment(Alignment::Center)
.border_type(BorderType::Rounded),
);

frame.render_widget(list, frame.area());
if self.is_comparing {
self.draw_compare(frame);
}

if self.effect.running() {
frame.render_effect(&mut self.effect, frame.area(), FxDuration::from_millis(50))
}
}

fn draw_compare(&mut self, frame: &mut Frame) {
let layout = Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
.split(frame.area());

let title = if self.is_syncing {
" synchronizing... "
} else {
" newver "
};

let new_data = &self.verfiles.1.data.data;
let old_data = &self.verfiles.0.data.data;

let mut new_items: Vec<Line> = Vec::with_capacity(new_data.len());
let mut old_items: Vec<Line> = Vec::with_capacity(old_data.len());

for new in new_data.iter() {
let old = old_data.iter().find(|old| old.0 == new.0);

let style = if let Some(old) = old {
if new.1.version != old.1.version {
(Style::new().fg(Color::Green), Style::new().fg(Color::Red))
} else {
(Style::default(), Style::default())
}
} else {
(Style::new().fg(Color::Yellow), Style::default())
};
let blue = Style::new().fg(Color::Blue);

let name = format!("{} ", new.0);

let new_line = Line::from_iter([
"📦️ ".into(),
Span::styled(name.clone(), blue),
Span::styled(new.1.version.clone(), style.0),
]);

let old_line = if let Some(old) = old {
Line::from_iter([
"📦️ ".into(),
Span::styled(name, blue),
Span::styled(old.1.version.clone(), style.1),
])
} else {
Line::from("")
};

new_items.push(new_line);
old_items.push(old_line);
}

let new_list = List::new(new_items).block(
Block::bordered()
.title_top(title)
.border_type(BorderType::Rounded),
);
let old_list = List::new(old_items).block(
Block::bordered()
.title_top(" oldver ")
.border_type(BorderType::Rounded),
);

frame.render_widget(new_list, layout[0]);
frame.render_widget(old_list, layout[1]);
}

async fn sync(&mut self) -> error::Result<()> {
let config = &self.config.0;

let tasks: Vec<_> = config
.packages
.to_owned()
.clone()
.into_iter()
.map(|p| tokio::spawn(run_source(p, self.client.clone(), self.keyfile.clone())))
.collect();
Expand Down

0 comments on commit 024b336

Please sign in to comment.