From 2e3642d48064f4fc66c3ca96ed641e130480e83c Mon Sep 17 00:00:00 2001 From: Lucas Pickering Date: Tue, 28 Nov 2023 15:10:57 -0800 Subject: [PATCH] Fullscreen improvements --- CHANGELOG.md | 2 + src/tui/view/component.rs | 4 +- src/tui/view/component/primary.rs | 61 ++++++++++++++++++++---------- src/tui/view/component/request.rs | 40 +++++--------------- src/tui/view/component/response.rs | 55 ++++----------------------- src/tui/view/event.rs | 4 -- 6 files changed, 62 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 661bc8b2..ed431b5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ ### Changed - Always show help text in footer, regardless of notification state +- Add highlight border to fullscreened pane +- Allow exiting fullscreen mode with ESC ## [0.8.0] - 2023-11-21 diff --git a/src/tui/view/component.rs b/src/tui/view/component.rs index 2a2b46fd..1a991a8f 100644 --- a/src/tui/view/component.rs +++ b/src/tui/view/component.rs @@ -8,15 +8,15 @@ pub mod response; pub mod root; pub mod settings; +pub use root::Root; + use crate::tui::view::{ draw::{Draw, DrawContext}, event::{Event, EventHandler, Update, UpdateContext}, }; use crossterm::event::MouseEvent; use derive_more::{Deref, DerefMut}; -pub use primary::FullscreenMode; use ratatui::layout::Rect; -pub use root::Root; use std::cell::Cell; /// A wrapper around the various component types. The main job of this is to diff --git a/src/tui/view/component/primary.rs b/src/tui/view/component/primary.rs index 867576f9..598e4f98 100644 --- a/src/tui/view/component/primary.rs +++ b/src/tui/view/component/primary.rs @@ -69,7 +69,7 @@ pub enum PrimaryPane { /// shown in fullscreen. If one of these is requested while not available, we /// simply won't show it. #[derive(Copy, Clone, Debug, PartialEq)] -pub enum FullscreenMode { +enum FullscreenMode { /// Fullscreen the active request recipe Request, /// Fullscreen the active response @@ -106,6 +106,15 @@ impl PrimaryView { fn selected_profile(&self) -> Option<&Profile> { self.profile_list_pane.profiles.selected() } + + fn toggle_fullscreen(&mut self, mode: FullscreenMode) { + // If we're already in the given mode, exit + self.fullscreen_mode = if Some(mode) == self.fullscreen_mode { + None + } else { + Some(mode) + }; + } } impl EventHandler for PrimaryView { @@ -127,10 +136,10 @@ impl EventHandler for PrimaryView { // Input messages Event::Input { - action, + action: Some(action), event: term_event, } => match action { - Some(Action::LeftClick) => { + Action::LeftClick => { let crossterm::event::Event::Mouse(mouse) = term_event else { unreachable!("Mouse action must have mouse event") @@ -151,47 +160,57 @@ impl EventHandler for PrimaryView { } Update::Consumed } - Some(Action::PreviousPane) => { + Action::PreviousPane => { self.selected_pane.previous(context); Update::Consumed } - Some(Action::NextPane) => { + Action::NextPane => { self.selected_pane.next(context); Update::Consumed } - Some(Action::SendRequest) => { + Action::SendRequest => { // Send a request from anywhere context.queue_event(Event::HttpSendRequest); Update::Consumed } - Some(Action::OpenSettings) => { + Action::OpenSettings => { context.queue_event(Event::OpenModal { modal: Box::::default(), priority: ModalPriority::Low, }); Update::Consumed } - Some(Action::OpenHelp) => { + Action::OpenHelp => { context.queue_event(Event::OpenModal { modal: Box::::default(), priority: ModalPriority::Low, }); Update::Consumed } + + // Toggle fullscreen + Action::Fullscreen => { + match self.selected_pane.selected() { + // These aren't fullscreenable. Still consume the event + // though, no one else will need it anyway + PrimaryPane::ProfileList | PrimaryPane::RecipeList => {} + PrimaryPane::Request => { + self.toggle_fullscreen(FullscreenMode::Request) + } + PrimaryPane::Response => { + self.toggle_fullscreen(FullscreenMode::Response) + } + } + Update::Consumed + } + // Exit fullscreen + Action::Cancel if self.fullscreen_mode.is_some() => { + self.fullscreen_mode = None; + Update::Consumed + } _ => Update::Propagate(event), }, - Event::ToggleFullscreen(mode) => { - // If we're already in the given mode, exit - self.fullscreen_mode = - if Some(mode) == self.fullscreen_mode.as_ref() { - None - } else { - Some(*mode) - }; - Update::Consumed - } - _ => Update::Propagate(event), } } @@ -294,7 +313,7 @@ impl<'a> Draw> for PrimaryView { self.request_pane.draw( context, RequestPaneProps { - is_selected: false, + is_selected: true, selected_recipe: self.selected_recipe(), selected_profile_id: self .selected_profile() @@ -307,7 +326,7 @@ impl<'a> Draw> for PrimaryView { self.response_pane.draw( context, ResponsePaneProps { - is_selected: false, + is_selected: true, active_request: props.active_request, }, area, diff --git a/src/tui/view/component/request.rs b/src/tui/view/component/request.rs index cb6ad255..ea011d8e 100644 --- a/src/tui/view/component/request.rs +++ b/src/tui/view/component/request.rs @@ -1,20 +1,17 @@ use crate::{ collection::{ProfileId, RequestRecipe, RequestRecipeId}, template::Template, - tui::{ - input::Action, - view::{ - common::{ - table::Table, tabs::Tabs, template_preview::TemplatePreview, - text_window::TextWindow, Block, - }, - component::primary::{FullscreenMode, PrimaryPane}, - draw::{Draw, DrawContext, Generate}, - event::{Event, EventHandler, Update, UpdateContext}, - state::StateCell, - util::layout, - Component, + tui::view::{ + common::{ + table::Table, tabs::Tabs, template_preview::TemplatePreview, + text_window::TextWindow, Block, }, + component::primary::PrimaryPane, + draw::{Draw, DrawContext, Generate}, + event::EventHandler, + state::StateCell, + util::layout, + Component, }, }; use derive_more::Display; @@ -65,23 +62,6 @@ enum Tab { } impl EventHandler for RequestPane { - fn update(&mut self, context: &mut UpdateContext, event: Event) -> Update { - match event { - // Toggle fullscreen - Event::Input { - action: Some(Action::Fullscreen), - .. - } => { - context.queue_event(Event::ToggleFullscreen( - FullscreenMode::Request, - )); - Update::Consumed - } - - _ => Update::Propagate(event), - } - } - fn children(&mut self) -> Vec> { let mut children = vec![self.tabs.as_child()]; // If the body is initialized and present, send events there too diff --git a/src/tui/view/component/response.rs b/src/tui/view/component/response.rs index dc950022..8c6f9896 100644 --- a/src/tui/view/component/response.rs +++ b/src/tui/view/component/response.rs @@ -1,18 +1,13 @@ use crate::{ http::{RequestId, RequestRecord}, - tui::{ - input::Action, - view::{ - common::{ - table::Table, tabs::Tabs, text_window::TextWindow, Block, - }, - component::primary::{FullscreenMode, PrimaryPane}, - draw::{Draw, DrawContext, Generate}, - event::{Event, EventHandler, Update, UpdateContext}, - state::{RequestState, StateCell}, - util::layout, - Component, - }, + tui::view::{ + common::{table::Table, tabs::Tabs, text_window::TextWindow, Block}, + component::primary::PrimaryPane, + draw::{Draw, DrawContext, Generate}, + event::EventHandler, + state::{RequestState, StateCell}, + util::layout, + Component, }, }; use derive_more::Display; @@ -45,23 +40,6 @@ enum Tab { } impl EventHandler for ResponsePane { - fn update(&mut self, context: &mut UpdateContext, event: Event) -> Update { - match event { - // Toggle fullscreen - Event::Input { - action: Some(Action::Fullscreen), - .. - } => { - context.queue_event(Event::ToggleFullscreen( - FullscreenMode::Response, - )); - Update::Consumed - } - - _ => Update::Propagate(event), - } - } - fn children(&mut self) -> Vec> { vec![self.content.as_child()] } @@ -185,23 +163,6 @@ struct ResponseContentProps<'a> { } impl EventHandler for ResponseContent { - fn update(&mut self, context: &mut UpdateContext, event: Event) -> Update { - match event { - // Toggle fullscreen - Event::Input { - action: Some(Action::Fullscreen), - .. - } => { - context.queue_event(Event::ToggleFullscreen( - FullscreenMode::Response, - )); - Update::Consumed - } - - _ => Update::Propagate(event), - } - } - fn children(&mut self) -> Vec> { let mut children = vec![self.tabs.as_child()]; if let Some(body) = self.body.get_mut() { diff --git a/src/tui/view/event.rs b/src/tui/view/event.rs index f52ad4ac..0a8812f1 100644 --- a/src/tui/view/event.rs +++ b/src/tui/view/event.rs @@ -8,7 +8,6 @@ use crate::{ message::{Message, MessageSender}, view::{ common::modal::{Modal, ModalPriority}, - component::FullscreenMode, state::{Notification, RequestState}, Component, ViewConfig, }, @@ -108,9 +107,6 @@ pub enum Event { state: RequestState, }, - /// Enter a particular fullscreen mode. If we're already in that mode, exit - ToggleFullscreen(FullscreenMode), - /// Show a modal to the user OpenModal { modal: Box,