Skip to content

Commit

Permalink
add general help text
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Jan 12, 2024
1 parent 0fc3f47 commit b5951a1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
20 changes: 19 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use crossterm::{
terminal::{disable_raw_mode, enable_raw_mode},
};
use network::network::{handle_tokio, Network, NetworkEvent};
use ratatui::style::{Color, Style};
use ratatui::widgets::Paragraph;
use util::constants::{GENERAL_HELP_TEXT, TICK_RATE};

use crate::widgets::{
chart::{render_chart, TokenChart},
Expand Down Expand Up @@ -78,7 +81,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
enable_raw_mode().expect("can run in raw mode");

let (tx, rx) = mpsc::channel();
let tick_rate = Duration::from_millis(200);
let tick_rate = Duration::from_millis(TICK_RATE);

// Start tick thread
thread::spawn(move || {
Expand Down Expand Up @@ -162,6 +165,15 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Render table at the bottom
f.render_stateful_widget(render_table(&mut table), chunks[2], &mut table.state);
//Render the help text at the bottom
let help_text = Paragraph::new(GENERAL_HELP_TEXT)
.style(Style::default().fg(Color::White))
.block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain),
);
f.render_widget(help_text, chunks[2]);
})?;

// #TODO: Move this to event handling
Expand All @@ -173,6 +185,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
KeyCode::Char('e') => {
app.input_mode = InputMode::Editing;
}
KeyCode::Char('q') => {
disable_raw_mode()?;
terminal.clear()?;
terminal.show_cursor()?;
break;
}
_ => {}
},
InputMode::Editing => match event.code {
Expand Down
2 changes: 1 addition & 1 deletion src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Default for Route {
fn default() -> Self {
Self {
id: RouteId::Welcome,
active_block: ActiveBlock::MyPositions,
active_block: ActiveBlock::SearchBar,
}
}
}
Empty file added src/widgets/home.rs
Empty file.
18 changes: 15 additions & 3 deletions src/widgets/search.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ratatui::{prelude::*, widgets::*};

use crate::app::App;
use crate::{app::App, models::states::InputMode, routes::ActiveBlock};

pub fn render_search_block<'a>(
outer: Rect,
Expand All @@ -15,8 +15,20 @@ pub fn render_search_block<'a>(
};

let searchbar_block = Block::default()
.border_style(Style::default())
.title(format!("Search by Address / ENS"))
.border_style(Style::default().fg(
if let ActiveBlock::SearchBar = app.get_current_route().get_active_block() {
Color::Green
} else {
Color::White
},
))
.title(format!(
"Search by Address / ENS ({})",
match app.input_mode {
InputMode::Normal => "Press 'q' to exit, 'e' to start editing.",
InputMode::Editing => "Press 'Esc' to stop editing, 'Enter' to search.",
}
))
.borders(Borders::ALL)
.border_type(BorderType::Plain);

Expand Down

0 comments on commit b5951a1

Please sign in to comment.