Skip to content

Commit

Permalink
Merge pull request #10 from DevCleaner/develop
Browse files Browse the repository at this point in the history
add current path
  • Loading branch information
yacosta738 authored Dec 18, 2021
2 parents be16c83 + aa99c38 commit 4333d63
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
10 changes: 1 addition & 9 deletions src/app/key_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ generate_keybindings! {
jump_to_deployments,
jump_to_jobs,
jump_to_daemonsets,
jump_to_more_resources,
cycle_group_by
jump_to_more_resources
}

#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
pub enum HContext {
General,
Overview,
Utilization,
}

impl fmt::Display for HContext {
Expand Down Expand Up @@ -274,12 +272,6 @@ pub const DEFAULT_KEYBINDING: KeyBindings = KeyBindings {
desc: "Select more resources",
context: HContext::Overview,
},
cycle_group_by: KeyBinding {
key: Key::Char('g'),
alt: None,
desc: "Cycle through grouping",
context: HContext::Utilization,
},
};

pub fn get_help_docs() -> Vec<Vec<String>> {
Expand Down
8 changes: 4 additions & 4 deletions src/banner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub const BANNER: &str = "
__ _ __ __ _ ___ _ _
| \\| | V | |/ / | | | |
| | ' | \\_/ | <| | |_| |_
|_|\\__|_| |_|_|\\_\\_|___|___|
___ _______
/ _ \\___ _ __/ ___/ /__ ___ ____ ___ ____
/ // / -_) |/ / /__/ / -_) _ `/ _ \\/ -_) __/
/____/\\__/|___/\\___/_/\\__/\\_,_/_//_/\\__/_/
";
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::{App as ClapApp, Arg};
use std::env;

use super::banner::BANNER;

Expand All @@ -15,7 +16,7 @@ pub struct Cli {
impl Cli {
pub fn new() -> Cli {
Cli {
path: "".to_string(),
path: env::current_dir().unwrap().to_str().unwrap().to_string(),
criteria: "node_modules".into(),
enhanced_graphics: true,
}
Expand All @@ -33,7 +34,6 @@ impl Cli {
Arg::with_name("path")
.short("p")
.long("path")
.required(true)
.help("Set the path to scan for the criteria.")
.takes_value(true),
)
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn main() -> Result<()> {
Ok(())
}

async fn start_ui(_cli: Cli, app: &Arc<Mutex<App>>) -> Result<()> {
async fn start_ui(cli: Cli, app: &Arc<Mutex<App>>) -> Result<()> {
// Terminal initialization
let mut stdout = stdout();
// not capturing mouse to make text select/copy possible
Expand Down Expand Up @@ -89,7 +89,7 @@ async fn start_ui(_cli: Cli, app: &Arc<Mutex<App>>) -> Result<()> {
}
};
// draw the UI layout
terminal.draw(|f| ui::draw(f, &mut app))?;
terminal.draw(|f| ui::draw(f, &mut app, &cli))?;

// handle key events
match events.next()? {
Expand Down
18 changes: 10 additions & 8 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
mod control_panel;
mod help;
mod overview;
mod utils;

use tui::{
backend::Backend,
layout::{Constraint, Rect},
Expand All @@ -11,16 +6,23 @@ use tui::{
Frame,
};

use crate::app::{App, RouteId};
use crate::Cli;

use self::{
help::draw_help,
overview::draw_overview,
utils::{style_failure, style_main_background, style_primary, vertical_chunks},
};
use crate::app::{App, RouteId};

mod control_panel;
mod help;
mod overview;
mod utils;

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, cli: &Cli) {
let block = Block::default().style(style_main_background(app.light_theme));
f.render_widget(block, f.size());

Expand All @@ -45,7 +47,7 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, app: &mut App) {
draw_help(f, app, last_chunk);
}
_ => {
draw_overview(f, app, last_chunk);
draw_overview(f, app, cli, last_chunk);
}
}
}
Expand Down
26 changes: 17 additions & 9 deletions src/ui/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ use tui::{
use crate::app::RouteId;
use crate::ui::control_panel::draw_control_panel_block;
use crate::ui::utils::{layout_block, style_help, title_style_logo};
use crate::{app::App, banner::BANNER};
use crate::{app::App, banner::BANNER, Cli};

use super::utils::{
horizontal_chunks, style_default, style_logo, style_primary, vertical_chunks,
vertical_chunks_with_margin,
};

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, cli: &Cli, 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]);
draw_status_block(f, app, cli, chunks[0]);
draw_control_panel_block(f, app, chunks[1]);
} else {
draw_control_panel_block(f, app, area);
}
}

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

draw_context_info_block(f, app, chunks[0]);
draw_general_info_block(f, app, cli, chunks[0]);
draw_logo_block(f, app, chunks[1]);
}

Expand All @@ -52,10 +52,10 @@ fn draw_logo_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
f.render_widget(paragraph, area);
}

fn draw_context_info_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
fn draw_general_info_block<B: Backend>(f: &mut Frame<B>, app: &mut App, cli: &Cli, area: Rect) {
let chunks = vertical_chunks_with_margin(
vec![
Constraint::Length(3),
Constraint::Length(4),
Constraint::Min(2),
Constraint::Min(2),
],
Expand All @@ -74,6 +74,14 @@ fn draw_context_info_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Re
project_size += project.size;
}
let text = vec![
Spans::from(vec![
Span::styled("Path: ", style_default(app.light_theme)),
Span::styled(cli.path.clone(), style_primary()),
]),
Spans::from(vec![
Span::styled("Criteria: ", style_default(app.light_theme)),
Span::styled(cli.criteria.clone(), style_primary()),
]),
Spans::from(vec![
Span::styled("Projects: ", style_default(app.light_theme)),
Span::styled(project_count.to_string(), style_primary()),
Expand All @@ -93,7 +101,7 @@ fn draw_context_info_block<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Re
fn draw_header_text<B: Backend>(f: &mut Frame<B>, app: &mut App, area: Rect) {
let text = match app.get_current_route().id {
RouteId::Home => vec![Spans::from(
"<up|down>: scroll context | <enter>: select context | <?> more help",
"<up|down>: move | <enter>: select and delete | <?> more help",
)],
_ => vec![Spans::from("<?> more help")],
};
Expand Down

0 comments on commit 4333d63

Please sign in to comment.