Skip to content

Commit

Permalink
Make request fullscreenable, clean up fullscreen logic
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPickering committed Nov 2, 2023
1 parent 9c12638 commit 96d81c3
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 98 deletions.
3 changes: 2 additions & 1 deletion src/tui/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl InputEngine {
}),
},
InputBinding::new(KeyCode::Char('r'), Action::ReloadCollection),
InputBinding::new(KeyCode::Char(' '), Action::Fullscreen),
InputBinding::new(KeyCode::F(11), Action::Fullscreen),
InputBinding::new(KeyCode::BackTab, Action::FocusPrevious),
InputBinding::new(KeyCode::Tab, Action::FocusNext),
InputBinding::new(KeyCode::Up, Action::Up),
Expand Down Expand Up @@ -174,6 +174,7 @@ impl Display for KeyCombination {
KeyCode::Right => write!(f, "→"),
KeyCode::Esc => write!(f, "<esc>"),
KeyCode::Enter => write!(f, "<enter>"),
KeyCode::F(num) => write!(f, "F{}", num),
KeyCode::Char(' ') => write!(f, "<space>"),
KeyCode::Char(c) => write!(f, "<{c}>"),
// Punting on everything else until we need it
Expand Down
24 changes: 14 additions & 10 deletions src/tui/view/component/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ impl Component for ErrorModal {
fn update(
&mut self,
_context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
match message {
match event {
// Extra close action
Event::Input {
action: Some(Action::Interact),
..
} => UpdateOutcome::Propagate(Event::CloseModal),

_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}
}
Expand Down Expand Up @@ -149,9 +149,9 @@ impl Component for PromptModal {
fn update(
&mut self,
_context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
match message {
match event {
// Submit
Event::Input {
action: Some(Action::Interact),
Expand All @@ -163,15 +163,19 @@ impl Component for PromptModal {
UpdateOutcome::Propagate(Event::CloseModal)
}

// All other input gets forwarded to the text editor (except cancel)
Event::Input { event, action }
if action != Some(Action::Cancel) =>
{
// Make sure cancel gets propagated to close the modal
event @ Event::Input {
action: Some(Action::Cancel),
..
} => UpdateOutcome::Propagate(event),

// All other input gets forwarded to the text editor
Event::Input { event, .. } => {
self.text_area.input(event);
UpdateOutcome::Consumed
}

_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/tui/view/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
input::{Action, InputEngine},
message::{Message, MessageSender},
view::{
component::root::RootMode,
component::root::FullscreenMode,
state::{Notification, RequestState},
theme::Theme,
Frame,
Expand Down Expand Up @@ -46,10 +46,10 @@ pub trait Component: Debug + Display {
fn update(
&mut self,
_context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
// By default just forward to our parent
UpdateOutcome::Propagate(message)
UpdateOutcome::Propagate(event)
}

/// Which, if any, of this component's children currently has focus? The
Expand Down Expand Up @@ -139,8 +139,8 @@ pub enum Event {
state: RequestState,
},

/// Change the root view mode
OpenView(RootMode),
/// Enter a particular fullscreen mode. If we're already in that mode, exit
ToggleFullscreen(FullscreenMode),

/// Show a modal to the user
OpenModal {
Expand Down
8 changes: 4 additions & 4 deletions src/tui/view/component/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl Component for ModalQueue {
fn update(
&mut self,
_context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
match message {
match event {
// Close the active modal. If there's no modal open, we'll propagate
// the event down
Event::Input {
Expand All @@ -111,7 +111,7 @@ impl Component for ModalQueue {
UpdateOutcome::Consumed
}
// Modal wasn't open, so don't consume the event
None => UpdateOutcome::Propagate(message),
None => UpdateOutcome::Propagate(event),
}
}

Expand All @@ -121,7 +121,7 @@ impl Component for ModalQueue {
UpdateOutcome::Consumed
}

_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}

Expand Down
28 changes: 19 additions & 9 deletions src/tui/view/component/primary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ impl PrimaryView {
self.profile_list_pane.profiles.selected()
}

/// Expose request pane, for fullscreening
pub fn request_pane(&self) -> &RequestPane {
&self.request_pane
}

/// Expose request pane, for fullscreening
pub fn request_pane_mut(&mut self) -> &mut RequestPane {
&mut self.request_pane
}

/// Expose response pane, for fullscreening
pub fn response_pane(&self) -> &ResponsePane {
&self.response_pane
Expand All @@ -97,9 +107,9 @@ impl Component for PrimaryView {
fn update(
&mut self,
context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
match message {
match event {
// Send HTTP request (bubbled up from child)
Event::HttpSendRequest => {
if let Some(recipe) = self.selected_recipe() {
Expand Down Expand Up @@ -130,7 +140,7 @@ impl Component for PrimaryView {
UpdateOutcome::Consumed
}

_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}

Expand Down Expand Up @@ -236,9 +246,9 @@ impl Component for ProfileListPane {
fn update(
&mut self,
_context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
match message {
match event {
Event::Input {
action: Some(Action::Up),
..
Expand All @@ -253,7 +263,7 @@ impl Component for ProfileListPane {
self.profiles.next();
UpdateOutcome::Consumed
}
_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}
}
Expand Down Expand Up @@ -299,7 +309,7 @@ impl Component for RecipeListPane {
fn update(
&mut self,
context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
let mut load_from_repo = |pane: &RecipeListPane| -> UpdateOutcome {
if let Some(recipe) = pane.recipes.selected() {
Expand All @@ -310,7 +320,7 @@ impl Component for RecipeListPane {
UpdateOutcome::Consumed
};

match message {
match event {
Event::Input {
action: Some(Action::Interact),
..
Expand All @@ -333,7 +343,7 @@ impl Component for RecipeListPane {
self.recipes.next();
load_from_repo(self)
}
_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions src/tui/view/component/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
input::Action,
view::{
component::{
primary::PrimaryPane, Component, Draw, Event, UpdateContext,
UpdateOutcome,
primary::PrimaryPane, root::FullscreenMode, Component, Draw,
Event, UpdateContext, UpdateOutcome,
},
state::{FixedSelect, StatefulSelect},
util::{layout, BlockBrick, TabBrick, ToTui},
Expand Down Expand Up @@ -45,9 +45,9 @@ impl Component for RequestPane {
fn update(
&mut self,
_context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
match message {
match event {
Event::Input {
action: Some(action),
..
Expand All @@ -60,9 +60,15 @@ impl Component for RequestPane {
self.tabs.next();
UpdateOutcome::Consumed
}
_ => UpdateOutcome::Propagate(message),

// Enter fullscreen
Action::Fullscreen => UpdateOutcome::Propagate(
Event::ToggleFullscreen(FullscreenMode::Request),
),

_ => UpdateOutcome::Propagate(event),
},
_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}
}
Expand Down
22 changes: 8 additions & 14 deletions src/tui/view/component/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::tui::{
input::Action,
view::{
component::{
primary::PrimaryPane, root::RootMode, Component, Draw, Event,
primary::PrimaryPane, root::FullscreenMode, Component, Draw, Event,
UpdateContext, UpdateOutcome,
},
state::{FixedSelect, RequestState, StatefulSelect},
Expand Down Expand Up @@ -43,9 +43,9 @@ impl Component for ResponsePane {
fn update(
&mut self,
_context: &mut UpdateContext,
message: Event,
event: Event,
) -> UpdateOutcome {
match message {
match event {
Event::Input {
action: Some(action),
..
Expand All @@ -62,16 +62,12 @@ impl Component for ResponsePane {

// Enter fullscreen
Action::Fullscreen => UpdateOutcome::Propagate(
Event::OpenView(RootMode::Response),
Event::ToggleFullscreen(FullscreenMode::Response),
),
// Exit fullscreen
Action::Cancel => {
UpdateOutcome::Propagate(Event::OpenView(RootMode::Primary))
}

_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
},
_ => UpdateOutcome::Propagate(message),
_ => UpdateOutcome::Propagate(event),
}
}
}
Expand Down Expand Up @@ -172,9 +168,7 @@ impl<'a> Draw<ResponsePaneProps<'a>> for ResponsePane {
// Main content for the response
match self.tabs.selected() {
ResponseTab::Body => {
// Render the pretty body if it's available,
// otherwise fall back to the regular one
let body: &str = pretty_body
let body = pretty_body
.as_deref()
.unwrap_or(response.body.text());
frame.render_widget(
Expand All @@ -194,7 +188,7 @@ impl<'a> Draw<ResponsePaneProps<'a>> for ResponsePane {
}

// Sadge
RequestState::RequestError { error, .. } => {
RequestState::RequestError { error } => {
frame.render_widget(
Paragraph::new(error.to_tui(context))
.wrap(Wrap::default()),
Expand Down
Loading

0 comments on commit 96d81c3

Please sign in to comment.