mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 03:55:23 +00:00
moving things around and documentation
This commit is contained in:
parent
635ea8a774
commit
65cad8dda8
@ -16,8 +16,11 @@ pub struct MatchedItem<I>
|
||||
where
|
||||
I: Sync + Send + Clone + 'static,
|
||||
{
|
||||
/// The matched item.
|
||||
pub inner: I,
|
||||
/// The dimension against which the item was matched (as a string).
|
||||
pub matched_string: String,
|
||||
/// The indices of the matched characters.
|
||||
pub match_indices: Vec<(u32, u32)>,
|
||||
}
|
||||
|
||||
@ -29,6 +32,7 @@ where
|
||||
/// front-end and display a loading indicator.
|
||||
#[derive(Default)]
|
||||
pub struct Status {
|
||||
/// Whether the matcher is currently running.
|
||||
pub running: bool,
|
||||
}
|
||||
|
||||
@ -52,9 +56,13 @@ impl From<nucleo::Status> for Status {
|
||||
/// cores on the current machine).
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Config {
|
||||
/// The number of threads to use for the fuzzy matcher.
|
||||
pub n_threads: Option<usize>,
|
||||
/// Whether to ignore case when matching.
|
||||
pub ignore_case: bool,
|
||||
/// Whether to prefer prefix matches.
|
||||
pub prefer_prefix: bool,
|
||||
/// Whether to optimize for matching paths.
|
||||
pub match_paths: bool,
|
||||
}
|
||||
|
||||
@ -118,6 +126,7 @@ pub struct Injector<I>
|
||||
where
|
||||
I: Sync + Send + Clone + 'static,
|
||||
{
|
||||
/// The inner `Injector` from the `Nucleo` fuzzy matcher.
|
||||
inner: nucleo::Injector<I>,
|
||||
}
|
||||
|
||||
@ -166,10 +175,15 @@ pub struct Matcher<I>
|
||||
where
|
||||
I: Sync + Send + Clone + 'static,
|
||||
{
|
||||
/// The inner `Nucleo` fuzzy matcher.
|
||||
inner: nucleo::Nucleo<I>,
|
||||
/// The current total number of items in the matcher.
|
||||
pub total_item_count: u32,
|
||||
/// The current number of matched items in the matcher.
|
||||
pub matched_item_count: u32,
|
||||
/// The current status of the matcher.
|
||||
pub status: Status,
|
||||
/// The last pattern that was matched against.
|
||||
pub last_pattern: String,
|
||||
}
|
||||
|
||||
|
@ -8,24 +8,25 @@ use tracing::{debug, info};
|
||||
use crate::app::App;
|
||||
use crate::channels::stdin::Channel as StdinChannel;
|
||||
use crate::cli::Cli;
|
||||
use crate::utils::is_readable_stdin;
|
||||
|
||||
mod action;
|
||||
mod app;
|
||||
mod channels;
|
||||
mod cli;
|
||||
mod config;
|
||||
mod entry;
|
||||
mod errors;
|
||||
mod event;
|
||||
mod fuzzy;
|
||||
mod logging;
|
||||
mod picker;
|
||||
mod previewers;
|
||||
mod render;
|
||||
mod television;
|
||||
mod tui;
|
||||
mod ui;
|
||||
mod utils;
|
||||
pub mod action;
|
||||
pub mod app;
|
||||
pub mod channels;
|
||||
pub mod cli;
|
||||
pub mod config;
|
||||
pub mod entry;
|
||||
pub mod errors;
|
||||
pub mod event;
|
||||
pub mod fuzzy;
|
||||
pub mod logging;
|
||||
pub mod picker;
|
||||
pub mod previewers;
|
||||
pub mod render;
|
||||
pub mod television;
|
||||
pub mod tui;
|
||||
pub mod ui;
|
||||
pub mod utils;
|
||||
|
||||
#[tokio::main(flavor = "multi_thread")]
|
||||
async fn main() -> Result<()> {
|
||||
@ -56,62 +57,3 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_readable_stdin() -> bool {
|
||||
use std::io::IsTerminal;
|
||||
|
||||
#[cfg(unix)]
|
||||
fn imp() -> bool {
|
||||
use std::{
|
||||
fs::File,
|
||||
os::{fd::AsFd, unix::fs::FileTypeExt},
|
||||
};
|
||||
|
||||
let stdin = std::io::stdin();
|
||||
let Ok(fd) = stdin.as_fd().try_clone_to_owned() else {
|
||||
return false;
|
||||
};
|
||||
let file = File::from(fd);
|
||||
let Ok(md) = file.metadata() else {
|
||||
return false;
|
||||
};
|
||||
let ft = md.file_type();
|
||||
let is_file = ft.is_file();
|
||||
let is_fifo = ft.is_fifo();
|
||||
let is_socket = ft.is_socket();
|
||||
is_file || is_fifo || is_socket
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn imp() -> bool {
|
||||
let stdin = winapi_util::HandleRef::stdin();
|
||||
let typ = match winapi_util::file::typ(stdin) {
|
||||
Ok(typ) => typ,
|
||||
Err(err) => {
|
||||
log::debug!(
|
||||
"for heuristic stdin detection on Windows, \
|
||||
could not get file type of stdin \
|
||||
(thus assuming stdin is not readable): {err}",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
let is_disk = typ.is_disk();
|
||||
let is_pipe = typ.is_pipe();
|
||||
let is_readable = is_disk || is_pipe;
|
||||
log::debug!(
|
||||
"for heuristic stdin detection on Windows, \
|
||||
found that is_disk={is_disk} and is_pipe={is_pipe}, \
|
||||
and thus concluded that is_stdin_readable={is_readable}",
|
||||
);
|
||||
is_readable
|
||||
}
|
||||
|
||||
#[cfg(not(any(unix, windows)))]
|
||||
fn imp() -> bool {
|
||||
log::debug!("on non-{{Unix,Windows}}, assuming stdin is not readable");
|
||||
false
|
||||
}
|
||||
|
||||
!std::io::stdin().is_terminal() && imp()
|
||||
}
|
||||
|
@ -221,14 +221,6 @@ impl Television {
|
||||
|
||||
/// Build the corresponding spans for a group of keys.
|
||||
///
|
||||
/// # Arguments
|
||||
/// - `group_name`: The name of the group.
|
||||
/// - `key_groups`: A vector of vectors of strings representing the keys for each group.
|
||||
/// Each vector of strings represents a group of alternate keys for a given `Action`.
|
||||
///
|
||||
/// # Returns
|
||||
/// A vector of `Span`s representing the key groups.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use ratatui::text::Span;
|
||||
@ -259,7 +251,6 @@ fn build_cells_for_key_groups(
|
||||
))];
|
||||
|
||||
let mut spans = Vec::new();
|
||||
//spans.push(Span::styled("[", Style::default().fg(KEY_COLOR)));
|
||||
|
||||
let key_group_spans: Vec<Span> = non_empty_groups
|
||||
.map(|keys| {
|
||||
@ -274,7 +265,6 @@ fn build_cells_for_key_groups(
|
||||
}
|
||||
});
|
||||
|
||||
//spans.push(Span::styled("]", Style::default().fg(KEY_COLOR)));
|
||||
cells.push(Cell::from(Line::from(spans)));
|
||||
|
||||
cells
|
||||
@ -282,13 +272,6 @@ fn build_cells_for_key_groups(
|
||||
|
||||
/// Get the keys for a given action.
|
||||
///
|
||||
/// # Arguments
|
||||
/// - `keymap`: A hashmap of keybindings.
|
||||
/// - `action`: The action to get the keys for.
|
||||
///
|
||||
/// # Returns
|
||||
/// A vector of strings representing the keys for the given action.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// use std::collections::HashMap;
|
||||
|
@ -2,3 +2,65 @@ pub mod files;
|
||||
pub mod indices;
|
||||
pub mod strings;
|
||||
pub mod syntax;
|
||||
|
||||
/// Heuristic to determine if stdin is readable.
|
||||
///
|
||||
/// This is used to determine if we should use the stdin channel.
|
||||
pub fn is_readable_stdin() -> bool {
|
||||
use std::io::IsTerminal;
|
||||
|
||||
#[cfg(unix)]
|
||||
fn imp() -> bool {
|
||||
use std::{
|
||||
fs::File,
|
||||
os::{fd::AsFd, unix::fs::FileTypeExt},
|
||||
};
|
||||
|
||||
let stdin = std::io::stdin();
|
||||
let Ok(fd) = stdin.as_fd().try_clone_to_owned() else {
|
||||
return false;
|
||||
};
|
||||
let file = File::from(fd);
|
||||
let Ok(md) = file.metadata() else {
|
||||
return false;
|
||||
};
|
||||
let ft = md.file_type();
|
||||
let is_file = ft.is_file();
|
||||
let is_fifo = ft.is_fifo();
|
||||
let is_socket = ft.is_socket();
|
||||
is_file || is_fifo || is_socket
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn imp() -> bool {
|
||||
let stdin = winapi_util::HandleRef::stdin();
|
||||
let typ = match winapi_util::file::typ(stdin) {
|
||||
Ok(typ) => typ,
|
||||
Err(err) => {
|
||||
log::debug!(
|
||||
"for heuristic stdin detection on Windows, \
|
||||
could not get file type of stdin \
|
||||
(thus assuming stdin is not readable): {err}",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
let is_disk = typ.is_disk();
|
||||
let is_pipe = typ.is_pipe();
|
||||
let is_readable = is_disk || is_pipe;
|
||||
log::debug!(
|
||||
"for heuristic stdin detection on Windows, \
|
||||
found that is_disk={is_disk} and is_pipe={is_pipe}, \
|
||||
and thus concluded that is_stdin_readable={is_readable}",
|
||||
);
|
||||
is_readable
|
||||
}
|
||||
|
||||
#[cfg(not(any(unix, windows)))]
|
||||
fn imp() -> bool {
|
||||
log::debug!("on non-{{Unix,Windows}}, assuming stdin is not readable");
|
||||
false
|
||||
}
|
||||
|
||||
!std::io::stdin().is_terminal() && imp()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user