Skip to content

Commit

Permalink
Merge 6d4b637 into a18ed61
Browse files Browse the repository at this point in the history
  • Loading branch information
omid committed Jan 24, 2022
2 parents a18ed61 + 6d4b637 commit 4255662
Show file tree
Hide file tree
Showing 19 changed files with 414 additions and 391 deletions.
519 changes: 255 additions & 264 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -12,19 +12,19 @@ homepage = "https://github.com/kdash-rs/kdash"
readme = "README.md"
license = "MIT"
exclude = ["assets/*", ".github", "Makefile.toml", "CONTRIBUTING.md", "*.log", "tags"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[badges]

[dependencies]
crossterm = "0.22.1"
tui = { version = "0.16.0", default-features = false, features = ['crossterm'] }
tui = { version = "0.17.0", default-features = false, features = ['crossterm'] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.8"
clap = "2.33.3"
clap = "3.0.10"
tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] }
tokio-stream = { version = "0.1.8", features = ["time"] }
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
@@ -1,5 +1,5 @@
tab_spaces=2
edition = "2018"
edition = "2021"
reorder_imports = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
Expand Down
2 changes: 1 addition & 1 deletion src/app/key_binding.rs
Expand Up @@ -62,7 +62,7 @@ pub enum HContext {
}

impl fmt::Display for HContext {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/metrics.rs
Expand Up @@ -47,7 +47,7 @@ pub struct KubeNodeMetrics {
}

impl KubeNodeMetrics {
pub fn from_api(metric: &NodeMetrics, app: &MutexGuard<App>) -> Self {
pub fn from_api(metric: &NodeMetrics, app: &MutexGuard<'_, App>) -> Self {
let name = metric.metadata.name.clone().unwrap_or_default();

let (cpu_percent, mem_percent) = match app.data.node_metrics.iter().find(|it| it.name == name) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/models.rs
Expand Up @@ -271,9 +271,9 @@ impl LogsState {
/// Render the current state as a list widget
pub fn render_list<B: Backend>(
&mut self,
f: &mut Frame<B>,
f: &mut Frame<'_, B>,
logs_area: Rect,
block: Block,
block: Block<'_>,
style: Style,
follow: bool,
) {
Expand Down Expand Up @@ -316,7 +316,7 @@ impl LogsState {
.map(|s| s.to_string())
.map(|c| Span::styled(c, style))
.map(ListItem::new)
.collect::<Vec<ListItem>>(),
.collect::<Vec<ListItem<'_>>>(),
logs_area.width,
));

Expand Down
2 changes: 1 addition & 1 deletion src/app/nodes.rs
Expand Up @@ -36,7 +36,7 @@ impl KubeNode {
pub fn from_api_with_pods(
node: &Node,
pods_list: &ObjectList<Pod>,
app: &mut MutexGuard<App>,
app: &mut MutexGuard<'_, App>,
) -> Self {
let node_name = node.metadata.name.clone().unwrap_or_default();
let unschedulable = &node
Expand Down
12 changes: 6 additions & 6 deletions src/banner.rs
@@ -1,6 +1,6 @@
pub const BANNER: &str = "
_ __ ___ _
| |/ /| \\ __ _ ___| |_
| ' < | |) |/ _` |(_-<| ' \\
|_|\\_\\|___/ \\__,_|/__/|_||_|
";
pub const BANNER: &str = r#" _ ______ _
| |/ / _ \ __ _ ___| |__
| ' /| | | |/ _` / __| '_ \
| . \| |_| | (_| \__ \ | | |
|_|\_\____/ \__,_|___/_| |_|
"#;
12 changes: 6 additions & 6 deletions src/cli.rs
Expand Up @@ -22,23 +22,23 @@ impl Cli {
}

/// create a new clapapp instance
pub fn get_clap_app<'a, 'b>(&mut self) -> ClapApp<'a, 'b> {
pub fn get_clap_app<'a>(&mut self) -> ClapApp<'a> {
ClapApp::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.usage("Press `?` while running the app to see keybindings")
.override_usage("Press `?` while running the app to see keybindings")
.before_help(BANNER)
.arg(
Arg::with_name("tick-rate")
.short("t")
Arg::new("tick-rate")
.short('t')
.long("tick-rate")
.help("Set the tick rate (milliseconds): the lower the number the higher the FPS.")
.takes_value(true),
)
.arg(
Arg::with_name("poll-rate")
.short("p")
Arg::new("poll-rate")
.short('p')
.long("poll-rate")
.help("Set the network call polling rate (milliseconds, should be multiples of tick-rate): the lower the number the higher the network calls.")
.takes_value(true),
Expand Down
2 changes: 1 addition & 1 deletion src/event/key.rs
Expand Up @@ -92,7 +92,7 @@ impl Key {
}

impl fmt::Display for Key {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Key::Alt(' ') => write!(f, "<Alt+Space>"),
Key::Ctrl(' ') => write!(f, "<Ctrl+Space>"),
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/mod.rs
Expand Up @@ -40,7 +40,9 @@ pub async fn handle_key_events(key: Key, app: &mut App) {
app.refresh();
}
_ if key == DEFAULT_KEYBINDING.help.key => {
app.push_navigation_stack(RouteId::HelpMenu, ActiveBlock::Help)
if app.get_current_route().active_block != ActiveBlock::Help {
app.push_navigation_stack(RouteId::HelpMenu, ActiveBlock::Help);
}
}
_ if key == DEFAULT_KEYBINDING.jump_to_all_context.key => {
app.route_contexts();
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
@@ -1,3 +1,4 @@
#![warn(rust_2018_idioms)]
#[deny(clippy::shadow_unrelated)]
mod app;
mod banner;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/contexts.rs
Expand Up @@ -14,8 +14,8 @@ use super::{
};
use crate::app::App;

pub fn draw_contexts<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
let title = format!("Contexts [{}]", app.data.contexts.items.len());
pub fn draw_contexts<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let title = format!(" Contexts [{}] ", app.data.contexts.items.len());
let block = layout_block_active(title.as_str());

if !app.data.contexts.items.is_empty() {
Expand Down
12 changes: 6 additions & 6 deletions src/ui/help.rs
Expand Up @@ -14,7 +14,7 @@ use super::{
};
use crate::app::App;

pub fn draw_help<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
pub fn draw_help<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let chunks = vertical_chunks(vec![Constraint::Percentage(100)], area);

// Create a one-column table to avoid flickering due to non-determinism when
Expand All @@ -37,7 +37,7 @@ pub fn draw_help<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
.iter()
.map(|item| Row::new(item.clone()).style(style_primary()));

let title = title_with_dual_style("Help ".into(), "| close <esc>".into(), app.light_theme);
let title = title_with_dual_style(" Help ".into(), "| close <esc> ".into(), app.light_theme);

let help_menu = Table::new(rows)
.header(Row::new(header).style(style_secondary()).bottom_margin(0))
Expand Down Expand Up @@ -73,24 +73,24 @@ mod tests {
.unwrap();

let mut expected = Buffer::with_lines(vec![
"Help | close <esc>────────────────────────────────────────────────────────────────────────────────┐",
"Help | close <esc> ──────────────────────────────────────────────────────────────────────────────",
"│ Key Action Conte│",
"│=> <Ctrl+c> | <q> Quit Gener│",
"│ <Esc> Close child page/Go back Gener│",
"│ <?> Help page Gener│",
"│ <Enter> Select table row Gener│",
"──────────────────────────────────────────────────────────────────────────────────────────────────",
"──────────────────────────────────────────────────────────────────────────────────────────────────",
]);
// set row styles
// First row heading style
for col in 0..=99 {
match col {
0 | 19..=99 => {
0 | 21..=99 => {
expected
.get_mut(col, 0)
.set_style(Style::default().fg(Color::Yellow));
}
1..=5 => {
1..=6 => {
expected.get_mut(col, 0).set_style(
Style::default()
.fg(Color::Yellow)
Expand Down
19 changes: 10 additions & 9 deletions src/ui/mod.rs
Expand Up @@ -9,7 +9,7 @@ use tui::{
backend::Backend,
layout::{Alignment, Constraint, Rect},
text::{Span, Spans, Text},
widgets::{Block, Borders, Paragraph, Tabs, Wrap},
widgets::{Block, BorderType, Borders, Paragraph, Tabs, Wrap},
Frame,
};

Expand All @@ -27,7 +27,7 @@ use crate::app::{App, RouteId};

static HIGHLIGHT: &str = "=> ";

pub fn draw<B: Backend>(f: &mut Frame<B>, app: &mut App) {
pub fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App) {
let block = Block::default().style(style_main_background(app.light_theme));
f.render_widget(block, f.size());

Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, app: &mut App) {
}
}

fn draw_app_header<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
fn draw_app_header<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let chunks =
horizontal_chunks_with_margin(vec![Constraint::Length(75), Constraint::Min(0)], area, 1);

Expand All @@ -85,7 +85,7 @@ fn draw_app_header<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
draw_header_text(f, app, chunks[1]);
}

fn draw_header_text<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
fn draw_header_text<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let text = match app.get_current_route().id {
RouteId::Contexts => vec![Spans::from(
"<up|down>: scroll context | <enter>: select context | <?> more help",
Expand All @@ -94,9 +94,9 @@ fn draw_header_text<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
"<left|right>: switch resource tabs | <char> select block | <up|down>: scroll | <enter>: select | <?> more help",
)],
RouteId::Utilization => vec![Spans::from(
"<up|down>: scroll | <g>: cycle through grouping | <?> more help",
" <up|down>: scroll | <g>: cycle through grouping | <?> more help",
)],
_ => vec![Spans::from("<?> more help")],
_ => vec![Spans::default()],
};
let paragraph = Paragraph::new(text)
.style(style_help())
Expand All @@ -106,11 +106,12 @@ fn draw_header_text<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
f.render_widget(paragraph, area);
}

fn draw_app_error<B: Backend>(f: &mut Frame<B>, app: &mut App, size: Rect) {
fn draw_app_error<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, size: Rect) {
let block = Block::default()
.title("Error | close <esc>")
.title(" Error | close <esc> ")
.style(style_failure())
.borders(Borders::ALL);
.borders(Borders::ALL)
.border_type(BorderType::Rounded);

let mut text = Text::from(app.api_error.clone());
text.patch_style(style_failure());
Expand Down
40 changes: 22 additions & 18 deletions src/ui/overview.rs
Expand Up @@ -2,7 +2,7 @@ use tui::{
backend::Backend,
layout::{Constraint, Rect},
text::{Span, Spans, Text},
widgets::{Block, Borders, Cell, LineGauge, Paragraph, Row, Table},
widgets::{Block, BorderType, Borders, Cell, LineGauge, Paragraph, Row, Table},
Frame,
};

Expand All @@ -20,7 +20,7 @@ use crate::{
banner::BANNER,
};

pub fn draw_overview<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
pub fn draw_overview<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
if app.show_info_bar {
let chunks = vertical_chunks(vec![Constraint::Length(9), Constraint::Min(10)], area);
draw_status_block(f, app, chunks[0]);
Expand All @@ -30,27 +30,27 @@ pub fn draw_overview<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
}
}

fn draw_status_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
fn draw_status_block<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let chunks = horizontal_chunks(
vec![
Constraint::Length(30),
Constraint::Length(35),
Constraint::Min(10),
Constraint::Length(40),
Constraint::Length(30),
Constraint::Length(32),
],
area,
);

draw_cli_version_block(f, app, chunks[0]);
draw_namespaces_block(f, app, chunks[0]);
draw_context_info_block(f, app, chunks[1]);
draw_namespaces_block(f, app, chunks[2]);
draw_cli_version_block(f, app, chunks[2]);
draw_logo_block(f, app, chunks[3])
}

fn draw_logo_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
fn draw_logo_block<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
// Banner text with correct styling
let text = format!(
"{}\nv{} with ♥ in Rust {}",
"{}\n v{} with ♥ in Rust {}",
BANNER,
env!("CARGO_PKG_VERSION"),
nw_loading_indicator(app.is_loading)
Expand All @@ -59,12 +59,16 @@ fn draw_logo_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
text.patch_style(style_logo());

// Contains the banner
let paragraph = Paragraph::new(text).block(Block::default().borders(Borders::ALL));
let paragraph = Paragraph::new(text).block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded),
);
f.render_widget(paragraph, area);
}

fn draw_cli_version_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
let block = layout_block_default("CLI Info");
fn draw_cli_version_block<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let block = layout_block_default(" CLI Info ");
if !app.data.clis.is_empty() {
let rows = app.data.clis.iter().map(|s| {
let style = if s.status {
Expand All @@ -81,14 +85,14 @@ fn draw_cli_version_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rec

let table = Table::new(rows)
.block(block)
.widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]);
.widths(&[Constraint::Length(15), Constraint::Length(15)]);
f.render_widget(table, area);
} else {
loading(f, block, area, app.is_loading);
}
}

fn draw_context_info_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
fn draw_context_info_block<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let chunks = vertical_chunks_with_margin(
vec![
Constraint::Length(3),
Expand All @@ -99,7 +103,7 @@ fn draw_context_info_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Re
1,
);

let block = layout_block_default("Context Info (toggle <i>)");
let block = layout_block_default(" Context Info (toggle <i>) ");

f.render_widget(block, area);

Expand Down Expand Up @@ -154,9 +158,9 @@ fn draw_context_info_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Re
f.render_widget(mem_gauge, chunks[2]);
}

fn draw_namespaces_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
fn draw_namespaces_block<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let title = format!(
"Namespaces {} (all: {})",
" Namespaces {} (all: {}) ",
DEFAULT_KEYBINDING.jump_to_namespace.key, DEFAULT_KEYBINDING.select_all_namespace.key
);
let mut block = layout_block_default(title.as_str());
Expand Down Expand Up @@ -184,7 +188,7 @@ fn draw_namespaces_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect
.block(block)
.highlight_style(style_highlight())
.highlight_symbol(HIGHLIGHT)
.widths(&[Constraint::Percentage(80), Constraint::Percentage(20)]);
.widths(&[Constraint::Length(22), Constraint::Length(6)]);

f.render_stateful_widget(table, area, &mut app.data.namespaces.state);
} else {
Expand Down

0 comments on commit 4255662

Please sign in to comment.