diff --git a/Cargo.toml b/Cargo.toml index 7639ab6..72513c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "qk" -version = "0.1.4" +version = "0.1.9" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] crossterm = "0.27.0" -ratatui = "0.26.2" +ratatui = "0.29" regex = "1.8.4" config = "0.14.0" strum = "0.26.2" @@ -15,6 +15,7 @@ color-eyre = "0.6.3" clap = { version = "4.5.4", features = ["derive"] } rand = "0.9.0" thiserror = "2.0.12" +tui-piechart = "0.2.8" [dev-dependencies] -assert_cmd = "2" \ No newline at end of file +assert_cmd = "2" diff --git a/src/gui.rs b/src/gui.rs index f12ee30..9eca039 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -5,13 +5,15 @@ use crossterm::{event, execute}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}; use rand::Rng; use ratatui::backend::{Backend, CrosstermBackend}; +use ratatui::style::palette::tailwind; use ratatui::text::{Line, Span}; use ratatui::{Frame, Terminal}; use ratatui::layout::{Constraint, Layout, Rect}; use ratatui::prelude::Stylize; use ratatui::style::{Color, Style}; use color_eyre::eyre::{Result}; -use ratatui::widgets::{Block, Clear, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, Wrap}; +use ratatui::widgets::{Block, Clear, Gauge, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, Widget, Wrap}; +use tui_piechart::{PieChart, PieSlice}; use crate::kubectl::{self, FoundPod, KubectlRunnerAgent, get_pod_status}; use crate::cli::{self}; @@ -44,6 +46,7 @@ struct App { pub horizontal_scroll: usize, pub show_pod_deleted_pop_up: bool, pub show_switch_error_text: bool, + pub show_pie_chart_for_running_pods: bool, pub new_pod_search_pop_up: bool, pub input_text: String, pub target_pod: FoundPod, @@ -204,11 +207,13 @@ fn run_app( KeyCode::Char('w') => { text = kubectl::get_pods(&runner, &app.target_pod).unwrap(); app.vertical_scroll = 0; + app.show_pie_chart_for_running_pods = true; app.last_action = Some(InternalAction::World); }, KeyCode::Char('W') => { text = kubectl::get_all(&runner, &app.target_pod).unwrap(); app.vertical_scroll = 0; + app.show_pie_chart_for_running_pods = false; app.last_action = Some(InternalAction::World); }, KeyCode::Char('e') => { @@ -306,6 +311,40 @@ fn ui(f: &mut Frame, app: &mut App, text: &str) { .wrap(Wrap { trim: true }); f.render_widget(paragraph, chunks[1]); + + if app.last_action == Some(InternalAction::World) && app.show_pie_chart_for_running_pods == true { + let vertical_chunks = Layout::vertical([ + Constraint::Percentage(20), + Constraint::Percentage(60), + Constraint::Percentage(20), + ]) + .split(size); + + let horiz_chunks = Layout::horizontal([ + Constraint::Percentage(60), + Constraint::Percentage(40), + ]) + .split(vertical_chunks[1]); + + // Do really bad way of counting by coutning substr matches + let total_pods: f64 = text.lines().count() as f64; + let running_pods: f64 = text.matches("🏃").count() as f64; + let starting_pods: f64 = text.matches("✨️").count() as f64; + // Create slices + let slices = vec![ + PieSlice::new("Failed", (((&total_pods - (&starting_pods + &running_pods)) / &total_pods) * 100.0) + 0.0001, Color::Red), + PieSlice::new("Starting", ((&starting_pods / &total_pods) * 100.0) + 0.001, Color::Blue), + PieSlice::new("Running", ((&running_pods / &total_pods) * 100.0) + 0.001, Color::Green), + ]; + + let piechart = PieChart::new(slices) + .show_legend(true) + .show_percentages(true); + + f.render_widget(Block::new(), vertical_chunks[0]); + f.render_widget(piechart, horiz_chunks[1]); + } + f.render_stateful_widget( Scrollbar::new(ScrollbarOrientation::VerticalRight) .begin_symbol(Some("↑"))