Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keybinding to send request from anywhere #27

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

### Added

- Added top-level collection `id` field
- Add top-level collection `id` field
- Needed in order to give each collection its own history file
- Disable mouse capture to allow text highlighting [#17](https://github.com/LucasPickering/slumber/issues/17)
- Add keybinding (F2) to send request from any view

### Fixed

Expand Down
4 changes: 4 additions & 0 deletions src/tui/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl InputEngine {
Action::ForceQuit,
),
InputBinding::new(KeyCode::Char('r'), Action::ReloadCollection),
InputBinding::new(KeyCode::F(2), Action::SendRequest),
InputBinding::new(KeyCode::F(11), Action::Fullscreen),
InputBinding::new(KeyCode::BackTab, Action::PreviousPane),
InputBinding::new(KeyCode::Tab, Action::NextPane),
Expand Down Expand Up @@ -116,6 +117,9 @@ pub enum Action {

/// Do a thing. E.g. select an item in a list
Submit,
/// Send the active request from *any* context
#[display(fmt = "Send Request")]
SendRequest,
/// Embiggen a pane
Fullscreen,
/// Close the current modal/dialog/etc.
Expand Down
7 changes: 4 additions & 3 deletions src/tui/view/component/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ impl Draw<HelpTextProps> for HelpText {
// Decide which actions to show based on context. This is definitely
// spaghetti and easy to get out of sync, but it's the easiest way to
// get granular control
let mut actions = vec![Action::Quit, Action::ReloadCollection];
let mut actions =
vec![Action::Quit, Action::ReloadCollection, Action::SendRequest];

match props.fullscreen_mode {
None => {
actions.extend([Action::NextPane, Action::PreviousPane]);
// Pane-specific actions
actions.extend(match props.selected_pane {
PrimaryPane::ProfileList => [].as_slice(),
PrimaryPane::RecipeList => &[Action::Submit],
PrimaryPane::ProfileList => &[] as &[Action],
PrimaryPane::RecipeList => &[],
PrimaryPane::Request => &[Action::Fullscreen],
PrimaryPane::Response => &[Action::Fullscreen],
});
Expand Down
2 changes: 1 addition & 1 deletion src/tui/view/component/primary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl PrimaryView {
impl Component for PrimaryView {
fn update(&mut self, context: &mut UpdateContext, event: Event) -> Update {
match event {
// Send HTTP request (bubbled up from child)
// Send HTTP request (bubbled up from child *or* queued by parent)
Event::HttpSendRequest => {
if let Some(recipe) = self.selected_recipe() {
context.send_message(Message::HttpBeginRequest {
Expand Down
22 changes: 12 additions & 10 deletions src/tui/view/component/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,18 @@ impl Component for Root {
}

// Input messages
Event::Input {
action: Some(Action::Quit),
..
} => context.send_message(Message::Quit),
Event::Input {
action: Some(Action::ReloadCollection),
..
} => context.send_message(Message::CollectionStartReload),
// Any other user input should get thrown away
Event::Input { .. } => {}
Event::Input { action, .. } => match action {
Some(Action::Quit) => context.send_message(Message::Quit),
Some(Action::ReloadCollection) => {
context.send_message(Message::CollectionStartReload)
}
Some(Action::SendRequest) => {
// Send a request from anywhere
context.queue_event(Event::HttpSendRequest)
}
// Any other user input should get thrown away
_ => {}
},

// There shouldn't be anything left unhandled. Bubble up to log it
_ => return Update::Propagate(event),
Expand Down
Loading