Skip to content

Commit

Permalink
refactor(cli/tools/repl): merge highlighter into helper (denoland#9448)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Feb 8, 2021
1 parent 1f9e900 commit 36e9e53
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions cli/tools/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 36e9e53

Please sign in to comment.