1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-06 08:07:37 +03:00

Add REPL config attribute (#1546)

This commit is contained in:
deotime 2023-08-28 02:57:39 -05:00 committed by GitHub
parent 77aac6666b
commit 9e6dc8c27d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 13 deletions

View File

@ -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};
@ -342,7 +344,6 @@ pub enum InputStatus {
derive(
rustyline_derive::Completer,
rustyline_derive::Helper,
rustyline_derive::Highlighter,
rustyline_derive::Hinter
)
)]
@ -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> {

View File

@ -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};
@ -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 {