Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Reiter committed Aug 10, 2024
1 parent 89661ee commit 8d94020
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 91 deletions.
6 changes: 3 additions & 3 deletions wireman/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ impl App {
if self.ctx.tab == Tab::Messages {
match self.ctx.messages_tab {
MessagesTab::Request => {
RequestEventHandler::handle_mouse_event(&mut self.ctx, event)
RequestEventHandler::handle_mouse_event(&mut self.ctx, event);
}
MessagesTab::Response => {
ResponseEventHandler::handle_mouse_event(&mut self.ctx, event)
ResponseEventHandler::handle_mouse_event(&mut self.ctx, event);
}
};
}
Expand All @@ -141,6 +141,6 @@ impl App {
E::Event: Display,
{
let key_mappings = E::format_event_mappings_as_strings(ctx);
ctx.help = Some(HelpContext::new(key_mappings))
ctx.help = Some(HelpContext::new(key_mappings));
}
}
24 changes: 6 additions & 18 deletions wireman/src/events/headers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{context::AppContext, model::headers::HeadersTab};
use crate::{context::AppContext, model::headers::HeadersTab, widgets::editor::TextEditor};
use std::fmt;
use tui_key_event_handler::{EventHandler, KeyCode, KeyEvent};

Expand Down Expand Up @@ -48,7 +48,7 @@ impl fmt::Display for HeadersEvents {
HeadersEvents::LoadHistory4 => "Load History 4",
HeadersEvents::LoadHistory5 => "Load History 5",
};
write!(f, "{}", display_str)
write!(f, "{display_str}")
}
}

Expand Down Expand Up @@ -79,22 +79,10 @@ impl EventHandler for HeadersEventHandler {
HeadersEvents::PrevRow => {
ctx.headers.borrow_mut().prev_row();
}
HeadersEvents::NextCol => {
HeadersEvents::NextCol | HeadersEvents::NextAuth | HeadersEvents::NextColForce => {
ctx.headers.borrow_mut().next_col();
}
HeadersEvents::PrevCol => {
ctx.headers.borrow_mut().prev_col();
}
HeadersEvents::NextAuth => {
ctx.headers.borrow_mut().next_col();
}
HeadersEvents::PrevAuth => {
ctx.headers.borrow_mut().prev_col();
}
HeadersEvents::NextColForce => {
ctx.headers.borrow_mut().next_col();
}
HeadersEvents::PrevColForce => {
HeadersEvents::PrevCol | HeadersEvents::PrevAuth | HeadersEvents::PrevColForce => {
ctx.headers.borrow_mut().prev_col();
}
HeadersEvents::Unselect => {
Expand Down Expand Up @@ -143,7 +131,7 @@ impl EventHandler for HeadersEventHandler {
None => (true, true),
};
let enable_switch_auth_tab = ctx.headers.borrow().tab == HeadersTab::Auth
&& selected_editor.map_or(true, |e| e.is_empty());
&& selected_editor.map_or(true, TextEditor::is_empty);
let enable_switch_col_force = ctx.headers.borrow().tab == HeadersTab::Meta;
let enable_next_col = enable_switch_col_force && is_last_col;
let enable_prev_col = enable_switch_col_force && is_first_col;
Expand Down Expand Up @@ -254,7 +242,7 @@ impl EventHandler for HeadersEventHandler {
.selected_editor_mut()
.on_key(key_event.clone().into());
}
_ => (),
HeadersTab::None => (),
}
}
}
4 changes: 2 additions & 2 deletions wireman/src/events/messages/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl fmt::Display for RequestEvents {
RequestEvents::LoadHistory4 => "Load History 4",
RequestEvents::LoadHistory5 => "Load History 5",
};
write!(f, "{}", display_str)
write!(f, "{display_str}")
}
}

Expand Down Expand Up @@ -177,6 +177,6 @@ impl EventHandler for RequestEventHandler {

fn pass_through_mouse_events(event: &MouseEvent, ctx: &mut Self::Context) {
let editor = &mut ctx.messages.borrow_mut().request.editor;
editor.on_mouse(event.clone().into());
editor.on_mouse(*event);
}
}
10 changes: 5 additions & 5 deletions wireman/src/events/messages/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl fmt::Display for ResponseEvents {
ResponseEvents::GoToRequest => "Go to Request",
ResponseEvents::CopyAsGrpCurl => "Copy as cURL",
};
write!(f, "{}", display_str)
write!(f, "{display_str}")
}
}

