From de74b619b86b81feb165c5518995d36ca9a0bada Mon Sep 17 00:00:00 2001 From: alexpasmantier Date: Fri, 8 Nov 2024 14:02:26 +0100 Subject: [PATCH] fix: stabilize preview scroll initialization --- README.md | 50 +++++++++++++++++++++++++++------ crates/television/television.rs | 6 ++-- crates/television/ui/preview.rs | 3 +- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b319c94..df07c14 100644 --- a/README.md +++ b/README.md @@ -19,20 +19,28 @@ ``` - The revolution will be televised. + The revolution will (not) be televised. ## 📺 About -`Television` is a blazingly fast general purpose fuzzy finder TUI written in Rust. It is inspired by the neovim `Telescope` plugin and the `fzf` command line tool. It is designed to be fast, efficient, easy to use and easily extensible. It is built on top of `tokio`, `ratatui` and the `nucleo` matcher which is used in the `helix` editor. +`Television` is an extremely fast general purpose fuzzy finder TUI written in Rust. -## 📺 Design -`Television`'s design is based on the concept of `Channels`. A `Channel` is a source of data that can be used for fuzzy -finding. A `Channel` can be anything from a file system directory, a git repository, a list of strings, a list of -numbers, etc. `Television` provides a set of built-in `Channels` that can be used out of the box. However, `Television` -is designed to be easily extensible and allows users to define their own custom `Channels` by implementing a simple -trait. +It is inspired by the neovim [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) plugin and the [fzf](https://github.com/junegunn/fzf) command line tool. It is designed to be fast, efficient, easy to use and easily extensible. It is built on top of [tokio](https://github.com/tokio-rs/tokio), [ratatui](https://github.com/ratatui/ratatui) and the *nucleo* matcher used in the [helix](https://github.com/helix-editor/helix) editor. -## Built-in Channels + +## 📺 Installation +```bash +cargo install television +``` + +## 📺 Usage +```bash +tv [channel] #[default: files] [possible values: env, files, git-repos, text, alias] +``` +By default, `television` will search through files in the current directory. + +## 📺 Built-in Channels +The following channels are currently available: - `Files`: search through files in a directory tree. - `Text`: search through textual content in a directory tree. - `GitRepos`: search through git repositories anywhere on the file system. @@ -40,3 +48,27 @@ trait. - `Alias`: search through shell aliases and their values. - `Stdin`: search through lines of text from stdin. + +## 📺 Design +#### Channels +**Television**'s design is primarily based on the concept of **Channels**. + +A **Channel** is a source of data that can be used for fuzzy finding. It can be anything from a file system directory, a git repository, a list of strings, a list of numbers, etc. + +**Television** provides a set of built-in **Channels** that can be used out of the box (see [Built-in Channels](#📺-built-in-channels)). The list of available channels +will grow over time as new channels are implemented to satisfy different use cases. + +Because a **Channel** is nothing more than a source of data that can respond to a user query, channels can virtually search through anything ranging from a local file system to a remote database, a list of environment variables, something passed through stdin, etc. + +#### Transitions +When it makes sense, **Television** allows for transitions between different channels. For example, you might want to +start searching through git repositories, then refine your search to a specific set of files in that shortlist of +repositories and then finally search through the textual content of those files. + +This can easily be achieved using transitions. + +#### Previewers +Entries returned by different channels can be previewed in a separate pane. This is useful when you want to see the +contents of a file, the value of an environment variable, etc. Because entries returned by different channels may +represent different types of data, **Television** allows for channels to declare the type of previewer that should be +used. Television comes with a set of built-in previewers that can be used out of the box and will grow over time. diff --git a/crates/television/television.rs b/crates/television/television.rs index 04ac3d7..10eb814 100644 --- a/crates/television/television.rs +++ b/crates/television/television.rs @@ -264,20 +264,20 @@ impl Television { if new_pattern != self.current_pattern { self.current_pattern.clone_from(&new_pattern); self.find(&new_pattern); - self.reset_preview_scroll(); self.reset_picker_selection(); + self.reset_preview_scroll(); } } _ => {} } } Action::SelectNextEntry => { - self.select_next_entry(); self.reset_preview_scroll(); + self.select_next_entry(); } Action::SelectPrevEntry => { - self.select_prev_entry(); self.reset_preview_scroll(); + self.select_prev_entry(); } Action::ScrollPreviewDown => self.scroll_preview_down(1), Action::ScrollPreviewUp => self.scroll_preview_up(1), diff --git a/crates/television/ui/preview.rs b/crates/television/ui/preview.rs index a23f1d6..75906bb 100644 --- a/crates/television/ui/preview.rs +++ b/crates/television/ui/preview.rs @@ -1,3 +1,4 @@ +use crate::channels::OnAir; use crate::entry::Entry; use crate::previewers::{ Preview, PreviewContent, FILE_TOO_LARGE_MSG, PREVIEW_NOT_SUPPORTED_MSG, @@ -216,7 +217,7 @@ impl Television { target_line: Option, height: u16, ) { - if self.preview_scroll.is_none() { + if self.preview_scroll.is_none() && !self.channel.running() { self.preview_scroll = Some(target_line.unwrap_or(0).saturating_sub(height / 3)); }