-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from zaghaghi/12-add-support-for-searching-in-…
…the-apis-pane 12 add support for searching in the apis pane
- Loading branch information
Showing
11 changed files
with
197 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,7 @@ pub enum Action { | |
Go, | ||
Back, | ||
ToggleFullScreen, | ||
FocusFooter, | ||
Filter(String), | ||
Noop, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,89 @@ | ||
use std::sync::{Arc, RwLock}; | ||
|
||
use color_eyre::eyre::Result; | ||
use ratatui::prelude::*; | ||
use crossterm::event::{Event, KeyCode, KeyEvent}; | ||
use ratatui::{prelude::*, widgets::Paragraph}; | ||
use tui_input::{backend::crossterm::EventHandler, Input}; | ||
|
||
use crate::{pages::home::State, panes::Pane, tui::Frame}; | ||
use crate::{ | ||
action::Action, | ||
pages::home::State, | ||
panes::Pane, | ||
tui::{EventResponse, Frame}, | ||
}; | ||
|
||
#[derive(Default)] | ||
pub struct FooterPane { | ||
focused: bool, | ||
#[allow(dead_code)] | ||
state: Arc<RwLock<State>>, | ||
input: Input, | ||
} | ||
|
||
impl FooterPane { | ||
pub fn new(state: Arc<RwLock<State>>) -> Self { | ||
Self { state } | ||
Self { focused: false, state, input: Input::default() } | ||
} | ||
} | ||
|
||
impl Pane for FooterPane { | ||
fn focus(&mut self) -> Result<()> { | ||
self.focused = true; | ||
Ok(()) | ||
} | ||
|
||
fn unfocus(&mut self) -> Result<()> { | ||
self.focused = false; | ||
Ok(()) | ||
} | ||
|
||
fn height_constraint(&self) -> Constraint { | ||
Constraint::Max(1) | ||
} | ||
|
||
fn handle_key_events(&mut self, key: KeyEvent) -> Result<Option<EventResponse<Action>>> { | ||
self.input.handle_event(&Event::Key(key)); | ||
let response = match key.code { | ||
KeyCode::Enter => Some(EventResponse::Stop(Action::Filter(self.input.to_string()))), | ||
KeyCode::Esc => { | ||
let filter: String; | ||
{ | ||
let state = self.state.read().unwrap(); | ||
filter = state.active_filter.clone(); | ||
} | ||
Some(EventResponse::Stop(Action::Filter(filter))) | ||
}, | ||
_ => Some(EventResponse::Stop(Action::Noop)), | ||
}; | ||
Ok(response) | ||
} | ||
|
||
fn draw(&mut self, frame: &mut Frame<'_>, area: Rect) -> Result<()> { | ||
const ARROW: &str = symbols::scrollbar::HORIZONTAL.end; | ||
frame.render_widget( | ||
Line::from(vec![ | ||
Span::styled(format!("[l/h {ARROW} next/prev pane] [j/k {ARROW} next/prev item] [1-9 {ARROW} select tab] [g/b {ARROW} go/back definitions] [q {ARROW} quit]"), Style::default()), | ||
]) | ||
.style(Style::default().fg(Color::DarkGray)), | ||
area, | ||
); | ||
if self.focused { | ||
let search_label = "Filter: "; | ||
let width = area.width.max(3); | ||
let scroll = self.input.visual_scroll(width as usize); | ||
let input = Paragraph::new(Line::from(vec![ | ||
Span::styled(search_label, Style::default().fg(Color::LightBlue)), | ||
Span::styled(self.input.value(), Style::default()), | ||
])) | ||
.scroll((0, scroll as u16)); | ||
frame.render_widget(input, area); | ||
|
||
frame.set_cursor( | ||
area.x + ((self.input.visual_cursor()).max(scroll) - scroll) as u16 + search_label.len() as u16, | ||
area.y + 1, | ||
) | ||
} else { | ||
frame.render_widget( | ||
Line::from(vec![ | ||
Span::styled(format!("[l,h,j,k {ARROW} movement] [/ {ARROW} filter] [1-9 {ARROW} select tab] [g,b {ARROW} go/back definitions] [q {ARROW} quit]"), Style::default()), | ||
]) | ||
.style(Style::default().fg(Color::DarkGray)), | ||
area, | ||
); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Output static/filter.gif | ||
Hide | ||
Set Shell zsh | ||
|
||
Set FontSize 16 | ||
Set Width 1200 | ||
Set Height 600 | ||
|
||
Set Padding 20 | ||
Set FontFamily "JetBrains Mono" | ||
|
||
Set WindowBar Colorful | ||
Set WindowBarSize 40 | ||
|
||
Set Theme "Catppuccin Mocha" | ||
Type "cargo run -- --openapi-path examples/stripe/spec.yml" | ||
Enter | ||
Sleep 10s | ||
Set TypingSpeed 400ms | ||
Show | ||
Sleep 2s | ||
Type "/" | ||
Sleep 2s | ||
Type "balance" | ||
Enter | ||
Sleep 2s | ||
Type "j" | ||
Type "j" | ||
|
||
Sleep 5s | ||
Hide | ||
Type "q" | ||
Ctrl+D | ||
Show |