Skip to content

Commit 67f5238

Browse files
authored
Merge pull request #18 from gpu-mode/alzhang/colors
Add new colors + animation to update.
2 parents 1448853 + 651d96d commit 67f5238

File tree

4 files changed

+119
-45
lines changed

4 files changed

+119
-45
lines changed

src/cmd/submit.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,18 @@ pub async fn run_submit_tui(
665665
let state = &mut app.result_page_state;
666666

667667
let mut result_page = ResultPage::new(result_text.clone(), state);
668+
let mut last_draw = std::time::Instant::now();
668669
while !state.ack {
669-
terminal
670-
.draw(|frame: &mut Frame| {
671-
frame.render_stateful_widget(&result_page, frame.size(), state);
672-
})
673-
.unwrap();
670+
// Force redraw every 100ms for smooth animation
671+
let now = std::time::Instant::now();
672+
if now.duration_since(last_draw) >= std::time::Duration::from_millis(100) {
673+
terminal
674+
.draw(|frame: &mut Frame| {
675+
frame.render_stateful_widget(&result_page, frame.size(), state);
676+
})
677+
.unwrap();
678+
last_draw = now;
679+
}
674680
result_page.handle_key_event(state);
675681
}
676682

src/utils/mod.rs

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,87 @@ pub fn get_popcorn_directives<P: AsRef<Path>>(filepath: P) -> Result<(PopcornDir
4848
))
4949
}
5050

