add requoting for completions (#2129)

This commit is contained in:
Aleš Katona 2020-07-07 15:13:39 -06:00 committed by GitHub
parent 32f18536e1
commit 28be39494c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -705,7 +705,7 @@ impl Shell for FilesystemShell {
pos pos
}; };
self.completer.complete(&expanded, pos, ctx) requote(self.completer.complete(&expanded, pos, ctx))
} }
fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option<String> { fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option<String> {
@ -797,3 +797,30 @@ fn is_hidden_dir(dir: impl AsRef<Path>) -> bool {
} }
} }
} }
fn requote(
completions: Result<(usize, Vec<rustyline::completion::Pair>), rustyline::error::ReadlineError>,
) -> Result<(usize, Vec<rustyline::completion::Pair>), rustyline::error::ReadlineError> {
match completions {
Ok(items) => {
let mut new_items = Vec::with_capacity(items.0);
for item in items.1 {
let unescaped = rustyline::completion::unescape(&item.replacement, Some('\\'));
let maybe_quote = if unescaped != item.replacement {
"\""
} else {
""
};
new_items.push(rustyline::completion::Pair {
display: item.display,
replacement: format!("{}{}{}", maybe_quote, unescaped, maybe_quote),
});
}
Ok((items.0, new_items))
}
Err(err) => Err(err),
}
}