Stuff stored in maps can be eval'd on access by storing with the -F flag
This commit is contained in:
@@ -228,7 +228,7 @@ pub enum CompSpecResult {
|
||||
NoSpec, // No compspec registered
|
||||
NoMatch { flags: CompOptFlags }, /* Compspec found but no candidates matched, returns
|
||||
* behavior flags */
|
||||
Match(CompResult), // Compspec found and candidates returned
|
||||
Match { result: CompResult, flags: CompOptFlags }, // Compspec found and candidates returned
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
@@ -433,6 +433,7 @@ impl CompSpec for BashCompSpec {
|
||||
if self.function.is_some() {
|
||||
candidates.extend(self.exec_comp_func(ctx)?);
|
||||
}
|
||||
candidates.sort_by_key(|c| c.len()); // sort by length to prioritize shorter completions, ties are then sorted alphabetically
|
||||
|
||||
Ok(candidates)
|
||||
}
|
||||
@@ -511,7 +512,7 @@ pub struct Completer {
|
||||
pub token_span: (usize, usize),
|
||||
pub active: bool,
|
||||
pub dirs_only: bool,
|
||||
pub no_space: bool,
|
||||
pub add_space: bool,
|
||||
}
|
||||
|
||||
impl Completer {
|
||||
@@ -612,7 +613,7 @@ impl Completer {
|
||||
}
|
||||
|
||||
pub fn add_spaces(&mut self) {
|
||||
if !self.no_space {
|
||||
if self.add_space {
|
||||
self.candidates = std::mem::take(&mut self.candidates)
|
||||
.into_iter()
|
||||
.map(|c| {
|
||||
@@ -744,9 +745,10 @@ impl Completer {
|
||||
flags: spec.get_flags(),
|
||||
})
|
||||
} else {
|
||||
Ok(CompSpecResult::Match(CompResult::from_candidates(
|
||||
candidates,
|
||||
)))
|
||||
Ok(CompSpecResult::Match {
|
||||
result: CompResult::from_candidates(candidates),
|
||||
flags: spec.get_flags(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,12 +778,15 @@ impl Completer {
|
||||
return Ok(CompResult::NoMatch);
|
||||
}
|
||||
|
||||
if flags.contains(CompOptFlags::NOSPACE) {
|
||||
self.no_space = true;
|
||||
if flags.contains(CompOptFlags::SPACE) {
|
||||
self.add_space = true;
|
||||
}
|
||||
}
|
||||
CompSpecResult::Match(comp_result) => {
|
||||
return Ok(comp_result);
|
||||
CompSpecResult::Match { result, flags } => {
|
||||
if flags.contains(CompOptFlags::SPACE) {
|
||||
self.add_space = true;
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
CompSpecResult::NoSpec => { /* carry on */ }
|
||||
}
|
||||
|
||||
@@ -780,27 +780,16 @@ impl AsFd for TermReader {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Layout {
|
||||
pub w_calc: Box<dyn WidthCalculator>,
|
||||
pub prompt_end: Pos,
|
||||
pub cursor: Pos,
|
||||
pub end: Pos,
|
||||
}
|
||||
|
||||
impl Debug for Layout {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, "Layout: ")?;
|
||||
writeln!(f, "\tPrompt End: {:?}", self.prompt_end)?;
|
||||
writeln!(f, "\tCursor: {:?}", self.cursor)?;
|
||||
writeln!(f, "\tEnd: {:?}", self.end)
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout {
|
||||
pub fn new() -> Self {
|
||||
let w_calc = width_calculator();
|
||||
Self {
|
||||
w_calc,
|
||||
prompt_end: Pos::default(),
|
||||
cursor: Pos::default(),
|
||||
end: Pos::default(),
|
||||
@@ -811,7 +800,6 @@ impl Layout {
|
||||
let cursor = Self::calc_pos(term_width, to_cursor, prompt_end, prompt_end.col);
|
||||
let end = Self::calc_pos(term_width, to_end, prompt_end, prompt_end.col);
|
||||
Layout {
|
||||
w_calc: width_calculator(),
|
||||
prompt_end,
|
||||
cursor,
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user