51-
pub fn get_ascii_art() -> String {
52-
let art = r#"
53-
_ __ _ ______ _
54-
| | / / | | | ___ \ | |
55-
| |/ / ___ _ __ _ __ ___ | | | |_/ / ___ _| |_
56-
| \ / _ \ '__| '_ \ / _ \| | | ___ \ / _ \| | __|
57-
| |\ \ __/ | | | | | __/| | | |_/ /| (_) | | |_
58-
\_| \_/\___|_| |_| |_|\___|_/ \____/ \___/|_|\__|
59-
60-
POPCORN CLI - GPU MODE
61-
62-
┌───────────────────────────────────────┐
63-
│ ┌─────┐ ┌─────┐ ┌─────┐ │
64-
│ │ooOoo│ │ooOoo│ │ooOoo│ │▒
65-
│ │oOOOo│ │oOOOo│ │oOOOo│ │▒
66-
│ │ooOoo│ │ooOoo│ │ooOoo│ ┌────────┐ │▒
67-
│ └─────┘ └─────┘ └─────┘ │████████│ │▒
68-
│ │████████│ │▒
69-
│ ┌────────────────────────┐ │████████│ │▒
70-
│ │ │ │████████│ │▒
71-
│ │ POPCORN GPU COMPUTE │ └────────┘ │▒
72-
│ │ │ │▒
73-
│ └────────────────────────┘ │▒
74-
│ │▒
75-
└───────────────────────────────────────┘▒
76-
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
77-
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
78-
"#;
51+
pub fn get_ascii_art_frame(frame: u16) -> String {
52+
let frame = frame % 3;
53+
match frame {
54+
0 => r#"
55+
▗▖ ▗▖▗▄▄▄▖▗▄▄▖ ▗▖ ▗▖▗▄▄▄▖▗▖ ▗▄▄▖ ▗▄▖ ▗▄▄▄▖
56+
▐▌▗▞▘▐▌ ▐▌ ▐▌▐▛▚▖▐▌▐▌ ▐▌ ▐▌ ▐▌▐▌ ▐▌ █
57+
▐▛▚▖ ▐▛▀▀▘▐▛▀▚▖▐▌ ▝▜▌▐▛▀▀▘▐▌ ▐▛▀▚▖▐▌ ▐▌ █
58+
▐▌ ▐▌▐▙▄▄▖▐▌ ▐▌▐▌ ▐▌▐▙▄▄▖▐▙▄▄▖▐▙▄▞▘▝▚▄▞▘ █
59+
60+
POPCORN CLI - GPU MODE
61+
62+
┌────────────────────────────────────────────┐
63+
│ ╔══════════════════════════════════╗ ϟ │
64+
│ ║ ▄▄ Graphics Processing Unit ▄▄║ ║ │▒
65+
│ ║ ██████ 80GB HBM3 MEMORY █║ ║ │▒
66+
│ ║ ▀▀▀▀▀▀ 700W TDP █║ ║ │▒
67+
│ ╚══════════════════════════════════╝ │▒
68+
│ ┌─────┐┌─────┐┌─────┐┌─────┐┌─────┐ │▒
69+
│ │:::::││:::::││:::::││:::::││:::::│ │▒
70+
│ └─────┘└─────┘└─────┘└─────┘└─────┘ │▒
71+
│ ┌──────────────────────────────────┐ │▒
72+
│ │ discord.com/invite/gpumode │ │▒
73+
│ │ ═══╧═══╧═══╧═══╧═══╧═══╧═══ │ │▒
74+
│ └──────────────────────────────────┘ │▒
75+
└────────────────────────────────────────────┘▒
76+
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
77+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"#.to_string(),
78+
1 => r#"
79+
▗▖ ▗▖▗▄▄▄▖▗▄▄▖ ▗▖ ▗▖▗▄▄▄▖▗▖ ▗▄▄▖ ▗▄▖ ▗▄▄▄▖
80+
▐▌▗▞▘▐▌ ▐▌ ▐▌▐▛▚▖▐▌▐▌ ▐▌ ▐▌ ▐▌▐▌ ▐▌ █
81+
▐▛▚▖ ▐▛▀▀▘▐▛▀▚▖▐▌ ▝▜▌▐▛▀▀▘▐▌ ▐▛▀▚▖▐▌ ▐▌ █
82+
▐▌ ▐▌▐▙▄▄▖▐▌ ▐▌▐▌ ▐▌▐▙▄▄▖▐▙▄▄▖▐▙▄▞▘▝▚▄▞▘ █
83+
84+
POPCORN CLI - GPU MODE
85+
86+
┌────────────────────────────────────────────┐
87+
│ ╔══════════════════════════════════╗ ϟϟ │
88+
│ ║ ▄▄ Graphics Processing Unit ▄▄║ ║ │▒
89+
│ ║ ██████ 80GB HBM3 MEMORY ███║ ║ │▒
90+
│ ║ ▀▀▀▀▀▀ 700W TDP ███║ ║ │▒
91+
│ ╚══════════════════════════════════╝ │▒
92+
│ ┌─────┐┌─────┐┌─────┐┌─────┐┌─────┐ │▒
93+
│ │:::::││:::::││:::::││:::::││:::::│ │▒
94+
│ └─────┘└─────┘└─────┘└─────┘└─────┘ │▒
95+
│ ┌──────────────────────────────────┐ │▒
96+
│ │ discord.com/invite/gpumode │ │▒
97+
│ │ ═══╧═══╧═══╧═══╧═══╧═══╧═══ │ │▒
98+
│ └──────────────────────────────────┘ │▒
99+
└────────────────────────────────────────────┘▒
100+
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
101+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"#.to_string(),
102+
_ => r#"
103+
▗▖ ▗▖▗▄▄▄▖▗▄▄▖ ▗▖ ▗▖▗▄▄▄▖▗▖ ▗▄▄▖ ▗▄▖ ▗▄▄▄▖
104+
▐▌▗▞▘▐▌ ▐▌ ▐▌▐▛▚▖▐▌▐▌ ▐▌ ▐▌ ▐▌▐▌ ▐▌ █
105+
▐▛▚▖ ▐▛▀▀▘▐▛▀▚▖▐▌ ▝▜▌▐▛▀▀▘▐▌ ▐▛▀▚▖▐▌ ▐▌ █
106+
▐▌ ▐▌▐▙▄▄▖▐▌ ▐▌▐▌ ▐▌▐▙▄▄▖▐▙▄▄▖▐▙▄▞▘▝▚▄▞▘ █
79107
80-
art.to_string()
108+
POPCORN CLI - GPU MODE
109+
110+
┌────────────────────────────────────────────┐
111+
│ ╔══════════════════════════════════╗ ϟϟϟ │
112+
│ ║ ▄▄ Graphics Processing Unit ▄▄║ ║ │▒
113+
│ ║ ██████ 80GB HBM3 MEMORY █████║ ║ │▒
114+
│ ║ ▀▀▀▀▀▀ 700W TDP █████║ ║ │▒
115+
│ ╚══════════════════════════════════╝ │▒
116+
│ ┌─────┐┌─────┐┌─────┐┌─────┐┌─────┐ │▒
117+
│ │:::::││:::::││:::::││:::::││:::::│ │▒
118+
│ └─────┘└─────┘└─────┘└─────┘└─────┘ │▒
119+
│ ┌──────────────────────────────────┐ │▒
120+
│ │ discord.com/invite/gpumode │ │▒
121+
│ │ ═══╧═══╧═══╧═══╧═══╧═══╧═══ │ │▒
122+
│ └──────────────────────────────────┘ │▒
123+
└────────────────────────────────────────────┘▒
124+
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
125+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀"#.to_string()
126+
}
81127
}
82128

129+
pub fn get_ascii_art() -> String {
130+
get_ascii_art_frame(0)
131+
}
83132

84133
pub fn display_ascii_art() {
85134
let art = get_ascii_art();

src/views/loading_page.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ pub struct LoadingPage {
1919
footer_area: Rect,
2020
}
2121

22-
const GAUGE_COLOR: Color = ratatui::style::palette::tailwind::RED.c800;
22+
fn get_gradient_color(progress: f64) -> Color {
23+
// Convert progress from 0-100 to 0-1
24+
let t = progress / 100.0;
25+
26+
// Start with red (255, 0, 0) and end with green (0, 255, 0)
27+
let r = ((1.0 - t) * 255.0) as u8;
28+
let g = (t * 255.0) as u8;
29+
let b = 0;
30+
31+
Color::Rgb(r, g, b)
32+
}
2333

2434
impl StatefulWidget for &LoadingPage {
2535
type State = LoadingPageState;
@@ -40,7 +50,7 @@ fn render_gauge(area: Rect, buf: &mut Buffer, state: &mut LoadingPageState) {
4050
let blk = Block::default().padding(Padding::horizontal(20));
4151
Gauge::default()
4252
.block(blk)
43-
.gauge_style(GAUGE_COLOR)
53+
.gauge_style(get_gradient_color(state.progress_bar))
4454
.ratio(state.progress_bar / 100.0)
4555
.render(area, buf);
4656
}

src/views/result_page.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct ResultPageState {
1515
pub horizontal_scroll: u16,
1616
pub horizontal_scroll_state: ScrollbarState,
1717
pub ack: bool,
18+
pub animation_frame: u16,
1819
}
1920

2021
#[derive(Default, Debug)]
@@ -37,29 +38,33 @@ impl ResultPage {
3738
.content_length(num_lines);
3839

3940
state.horizontal_scroll_state = state.horizontal_scroll_state.content_length(max_width);
41+
state.animation_frame = 0;
4042

4143
Self {
4244
result_text: Paragraph::new(result_text),
4345
}
4446
}
4547

46-
fn render_left(&self, buf: &mut Buffer, left: Rect) {
48+
fn render_left(&self, buf: &mut Buffer, left: Rect, state: &mut ResultPageState) {
4749
let left_block = Block::bordered()
4850
.border_type(BorderType::Plain)
49-
.border_style(Style::default().fg(Color::Yellow));
51+
.border_style(Style::default().fg(Color::Rgb(255, 165, 0)))
52+
.title("GPU MODE")
53+
.title_alignment(Alignment::Center);
5054

51-
let left_text = Paragraph::new(utils::get_ascii_art());
55+
let left_text = Paragraph::new(utils::get_ascii_art_frame(state.animation_frame / 5));
5256

5357
left_text.block(left_block).render(left, buf);
5458
}
5559

5660
fn render_right(&self, buf: &mut Buffer, right: Rect, state: &mut ResultPageState) {
5761
let right_block = Block::bordered()
5862
.border_type(BorderType::Plain)
59-
.border_style(Style::default().fg(Color::Yellow))
63+
.border_style(Style::default().fg(Color::Rgb(255, 165, 0)))
64+
.title_alignment(Alignment::Center)
65+
.title("Submission Results")
6066
.title_bottom("Press q to quit...")
61-
.title_style(Style::default().fg(Color::Red))
62-
.title_alignment(Alignment::Right);
67+
.title_style(Style::default().fg(Color::Magenta));
6368

6469
let result_text = self
6570
.result_text
@@ -70,8 +75,9 @@ impl ResultPage {
7075
}
7176

7277
pub fn handle_key_event(&mut self, state: &mut ResultPageState) {
73-
if event::poll(std::time::Duration::from_millis(50)).unwrap() {
74-
if let Event::Key(key) = event::read().unwrap() {
78+
// Use a non-blocking poll
79+
if let Ok(true) = event::poll(std::time::Duration::from_millis(0)) {
80+
if let Ok(Event::Key(key)) = event::read() {
7581
if key.kind != KeyEventKind::Press {
7682
return;
7783
}
@@ -115,10 +121,13 @@ impl StatefulWidget for &ResultPage {
115121
type State = ResultPageState;
116122

117123
fn render(self, area: Rect, buf: &mut Buffer, state: &mut ResultPageState) {
124+
// Increment animation frame on every render
125+
state.animation_frame = state.animation_frame.wrapping_add(1);
126+
118127
let layout = Layout::horizontal([Constraint::Percentage(45), Constraint::Percentage(55)]);
119128
let [left, right] = layout.areas(area);
120129

121-
self.render_left(buf, left);
130+
self.render_left(buf, left, state);
122131
self.render_right(buf, right, state);
123132

124133
let vertical_scrollbar =

0 commit comments

Comments
 (0)