Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
[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"
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"
assert_cmd = "2"
41 changes: 40 additions & 1 deletion src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -204,11 +207,13 @@ fn run_app<B: Backend>(
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') => {
Expand Down Expand Up @@ -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("↑"))
Expand Down