improved hinting
This commit is contained in:
@@ -98,7 +98,6 @@ impl FernHighlighter {
|
|||||||
.rev()
|
.rev()
|
||||||
.collect::<Vec<Tk>>();
|
.collect::<Vec<Tk>>();
|
||||||
for token in tokens {
|
for token in tokens {
|
||||||
flog!(DEBUG, token.flags);
|
|
||||||
match token.class {
|
match token.class {
|
||||||
_ if token.flags.intersects(TkFlags::IS_CMDSUB | TkFlags::IS_SUBSH) => {
|
_ if token.flags.intersects(TkFlags::IS_CMDSUB | TkFlags::IS_SUBSH) => {
|
||||||
let styled = self.highlight_subsh(token.clone());
|
let styled = self.highlight_subsh(token.clone());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use rustyline::{completion::Completer, hint::{Hint, Hinter}, validate::{ValidationResult, Validator}, Helper};
|
use rustyline::{completion::Completer, hint::{Hint, Hinter}, history::SearchDirection, validate::{ValidationResult, Validator}, Helper};
|
||||||
|
|
||||||
use crate::{libsh::term::{Style, Styled}, parse::{lex::{LexFlags, LexStream}, ParseStream}};
|
use crate::{libsh::term::{Style, Styled}, parse::{lex::{LexFlags, LexStream}, ParseStream}};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
@@ -10,7 +10,17 @@ pub struct FernReadline;
|
|||||||
|
|
||||||
impl FernReadline {
|
impl FernReadline {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self
|
||||||
|
}
|
||||||
|
pub fn search_hist(value: &str, ctx: &rustyline::Context<'_>) -> Option<String> {
|
||||||
|
let len = ctx.history().len();
|
||||||
|
for i in 0..len {
|
||||||
|
let entry = ctx.history().get(i, SearchDirection::Reverse).unwrap().unwrap();
|
||||||
|
if entry.entry.starts_with(value) {
|
||||||
|
return Some(entry.entry.into_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,12 +58,11 @@ impl Hint for FernHint {
|
|||||||
impl Hinter for FernReadline {
|
impl Hinter for FernReadline {
|
||||||
type Hint = FernHint;
|
type Hint = FernHint;
|
||||||
fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option<Self::Hint> {
|
fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option<Self::Hint> {
|
||||||
let ent = ctx.history().search(
|
if line.is_empty() {
|
||||||
line,
|
return None
|
||||||
ctx.history().len().saturating_sub(1),
|
}
|
||||||
rustyline::history::SearchDirection::Reverse
|
let ent = Self::search_hist(line,ctx)?;
|
||||||
).ok()??;
|
let entry_raw = ent.get(pos..)?.to_string();
|
||||||
let entry_raw = ent.entry.get(pos..)?.to_string();
|
|
||||||
Some(FernHint::new(entry_raw))
|
Some(FernHint::new(entry_raw))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user