Skip to content

Commit

Permalink
UI improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-cpsn committed Feb 19, 2024
1 parent 10c415a commit ce4da21
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 25 deletions.
32 changes: 31 additions & 1 deletion src/app/app_states.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use ratatui::prelude::Span;
use ratatui::style::Stylize;
use ratatui::text::Line;
use strum::Display;
use crate::app::app::App;
use crate::app::app_states::AppState::*;
Expand Down Expand Up @@ -39,6 +42,30 @@ pub enum AppState {
const TEXT_INPUT_KEYS: &str = "Esc Enter ← → copy paste";

impl App<'_> {
pub fn get_state_line(&self) -> Line {
match self.state {
Normal | CreatingNewRequest => Line::from(self.state.to_string().white().on_dark_gray()),
_ => {
let selected_request_index = self.collection.selected.unwrap();
let selected_request = &self.collection.items[selected_request_index];

if self.state == SelectedRequest {
Line::from(vec![
Span::raw("Request > ").dark_gray(),
Span::raw(selected_request.name).white().on_dark_gray()
])
}
else {
Line::from(vec![
Span::raw("Request > ").dark_gray(),
Span::raw(format!("{} > ", selected_request.name)).dark_gray(),
Span::raw(self.state.to_string()).white().on_dark_gray()
])
}
}
}
}

pub fn get_available_keys(&self) -> String {
match self.state {
Normal => String::from("(q)uit or ^c ↑ ↓ ← → (n)ew (d)elete"),
Expand All @@ -50,7 +77,10 @@ impl App<'_> {
let mut base_keys = String::from("Esc Space ^TAB (u)rl (m)ethod ^(p)arams ^(a)uth ^(b)ody");

let additional_keys = match self.request_param_tab {
RequestParamsTabs::Params => Some("↑ ↓ ← → Enter"),
RequestParamsTabs::Params => match selected_request.params.is_empty() {
true => None,
false => Some("↑ ↓ ← → Enter")
},
RequestParamsTabs::Auth => match selected_request.auth {
Auth::NoAuth => None,
Auth::BasicAuth(_, _) => Some("↑ ↓ Enter"),
Expand Down
39 changes: 32 additions & 7 deletions src/app/request_ui/param_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use ratatui::layout::{Constraint, Layout, Rect};
use ratatui::layout::Direction::{Horizontal, Vertical};
use ratatui::prelude::{Color, Style};
use ratatui::style::Color::{LightYellow, Yellow};
use ratatui::style::Stylize;
use ratatui::style::{Modifier, Stylize};
use ratatui::text::{Line};
use ratatui::widgets::{Block, Borders, List, ListItem, Paragraph, Tabs};
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};
use crate::app::app::App;
Expand Down Expand Up @@ -136,7 +137,17 @@ impl App<'_> {
match self.request_param_tab {
RequestParamsTabs::Params => {
match self.request_param_table.selection {
None => {}
None => {
let params_lines = vec![
Line::default(),
Line::from("No params"),
Line::from("(Add one via the URL)".dark_gray())
];

let params_paragraph = Paragraph::new(params_lines).centered();

frame.render_widget(params_paragraph, request_params_layout[1]);
},
Some(param_selection) => {
let params_layout = Layout::new(
Vertical,
Expand Down Expand Up @@ -200,8 +211,8 @@ impl App<'_> {
let mut right_list_style = Style::default().fg(LightYellow);

match param_selection.1 {
0 => left_list_style = left_list_style.fg(Yellow).bold(),
1 => right_list_style = right_list_style.fg(Yellow).bold(),
0 => left_list_style = left_list_style.fg(Yellow).add_modifier(Modifier::BOLD),
1 => right_list_style = right_list_style.fg(Yellow).add_modifier(Modifier::BOLD),
_ => {}
}

Expand Down Expand Up @@ -255,8 +266,15 @@ impl App<'_> {
RequestParamsTabs::Auth => {
match &request.auth {
NoAuth => {
let body_paragraph = Paragraph::new("\nNo auth").centered();
frame.render_widget(body_paragraph, request_params_layout[1]);
let auth_lines = vec![
Line::default(),
Line::from("No auth"),
Line::from("(Change auth method with ^a)".dark_gray())
];

let auth_paragraph = Paragraph::new(auth_lines).centered();

frame.render_widget(auth_paragraph, request_params_layout[1]);
}
BasicAuth(_, _) => {
let basic_auth_layout = Layout::new(
Expand Down Expand Up @@ -379,7 +397,14 @@ impl App<'_> {
RequestParamsTabs::Body => {
match &request.body {
NoBody => {
let body_paragraph = Paragraph::new("\nNo body").centered();
let body_lines = vec![
Line::default(),
Line::from("No body"),
Line::from("(Change body type with ^b)".dark_gray())
];

let body_paragraph = Paragraph::new(body_lines).centered();

frame.render_widget(body_paragraph, request_params_layout[1]);
}
Raw(_) | JSON(_) | XML(_) | HTML(_) => {
Expand Down
20 changes: 3 additions & 17 deletions src/app/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,11 @@ impl App<'_> {

// FOOTER

let state_text = match self.state {
Normal | CreatingNewRequest => self.state.to_string(),
_ => {
let selected_request_index = self.collection.selected.unwrap();
let selected_request = &self.collection.items[selected_request_index];

if self.state == SelectedRequest {
format!("Request > {}", selected_request.name)
}
else {
format!("Request > {} > {}", selected_request.name, self.state.to_string())
}
}
};

let state_line = self.get_state_line();
let available_keys = self.get_available_keys();

let footer = Block::new()
.title(Title::from(state_text).alignment(Alignment::Left))
.title(Title::from(state_line).alignment(Alignment::Left))
.title(Title::from(available_keys.dark_gray()).alignment(Alignment::Right));

frame.render_widget(footer, main_layout[2]);
Expand All @@ -129,7 +115,7 @@ impl App<'_> {

let list = List::new(items)
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
.highlight_symbol("> ")
.highlight_symbol(">")
.block(
Block::default()
.title("Collection")
Expand Down

0 comments on commit ce4da21

Please sign in to comment.