Skip to content

Commit

Permalink
Make response pane fullscreenable
Browse files Browse the repository at this point in the history
This involved splitting up the view code a lot
  • Loading branch information
LucasPickering committed Nov 1, 2023
1 parent 3f2f6ff commit 2bfd149
Show file tree
Hide file tree
Showing 11 changed files with 833 additions and 611 deletions.
1 change: 1 addition & 0 deletions src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static TEMPLATE_REGEX: OnceLock<Regex> = OnceLock::new();

/// A string that can contain templated content
#[derive(Clone, Debug, Deref, Display, From, Serialize, Deserialize)]
#[deref(forward)]
pub struct TemplateString(String);

/// A little container struct for all the data that the user can access via
Expand Down
3 changes: 3 additions & 0 deletions src/tui/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl InputEngine {
}),
},
InputBinding::new(KeyCode::Char('r'), Action::ReloadCollection),
InputBinding::new(KeyCode::Char(' '), Action::Fullscreen),
InputBinding::new(KeyCode::BackTab, Action::FocusPrevious),
InputBinding::new(KeyCode::Tab, Action::FocusNext),
InputBinding::new(KeyCode::Up, Action::Up),
Expand Down Expand Up @@ -105,6 +106,8 @@ pub enum Action {
Right,
/// Do a thing. E.g. select an item in a list
Interact,
/// Embiggen a pane
Fullscreen,
/// Close the current modal/dialog/etc.
Cancel,
}
Expand Down
17 changes: 10 additions & 7 deletions src/tui/view/component/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
},
},
};
use derive_more::Display;
use itertools::Itertools;
use ratatui::{
prelude::{Alignment, Constraint, Direction, Rect},
Expand All @@ -24,7 +25,8 @@ use ratatui::{
use std::fmt::Debug;
use tui_textarea::TextArea;

#[derive(Debug)]
#[derive(Debug, Display)]
#[display(fmt = "ErrorModal")]
pub struct ErrorModal(anyhow::Error);

impl Modal for ErrorModal {
Expand All @@ -41,7 +43,7 @@ impl Component for ErrorModal {
fn update(&mut self, message: ViewMessage) -> UpdateOutcome {
match message {
// Extra close action
ViewMessage::InputAction {
ViewMessage::Input {
action: Some(Action::Interact),
..
} => UpdateOutcome::Propagate(ViewMessage::CloseModal),
Expand Down Expand Up @@ -94,13 +96,13 @@ impl IntoModal for anyhow::Error {
}

/// Inner state for the prompt modal
#[derive(Debug)]
#[derive(Debug, Display)]
#[display(fmt = "PromptModal")]
pub struct PromptModal {
// Prompt currently being shown
/// Prompt currently being shown
prompt: Prompt,
/// A queue of additional prompts to shown. If the queue is populated,
/// closing one prompt will open a the next one.
// queue: VecDeque<Prompt>,
text_area: TextArea<'static>,
/// Flag set before closing to indicate if we should submit in `on_close``
submit: bool,
Expand Down Expand Up @@ -142,7 +144,7 @@ impl Component for PromptModal {
fn update(&mut self, message: ViewMessage) -> UpdateOutcome {
match message {
// Submit
ViewMessage::InputAction {
ViewMessage::Input {
action: Some(Action::Interact),
..
} => {
Expand All @@ -153,7 +155,7 @@ impl Component for PromptModal {
}

// All other input gets forwarded to the text editor (except cancel)
ViewMessage::InputAction { event, action }
ViewMessage::Input { event, action }
if action != Some(Action::Cancel) =>
{
self.text_area.input(event);
Expand Down Expand Up @@ -201,6 +203,7 @@ impl Draw for HelpText {
Action::ReloadCollection,
Action::FocusNext,
Action::FocusPrevious,
Action::Fullscreen,
Action::Cancel,
];
let text = actions
Expand Down
Loading

0 comments on commit 2bfd149

Please sign in to comment.