1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

refactor(cli/tools/repl): merge highlighter into helper (#9448)

This commit is contained in:
Casper Beyer 2021-02-09 00:25:10 +08:00 committed by GitHub
parent 1f9e9002d5
commit 36e9e53b37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,7 +37,6 @@ struct Helper {
context_id: u64,
message_tx: SyncSender<(String, Option<Value>)>,
response_rx: Receiver<Result<Value, AnyError>>,
highlighter: LineHighlighter,
}
impl Helper {
@ -183,32 +182,18 @@ impl Highlighter for Helper {
hint.into()
}
fn highlight<'l>(&self, line: &'l str, pos: usize) -> Cow<'l, str> {
self.highlighter.highlight(line, pos)
}
fn highlight_candidate<'c>(
&self,
candidate: &'c str,
_completion: rustyline::CompletionType,
) -> Cow<'c, str> {
self.highlighter.highlight(candidate, 0)
self.highlight(candidate, 0)
}
fn highlight_char(&self, line: &str, _: usize) -> bool {
!line.is_empty()
}
}
struct LineHighlighter;
impl LineHighlighter {
fn new() -> Self {
Self
}
}
impl Highlighter for LineHighlighter {
fn highlight<'l>(&self, line: &'l str, _: usize) -> Cow<'l, str> {
let mut out_line = String::from(line);
@ -436,7 +421,6 @@ pub async fn run(
context_id,
message_tx,
response_rx,
highlighter: LineHighlighter::new(),
};
let editor = Arc::new(Mutex::new(Editor::new()));