Skip to content

Commit

Permalink
add inline viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat authored and conradludgate committed Mar 23, 2023
1 parent ba1d615 commit 1200524
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ version = "0.3"
default-features = false
features = ["ansi", "fmt", "registry", "env-filter"]
optional = true

[patch.crates-io]
ratatui = { git = "https://github.com/conradludgate/tui-rs-revival", branch = "inline" }
16 changes: 12 additions & 4 deletions src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use ratatui::{
style::{Color, Modifier, Style},
text::{Span, Spans, Text},
widgets::{Block, BorderType, Borders, Paragraph},
Frame, Terminal,
Frame, Terminal, TerminalOptions, Viewport,
};

const RETURN_ORIGINAL: usize = usize::MAX;
Expand Down Expand Up @@ -469,7 +469,7 @@ impl Stdout {
let mut stdout = stdout();
execute!(
stdout,
terminal::EnterAlternateScreen,
// terminal::EnterAlternateScreen,
event::EnableMouseCapture,
event::EnableBracketedPaste
)?;
Expand All @@ -481,7 +481,7 @@ impl Drop for Stdout {
fn drop(&mut self) {
execute!(
self.stdout,
terminal::LeaveAlternateScreen,
// terminal::LeaveAlternateScreen,
event::DisableMouseCapture,
event::DisableBracketedPaste
)
Expand Down Expand Up @@ -528,7 +528,12 @@ pub async fn history(
) -> Result<String> {
let stdout = Stdout::new()?;
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let mut terminal = Terminal::with_options(
backend,
TerminalOptions {
viewport: Viewport::Inline(24),
},
)?;

let mut input = Cursor::from(query.join(" "));
// Put the cursor at the end of the query by default
Expand Down Expand Up @@ -603,6 +608,9 @@ pub async fn history(
results = app.query_results(db).await?;
}
};

terminal.clear()?;

if index < results.len() {
// index is in bounds so we return that entry
Ok(results.swap_remove(index).command.clone())
Expand Down

0 comments on commit 1200524

Please sign in to comment.