Skip to content

Commit

Permalink
Add REPL config attribute (tweag#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
deotimedev authored Aug 28, 2023
1 parent 77aac66 commit 9e6dc8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
15 changes: 14 additions & 1 deletion core/src/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use std::io::Write;
use std::result::Result;
use std::str::FromStr;

#[cfg(feature = "repl")]
use ansi_term::{Colour, Style};
#[cfg(feature = "repl")]
use rustyline::validate::{ValidationContext, ValidationResult};

Expand Down Expand Up @@ -342,7 +344,6 @@ pub enum InputStatus {
derive(
rustyline_derive::Completer,
rustyline_derive::Helper,
rustyline_derive::Highlighter,
rustyline_derive::Hinter
)
)]
Expand Down Expand Up @@ -387,6 +388,18 @@ impl InputParser {
}
}

#[cfg(feature = "repl")]
impl rustyline::highlight::Highlighter for InputParser {
fn highlight_prompt<'b, 's: 'b, 'p: 'b>(
&'s self,
prompt: &'p str,
_default: bool,
) -> std::borrow::Cow<'b, str> {
let style = Style::new().fg(Colour::Green);
std::borrow::Cow::Owned(style.paint(prompt).to_string())
}
}

#[cfg(feature = "repl")]
impl rustyline::validate::Validator for InputParser {
fn validate(&self, ctx: &mut ValidationContext<'_>) -> rustyline::Result<ValidationResult> {
Expand Down
14 changes: 2 additions & 12 deletions core/src/repl/rustyline_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::*;

use crate::eval::cache::CacheImpl;
use crate::program::{self, ColorOpt};
use ansi_term::{Colour, Style};
use ansi_term::Style;
use rustyline::error::ReadlineError;
use rustyline::{Config, EditMode, Editor};

Expand Down Expand Up @@ -53,18 +53,8 @@ pub fn repl(histfile: PathBuf, color_opt: ColorOpt) -> Result<(), InitError> {
let _ = editor.load_history(&histfile);
editor.set_helper(Some(validator));

let prompt = {
let style = Style::new();
let style = if color_opt.0 != clap::ColorChoice::Never {
style.fg(Colour::Green)
} else {
style
};
style.paint("nickel> ").to_string()
};

let result = loop {
let line = editor.readline(&prompt);
let line = editor.readline("nickel> ");
let mut stdout = std::io::stdout();

match line {
Expand Down

0 comments on commit 9e6dc8c

Please sign in to comment.