Expand Down Expand Up @@ -73,18 +73,18 @@ impl EventHandler for ResponseEventHandler {
map
}

fn pass_through_key_events(key_event: &KeyEvent, ctx: &mut Self::Context) {
fn pass_through_key_events(event: &KeyEvent, ctx: &mut Self::Context) {
// read only
if key_event.code == KeyCode::Char('i') {
if event.code == KeyCode::Char('i') {
return;
}
let response = &mut ctx.messages.borrow_mut().response.editor;
response.on_key(key_event.clone().into());
response.on_key(event.clone().into());
ctx.disable_root_events = !response.normal_mode();
}

fn pass_through_mouse_events(event: &MouseEvent, ctx: &mut Self::Context) {
let editor = &mut ctx.messages.borrow_mut().response.editor;
editor.on_mouse(event.clone().into());
editor.on_mouse(*event);
}
}
20 changes: 10 additions & 10 deletions wireman/src/events/selection/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl fmt::Display for MethodsSelectionEvents {
MethodsSelectionEvents::ClearSearch => "Clear Search",
MethodsSelectionEvents::GoToServices => "Go to Services",
};
write!(f, "{}", display_str)
write!(f, "{display_str}")
}
}

Expand Down Expand Up @@ -93,12 +93,7 @@ impl EventHandler for MethodsSelectionEventsHandler {
let method_selected = ctx.selection.borrow().selected_method().is_some();
let filter_active = ctx.selection.borrow_mut().methods_filter.is_some();
let mut map = Vec::new();
if !method_selected {
map.extend([(
KeyEvent::new(KeyCode::Enter),
MethodsSelectionEvents::Select,
)]);
} else {
if method_selected {
map.extend([
(
KeyEvent::new(KeyCode::Enter),
Expand All @@ -110,16 +105,21 @@ impl EventHandler for MethodsSelectionEventsHandler {
MethodsSelectionEvents::PrevTab,
),
]);
} else {
map.extend([(
KeyEvent::new(KeyCode::Enter),
MethodsSelectionEvents::Select,
)]);
}
if !filter_active {
if filter_active {
map.extend([(
KeyEvent::new(KeyCode::Esc),
MethodsSelectionEvents::Unselect,
MethodsSelectionEvents::ClearSearch,
)]);
} else {
map.extend([(
KeyEvent::new(KeyCode::Esc),
MethodsSelectionEvents::ClearSearch,
MethodsSelectionEvents::Unselect,
)]);
}
map.extend(vec![
Expand Down
2 changes: 1 addition & 1 deletion wireman/src/events/selection/methods_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl fmt::Display for MethodsSearchEvents {
MethodsSearchEvents::Finish => "Finish",
MethodsSearchEvents::RemoveChar => "Remove Character",
};
write!(f, "{}", display_str)
write!(f, "{display_str}")
}
}

Expand Down
4 changes: 2 additions & 2 deletions wireman/src/events/selection/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl fmt::Display for ServicesSelectionEvents {
ServicesSelectionEvents::ClearSearch => "Clear Search",
ServicesSelectionEvents::GoToMethods => "Go to Methods",
};
write!(f, "{}", display_str)
write!(f, "{display_str}")
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ impl EventHandler for ServicesSelectionEventsHandler {
map.extend([(
KeyEvent::new(KeyCode::Esc),
ServicesSelectionEvents::ClearSearch,
)])
)]);
}
map
}
Expand Down
2 changes: 1 addition & 1 deletion wireman/src/events/selection/services_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl fmt::Display for ServicesSearchEvents {
ServicesSearchEvents::Finish => "Finish",
ServicesSearchEvents::RemoveChar => "Remove Character",
};
write!(f, "{}", display_str)
write!(f, "{display_str}")
}
}

Expand Down
4 changes: 2 additions & 2 deletions wireman/src/model/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl HeadersModel {
HeadersTab::Addr => Some(&self.addr),
HeadersTab::Auth => Some(self.auth.selected_editor()),
HeadersTab::Meta => self.meta.selected_editor(),
_ => None,
HeadersTab::None => None,
}
}

Expand All @@ -61,7 +61,7 @@ impl HeadersModel {
HeadersTab::Addr => Some(&mut self.addr),
HeadersTab::Auth => Some(self.auth.selected_editor_mut()),
HeadersTab::Meta => self.meta.selected_editor_mut(),
_ => None,
HeadersTab::None => None,
}
}
/// Whether any editor is currently in insert mode
Expand Down
2 changes: 1 addition & 1 deletion wireman/src/model/headers/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ impl MetaHeaders {
}

