aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick Decat <pdecat@gmail.com>2023-03-25 18:27:20 +0100
committerGitHub <noreply@github.com>2023-03-25 17:27:20 +0000
commit13ce5f746c946f5695c55642a9af5ead8894f692 (patch)
tree897bf423b9cebff29654b2a32e45b99027fcb02a /src
parentRespect exit_mode setting when exiting with arrow down keypress (#807) (diff)
downloadatuin-13ce5f746c946f5695c55642a9af5ead8894f692.zip
feat: add an inline view mode (#648)
* add inline viewport * Add inline_height setting. Zero disables inline mode (the default)
Diffstat (limited to 'src')
-rw-r--r--src/command/client/search/interactive.rs40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/command/client/search/interactive.rs b/src/command/client/search/interactive.rs
index feec4171..6fd4e1d8 100644
--- a/src/command/client/search/interactive.rs
+++ b/src/command/client/search/interactive.rs
@@ -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;
@@ -466,29 +466,37 @@ impl State {
struct Stdout {
stdout: std::io::Stdout,
+ inline_mode: bool,
}
impl Stdout {
- pub fn new() -> std::io::Result<Self> {
+ pub fn new(inline_mode: bool) -> std::io::Result<Self> {
terminal::enable_raw_mode()?;
let mut stdout = stdout();
+ if !inline_mode {
+ execute!(stdout, terminal::EnterAlternateScreen)?;
+ }
execute!(
stdout,
- terminal::EnterAlternateScreen,
event::EnableMouseCapture,
- event::EnableBracketedPaste
+ event::EnableBracketedPaste,
)?;
- Ok(Self { stdout })
+ Ok(Self {
+ stdout,
+ inline_mode,
+ })
}
}
impl Drop for Stdout {
fn drop(&mut self) {
+ if !self.inline_mode {
+ execute!(self.stdout, terminal::LeaveAlternateScreen).unwrap();
+ }
execute!(
self.stdout,
- terminal::LeaveAlternateScreen,
event::DisableMouseCapture,
- event::DisableBracketedPaste
+ event::DisableBracketedPaste,
)
.unwrap();
terminal::disable_raw_mode().unwrap();
@@ -531,9 +539,18 @@ pub async fn history(
settings: &Settings,
db: &mut impl Database,
) -> Result<String> {
- let stdout = Stdout::new()?;
+ let stdout = Stdout::new(settings.inline_height > 0)?;
let backend = CrosstermBackend::new(stdout);
- let mut terminal = Terminal::new(backend)?;
+ let mut terminal = Terminal::with_options(
+ backend,
+ TerminalOptions {
+ viewport: if settings.inline_height > 0 {
+ Viewport::Inline(settings.inline_height)
+ } else {
+ Viewport::Fullscreen
+ },
+ },
+ )?;
let mut input = Cursor::from(query.join(" "));
// Put the cursor at the end of the query by default
@@ -608,6 +625,11 @@ pub async fn history(
results = app.query_results(db).await?;
}
};
+
+ if settings.inline_height > 0 {
+ terminal.clear()?;
+ }
+
if index < results.len() {
// index is in bounds so we return that entry
Ok(results.swap_remove(index).command.clone())