Folderize hinter

This commit is contained in:
sholderbach 2022-03-14 15:56:55 +01:00 committed by Stefan Holderbach
parent 804f31d181
commit 56ea39ec32
2 changed files with 30 additions and 27 deletions

View File

@ -1,31 +1,9 @@
use {
crate::History,
nu_ansi_term::{Color, Style},
};
use crate::{Hinter, History};
use nu_ansi_term::{Color, Style};
/// A trait that's responsible for returning the hint for the current line and position
/// Hints are often shown in-line as part of the buffer, showing the user text they can accept or ignore
pub trait Hinter: Send {
/// Handle the hinting duty by using the line, position, and current history
///
/// Returns the formatted output to show the user
fn handle(
&mut self,
line: &str,
pos: usize,
history: &dyn History,
use_ansi_coloring: bool,
) -> String;
/// Return the current hint unformatted to perform the completion of the full hint
fn complete_hint(&self) -> String;
/// Return the first semantic token of the hint
/// for incremental completion
fn next_hint_token(&self) -> String;
}
/// A default example hinter that use the completions or the history to show a hint to the user
/// A hinter that use the completions or the history to show a hint to the user
///
/// Similar to `fish` autosuggestins
pub struct DefaultHinter {
style: Style,
current_hint: String,

25
src/hinter/mod.rs Normal file
View File

@ -0,0 +1,25 @@
mod default;
pub use default::DefaultHinter;
use crate::History;
/// A trait that's responsible for returning the hint for the current line and position
/// Hints are often shown in-line as part of the buffer, showing the user text they can accept or ignore
pub trait Hinter: Send {
/// Handle the hinting duty by using the line, position, and current history
///
/// Returns the formatted output to show the user
fn handle(
&mut self,
line: &str,
pos: usize,
history: &dyn History,
use_ansi_coloring: bool,
) -> String;
/// Return the current hint unformatted to perform the completion of the full hint
fn complete_hint(&self) -> String;
/// Return the first semantic token of the hint
/// for incremental completion
fn next_hint_token(&self) -> String;
}