fn next_col(col: &mut usize) {
*col = (*col + 1) % 2
*col = (*col + 1) % 2;
}
49 changes: 9 additions & 40 deletions wireman/src/view/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,21 @@ impl<'a> HeadersPage<'a> {
Self { model }
}

pub fn footer_keys(&self) -> Vec<(&'static str, &'static str)> {
match self.model.tab {
HeadersTab::Addr => {
vec![
("^c", "Quit"),
("Tab", "Next Tab"),
("↑/k", "Up"),
("↓/j", "Down"),
("?", "Show help"),
]
}
HeadersTab::Auth => {
vec![
("^c", "Quit"),
("Tab", "Next Tab"),
("↑/k", "Up"),
("↓/j", "Down"),
("?", "Show help"),
]
}
HeadersTab::Meta => {
vec![
("^c", "Quit"),
("Tab", "Next Tab"),
("↑/k", "Up"),
("↓/j", "Down"),
("?", "Show help"),
]
}
HeadersTab::None => {
vec![
("^c", "Quit"),
("Tab", "Next Tab"),
("↑/k", "Up"),
("↓/j", "Down"),
("?", "Show help"),
]
}
}
pub fn footer_keys() -> Vec<(&'static str, &'static str)> {
vec![
("^c", "Quit"),
("Tab", "Next Tab"),
("↑/k", "Up"),
("↓/j", "Down"),
("?", "Show help"),
]
}
}

impl Widget for HeadersPage<'_> {
fn render(self, area: Rect, buf: &mut ratatui::prelude::Buffer) {
let theme = theme::Theme::global();
let sl = if theme.editor.hide_status_line { 0 } else { 1 };
let sl = u16::from(!theme.editor.hide_status_line);
let [addr_title, addr_content, _, auth_title, auth_content, _, meta_title, meta_content, status] =
layout(area, Direction::Vertical, &[1, 3, 1, 1, 4, 1, 1, 0, sl]);

Expand Down
2 changes: 1 addition & 1 deletion wireman/src/view/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Widget for MessagesPage<'_> {
fn render(self, area: Rect, buf: &mut ratatui::prelude::Buffer) {
use ratatui::layout::Constraint::{Length, Min, Percentage};
let theme = theme::Theme::global();
let sl = if theme.editor.hide_status_line { 0 } else { 1 };
let sl = u16::from(!theme.editor.hide_status_line);
let [top, bottom, status] =
Layout::vertical([Percentage(50), Min(0), Length(sl)]).areas(area);

Expand Down
6 changes: 3 additions & 3 deletions wireman/src/view/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Root<'_> {
model: &mut self.ctx.messages.borrow_mut(),
tab: self.ctx.messages_tab,
}
.render(messages, buf)
.render(messages, buf);
}
Tab::Headers => {
//
Expand All @@ -65,7 +65,7 @@ impl Root<'_> {
)
.render(history, buf);

HeadersPage::new(&self.ctx.headers.borrow()).render(headers, buf)
HeadersPage::new(&self.ctx.headers.borrow()).render(headers, buf);
}
};
}
Expand All @@ -75,7 +75,7 @@ impl Root<'_> {
let keys = match self.ctx.tab {
Tab::Selection => SelectionPage::footer_keys(self.ctx.selection_tab),
Tab::Messages => MessagesPage::footer_keys(self.ctx.messages_tab),
Tab::Headers => HeadersPage::new(&self.ctx.headers.borrow()).footer_keys(),
Tab::Headers => HeadersPage::footer_keys(),
};
let spans: Vec<Span> = keys
.iter()
Expand Down
2 changes: 1 addition & 1 deletion wireman/src/view/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl<'a> SelectionPage<'a> {

impl Widget for SelectionPage<'_> {
fn render(self, area: Rect, buf: &mut ratatui::prelude::Buffer) {
let theme = Theme::global();
use ratatui::layout::Constraint::{Length, Min, Percentage};
let theme = Theme::global();
let [top, bottom] = Layout::vertical([Percentage(50), Percentage(50)]).areas(area);

let mut show_services_search = 0;
Expand Down
2 changes: 1 addition & 1 deletion wireman/src/widgets/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl TextEditor {
/// Handle mouse events.
pub fn on_mouse(&mut self, event: MouseEvent) {
let mouse = EditorMouse::default();
mouse.on_event(event, &mut self.state)
mouse.on_event(event, &mut self.state);
}
}

Expand Down

0 comments on commit 8d94020

Please sign in to comment.