mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
further improved tips UX, fixed cli.rs assert
This commit is contained in:
parent
d6b59e7091
commit
a46d4fa1c6
2 changed files with 29 additions and 7 deletions
|
@ -44,8 +44,29 @@ pub const WELCOME_MESSAGE: &str = concatcp!(
|
||||||
END_COL,
|
END_COL,
|
||||||
"\n\n"
|
"\n\n"
|
||||||
);
|
);
|
||||||
pub const INSTRUCTIONS: &str = "Enter an expression, or :help, or :q to quit.\n";
|
|
||||||
pub const TIPS: &str = "Everything in the repl needs to be an expression, it needs to return something. See example below: \n\n\n foo = 1 \n\n foo";
|
// For when nothing is entered in the repl
|
||||||
|
// TODO add link to repl tutorial(does not yet exist).
|
||||||
|
pub const SHORT_INSTRUCTIONS: &str = "Enter an expression, or :help, or :q to quit.\n\n";
|
||||||
|
|
||||||
|
// TODO add link to repl tutorial(does not yet exist).
|
||||||
|
pub const TIPS: &str = concatcp!(
|
||||||
|
BLUE,
|
||||||
|
" - ",
|
||||||
|
END_COL,
|
||||||
|
"Entered code needs to return something. For example:\n\n",
|
||||||
|
PINK,
|
||||||
|
" » foo = 1\n … foo\n\n",
|
||||||
|
END_COL,
|
||||||
|
BLUE,
|
||||||
|
" - ",
|
||||||
|
END_COL,
|
||||||
|
":q to quit\n\n",
|
||||||
|
BLUE,
|
||||||
|
" - ",
|
||||||
|
END_COL,
|
||||||
|
":help\n"
|
||||||
|
);
|
||||||
pub const PROMPT: &str = concatcp!("\n", BLUE, "»", END_COL, " ");
|
pub const PROMPT: &str = concatcp!("\n", BLUE, "»", END_COL, " ");
|
||||||
pub const CONT_PROMPT: &str = concatcp!(BLUE, "…", END_COL, " ");
|
pub const CONT_PROMPT: &str = concatcp!(BLUE, "…", END_COL, " ");
|
||||||
|
|
||||||
|
@ -393,7 +414,7 @@ pub fn main() -> io::Result<()> {
|
||||||
// To debug rustyline:
|
// To debug rustyline:
|
||||||
// <UNCOMMENT> env_logger::init();
|
// <UNCOMMENT> env_logger::init();
|
||||||
// <RUN WITH:> RUST_LOG=rustyline=debug cargo run repl 2> debug.log
|
// <RUN WITH:> RUST_LOG=rustyline=debug cargo run repl 2> debug.log
|
||||||
print!("{}{}{}", WELCOME_MESSAGE, INSTRUCTIONS, TIPS);
|
print!("{}{}", WELCOME_MESSAGE, TIPS);
|
||||||
|
|
||||||
let mut prev_line_blank = false;
|
let mut prev_line_blank = false;
|
||||||
let mut editor = Editor::<ReplHelper>::new();
|
let mut editor = Editor::<ReplHelper>::new();
|
||||||
|
@ -416,7 +437,7 @@ pub fn main() -> io::Result<()> {
|
||||||
match trim_line.to_lowercase().as_str() {
|
match trim_line.to_lowercase().as_str() {
|
||||||
"" => {
|
"" => {
|
||||||
if pending_src.is_empty() {
|
if pending_src.is_empty() {
|
||||||
print!("\n{}", INSTRUCTIONS);
|
print!("\n{}", SHORT_INSTRUCTIONS);
|
||||||
} else if prev_line_blank {
|
} else if prev_line_blank {
|
||||||
// After two blank lines in a row, give up and try parsing it
|
// After two blank lines in a row, give up and try parsing it
|
||||||
// even though it's going to fail. This way you don't get stuck.
|
// even though it's going to fail. This way you don't get stuck.
|
||||||
|
@ -438,7 +459,8 @@ pub fn main() -> io::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
":help" => {
|
":help" => {
|
||||||
println!("Use :exit or :quit or :q to exit.");
|
// TODO add link to repl tutorial(does not yet exist).
|
||||||
|
println!("Use :q to exit.");
|
||||||
}
|
}
|
||||||
":exit" | ":quit" | ":q" => {
|
":exit" | ":quit" | ":q" => {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Command, ExitStatus, Stdio};
|
use std::process::{Command, ExitStatus, Stdio};
|
||||||
|
|
||||||
use roc_repl_cli::{INSTRUCTIONS, WELCOME_MESSAGE};
|
use roc_repl_cli::{TIPS, WELCOME_MESSAGE};
|
||||||
use roc_test_utils::assert_multiline_str_eq;
|
use roc_test_utils::assert_multiline_str_eq;
|
||||||
|
|
||||||
const ERROR_MESSAGE_START: char = '─';
|
const ERROR_MESSAGE_START: char = '─';
|
||||||
|
@ -75,7 +75,7 @@ fn repl_eval(input: &str) -> Out {
|
||||||
|
|
||||||
// Remove the initial instructions from the output.
|
// Remove the initial instructions from the output.
|
||||||
|
|
||||||
let expected_instructions = format!("{}{}", WELCOME_MESSAGE, INSTRUCTIONS);
|
let expected_instructions = format!("{}{}", WELCOME_MESSAGE, TIPS);
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue