Skip to content

Commit

Permalink
refactor: changing crossterm style to ratatui style on theme
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 1, 2024
1 parent db39c05 commit 4070300
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 79 deletions.
4 changes: 1 addition & 3 deletions reqtui/src/text_object/text_object.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::str::{Chars, FromStr};

use ratatui::{
style::{Color, Style, Styled},
style::Styled,
text::{Line, Span},
widgets::Paragraph,
};
Expand Down
5 changes: 1 addition & 4 deletions tui/src/components/api_explorer/api_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ impl<'a> ApiExplorer<'a> {

fn draw_background(&self, size: Rect, frame: &mut Frame) {
frame.render_widget(Clear, size);
frame.render_widget(
Block::default().bg(self.colors.primary.background.into()),
size,
);
frame.render_widget(Block::default().bg(self.colors.primary.background), size);
}

fn draw_sidebar(&mut self, frame: &mut Frame) {
Expand Down
4 changes: 2 additions & 2 deletions tui/src/components/api_explorer/req_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl<'a> StatefulWidget for ReqUri<'a> {

fn render(self, size: Rect, buf: &mut Buffer, state: &mut Self::State) {
let block_border = if state.is_focused {
Style::default().fg(self.colors.bright.magenta.into())
Style::default().fg(self.colors.bright.magenta)
} else {
Style::default().fg(self.colors.primary.hover.into())
Style::default().fg(self.colors.primary.hover)
};

if let Some(req) = state.selected_request {
Expand Down
16 changes: 8 additions & 8 deletions tui/src/components/api_explorer/res_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use reqtui::net::request_manager::ReqtuiResponse;
use ratatui::{
buffer::Buffer,
layout::{Constraint, Direction, Layout, Rect},
style::{Style, Styled, Stylize},
text::{Line, Span},
style::{Style, Stylize},
text::Line,
widgets::{
Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget,
Tabs, Widget,
Expand Down Expand Up @@ -87,9 +87,9 @@ impl<'a> ResViewer<'a> {

fn draw_container(&self, size: Rect, buf: &mut Buffer, state: &mut ResViewerState) {
let block_border = match (state.is_focused, state.is_selected) {
(true, false) => Style::default().fg(self.colors.bright.magenta.into()),
(true, true) => Style::default().fg(self.colors.bright.yellow.into()),
(_, _) => Style::default().fg(self.colors.primary.hover.into()),
(true, false) => Style::default().fg(self.colors.bright.magenta),
(true, true) => Style::default().fg(self.colors.bright.yellow),
(_, _) => Style::default().fg(self.colors.primary.hover),
};

let block = Block::default()
Expand All @@ -101,12 +101,12 @@ impl<'a> ResViewer<'a> {

fn draw_tabs(&self, buf: &mut Buffer, state: &ResViewerState, size: Rect) {
let tabs = Tabs::new(["Pretty", "Raw", "Cookies", "Headers"])
.style(Style::default().fg(self.colors.primary.hover.into()))
.style(Style::default().fg(self.colors.primary.hover))
.select(state.curr_tab.clone().into())
.highlight_style(
Style::default()
.fg(self.colors.bright.magenta.into())
.bg(self.colors.primary.hover.into()),
.fg(self.colors.bright.magenta)
.bg(self.colors.primary.hover),
);
tabs.render(size, buf);
}
Expand Down
24 changes: 12 additions & 12 deletions tui/src/components/api_explorer/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ impl<'a> StatefulWidget for Sidebar<'a> {
.collect::<Vec<Paragraph>>();

let block_border = if state.is_focused {
Style::default().fg(self.colors.bright.magenta.into())
Style::default().fg(self.colors.bright.magenta)
} else {
// TODO: we need better border colors
Style::default().fg(self.colors.primary.hover.into())
Style::default().fg(self.colors.primary.hover)
};

let block = Block::default()
Expand Down Expand Up @@ -111,10 +111,10 @@ fn build_lines(

let dir_style = match is_hovered {
true => Style::default()
.fg(colors.normal.white.into())
.bg(colors.primary.hover.into())
.fg(colors.normal.white)
.bg(colors.primary.hover)
.bold(),
false => Style::default().fg(colors.normal.white.into()).bold(),
false => Style::default().fg(colors.normal.white).bold(),
};

let gap = " ".repeat(level * 2);
Expand Down Expand Up @@ -152,15 +152,15 @@ fn build_lines(

let req_style = match (is_selected, is_hovered) {
(true, true) => Style::default()
.fg(colors.normal.yellow.into())
.bg(colors.primary.accent.into()),
.fg(colors.normal.yellow)
.bg(colors.primary.accent),
(true, _) => Style::default()
.fg(colors.normal.white.into())
.bg(colors.primary.accent.into()),
.fg(colors.normal.white)
.bg(colors.primary.accent),
(_, true) => Style::default()
.fg(colors.normal.white.into())
.bg(colors.primary.hover.into()),
(false, false) => Style::default().fg(colors.normal.white.into()),
.fg(colors.normal.white)
.bg(colors.primary.hover),
(false, false) => Style::default().fg(colors.normal.white),
};

let line: Line<'_> = vec![
Expand Down
8 changes: 4 additions & 4 deletions tui/src/components/confirm_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ impl<'a> ConfirmPopup<'a> {
Paragraph::new(lines).wrap(Wrap { trim: true }).block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(self.colors.bright.black.into()))
.border_style(Style::default().fg(self.colors.bright.black))
.padding(Padding::new(2, 2, 1, 1))
.bg(self.colors.normal.black.into()),
.bg(self.colors.normal.black),
)
}
}
Expand Down Expand Up @@ -69,9 +69,9 @@ mod tests {
let expected = Paragraph::new(lines).wrap(Wrap { trim: true }).block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(colors.bright.black.into()))
.border_style(Style::default().fg(colors.bright.black))
.padding(Padding::new(2, 2, 1, 1))
.bg(colors.normal.black.into()),
.bg(colors.normal.black),
);

let content = popup.build_popup();
Expand Down
25 changes: 10 additions & 15 deletions tui/src/components/dashboard/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl<'a> Dashboard<'a> {
let hint =
"[h/j/k/l to move] [n -> new] [enter -> select item] [? -> help] [<C-c> -> quit]"
.fg(self.colors.normal.magenta)
.to_centered_line();
.into_centered_line();

frame.render_widget(hint, self.layout.hint_pane);
}
Expand All @@ -332,7 +332,7 @@ impl<'a> Dashboard<'a> {

let overlay = Paragraph::new(lines)
.fg(self.colors.primary.hover)
.bg(self.colors.primary.background.into())
.bg(self.colors.primary.background)
.bold();

frame.render_widget(overlay, size);
Expand Down Expand Up @@ -390,11 +390,9 @@ impl<'a> Dashboard<'a> {
frame.render_widget(Clear, self.layout.help_popup);
frame.render_widget(
Paragraph::new(lines).wrap(Wrap { trim: true }).block(
Block::default().padding(Padding::new(2, 2, 1, 1)).bg(self
.colors
.primary
.background
.into()),
Block::default()
.padding(Padding::new(2, 2, 1, 1))
.bg(self.colors.primary.background),
),
self.layout.help_popup,
);
Expand Down Expand Up @@ -425,7 +423,7 @@ impl<'a> Dashboard<'a> {

let no_matches = BigText::builder()
.pixel_size(PixelSize::Quadrant)
.style(Style::default().fg(self.colors.normal.magenta.into()))
.style(Style::default().fg(self.colors.normal.magenta))
.lines(vec!["No matches".into()])
.alignment(Alignment::Center)
.build()?;
Expand All @@ -448,7 +446,7 @@ impl<'a> Dashboard<'a> {

let empty_message = BigText::builder()
.pixel_size(PixelSize::Quadrant)
.style(Style::default().fg(self.colors.normal.magenta.into()))
.style(Style::default().fg(self.colors.normal.magenta))
.lines(vec!["No schemas".into()])
.alignment(Alignment::Center)
.build()?;
Expand All @@ -460,10 +458,7 @@ impl<'a> Dashboard<'a> {

fn draw_background(&self, size: Rect, frame: &mut Frame) {
frame.render_widget(Clear, size);
frame.render_widget(
Block::default().bg(self.colors.primary.background.into()),
size,
);
frame.render_widget(Block::default().bg(self.colors.primary.background), size);
}

fn draw_error_popup(&self, frame: &mut Frame) {
Expand Down Expand Up @@ -508,7 +503,7 @@ impl<'a> Dashboard<'a> {
fn draw_title(&self, frame: &mut Frame) -> anyhow::Result<()> {
let title = BigText::builder()
.pixel_size(PixelSize::Quadrant)
.style(Style::default().fg(self.colors.bright.magenta.into()))
.style(Style::default().fg(self.colors.bright.magenta))
.lines(vec!["Select a collection".into()])
.alignment(Alignment::Center)
.build()?;
Expand Down Expand Up @@ -964,7 +959,7 @@ mod tests {
dashboard.draw_background(size, &mut frame);

for cell in frame.buffer_mut().content.iter() {
assert_eq!(cell.bg, colors.primary.background.into());
assert_eq!(cell.bg, colors.primary.background);
}
}

Expand Down
10 changes: 5 additions & 5 deletions tui/src/components/dashboard/new_collection_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,36 @@ impl StatefulWidget for NewCollectionForm<'_> {
let cancel_text = if state.focused_field.eq(&FormFocus::Cancel) {
"Cancel"
.fg(self.colors.normal.white)
.bg(self.colors.normal.red.into())
.bg(self.colors.normal.red)
} else {
"Cancel".fg(self.colors.normal.white)
};

let cancel_button = Paragraph::new(Line::from(cancel_text).centered()).block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(self.colors.bright.red.into()))
.border_style(Style::default().fg(self.colors.bright.red))
.border_type(BorderType::Rounded),
);

let confirm_text = if state.focused_field.eq(&FormFocus::Confirm) {
"Create"
.fg(self.colors.normal.white)
.bg(self.colors.normal.magenta.into())
.bg(self.colors.normal.magenta)
} else {
"Create".fg(self.colors.normal.white)
};

let confirm_button = Paragraph::new(Line::from(confirm_text).centered()).block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(self.colors.bright.magenta.into()))
.border_style(Style::default().fg(self.colors.bright.magenta))
.border_type(BorderType::Rounded),
);

let full_block = Block::default()
.padding(Padding::uniform(1))
.style(Style::default().bg(self.colors.primary.background.into()));
.style(Style::default().bg(self.colors.primary.background));

let hint = Paragraph::new("[Tab] to switch focus [Enter] to select a button")
.centered()
Expand Down
6 changes: 3 additions & 3 deletions tui/src/components/dashboard/schema_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> SchemaList<'a> {
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(border_color.into())),
.border_style(Style::default().fg(border_color)),
)
}
}
Expand All @@ -131,7 +131,7 @@ impl StatefulWidget for SchemaList<'_> {
.position(state.scroll);

let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
.style(Style::default().fg(self.colors.normal.magenta.into()))
.style(Style::default().fg(self.colors.normal.magenta))
.begin_symbol(Some("↑"))
.end_symbol(Some("↓"));

Expand Down Expand Up @@ -232,7 +232,7 @@ mod tests {
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(colors.primary.hover.into())),
.border_style(Style::default().fg(colors.primary.hover)),
);

let card = schema_list.build_card(&state, &schemas[0], 0);
Expand Down
12 changes: 6 additions & 6 deletions tui/src/components/error_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a> ErrorPopup<'a> {
let message = Paragraph::new(self.message.clone().fg(self.colors.normal.red))
.wrap(Wrap { trim: true });

let confirmation = Paragraph::new("(O)k".fg(self.colors.normal.green).to_centered_line())
let confirmation = Paragraph::new("(O)k".fg(self.colors.normal.green).into_centered_line())
.wrap(Wrap { trim: true });

(message, confirmation)
Expand Down Expand Up @@ -54,9 +54,9 @@ impl<'a> ErrorPopup<'a> {
fn build_container(&self) -> Block<'_> {
Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(self.colors.bright.black.into()))
.border_style(Style::default().fg(self.colors.bright.black))
.padding(Padding::new(2, 2, 1, 1))
.bg(self.colors.normal.black.into())
.bg(self.colors.normal.black)
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ mod tests {

assert_eq!(
confirmation,
Paragraph::new("(O)k".fg(colors.normal.green).to_centered_line())
Paragraph::new("(O)k".fg(colors.normal.green).into_centered_line())
.wrap(Wrap { trim: true })
);
}
Expand All @@ -121,9 +121,9 @@ mod tests {

let expected = Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(colors.bright.black.into()))
.border_style(Style::default().fg(colors.bright.black))
.padding(Padding::new(2, 2, 1, 1))
.bg(colors.normal.black.into());
.bg(colors.normal.black);

let block = popup.build_container();

Expand Down
Loading

0 comments on commit 4070300

Please sign in to comment.