diff --git a/Cargo.lock b/Cargo.lock index 805257dd15..b8993de844 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,7 +129,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -509,7 +509,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342" dependencies = [ "lazy-bytes-cast", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -520,7 +520,7 @@ checksum = "2f3e1238132dc01f081e1cbb9dace14e5ef4c3a51ee244bd982275fb514605db" dependencies = [ "error-code", "str-buf", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -572,7 +572,7 @@ checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" dependencies = [ "atty", "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -606,7 +606,7 @@ dependencies = [ "libc", "once_cell", "terminal_size", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -801,7 +801,7 @@ dependencies = [ "stdweb 0.1.3", "thiserror", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1040,7 +1040,7 @@ checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c" dependencies = [ "bitflags", "libloading", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1145,7 +1145,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1156,7 +1156,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1313,7 +1313,7 @@ checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" dependencies = [ "errno-dragonfly", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1913,16 +1913,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "khronos-egl" version = "4.1.0" @@ -1981,7 +1971,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" dependencies = [ "cfg-if 1.0.0", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2403,7 +2393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" dependencies = [ "overload", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2466,12 +2456,6 @@ dependencies = [ "libc", ] -[[package]] -name = "numtoa" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" - [[package]] name = "objc" version = "0.2.7" @@ -2601,7 +2585,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2648,7 +2632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2707,7 +2691,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3146,15 +3130,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_termios" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" -dependencies = [ - "redox_syscall", -] - [[package]] name = "redox_users" version = "0.4.3" @@ -3212,7 +3187,7 @@ dependencies = [ "bitflags", "libc", "mach", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3221,7 +3196,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3234,7 +3209,7 @@ dependencies = [ "log", "num_cpus", "rayon", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3338,7 +3313,7 @@ dependencies = [ "roc_unify", "snafu", "ven_graph", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3944,7 +3919,6 @@ dependencies = [ "rustyline", "rustyline-derive", "target-lexicon", - "termsize", "unicode-segmentation", ] @@ -4260,7 +4234,7 @@ dependencies = [ "unicode-segmentation", "unicode-width", "utf8parse", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -4557,7 +4531,7 @@ checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25" dependencies = [ "libc", "mach", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -4805,7 +4779,7 @@ dependencies = [ "libc", "redox_syscall", "remove_dir_all 0.5.3", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -4824,32 +4798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" dependencies = [ "libc", - "winapi 0.3.9", -] - -[[package]] -name = "termion" -version = "1.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" -dependencies = [ - "libc", - "numtoa", - "redox_syscall", - "redox_termios", -] - -[[package]] -name = "termsize" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e86d824a8e90f342ad3ef4bd51ef7119a9b681b0cc9f8ee7b2852f02ccd2517" -dependencies = [ - "atty", - "kernel32-sys", - "libc", - "termion", - "winapi 0.2.8", + "winapi", ] [[package]] @@ -5009,7 +4958,7 @@ dependencies = [ "stdweb 0.4.20", "time-macros 0.1.1", "version_check", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5300,7 +5249,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -5433,7 +5382,7 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wat", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5584,7 +5533,7 @@ dependencies = [ "wasmer-engine-universal-artifact", "wasmer-types", "wasmer-vm", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5667,7 +5616,7 @@ dependencies = [ "thiserror", "wasmer-artifact", "wasmer-types", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5686,7 +5635,7 @@ dependencies = [ "wasmer", "wasmer-vfs", "wasmer-wasi-types", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5889,7 +5838,7 @@ dependencies = [ "wasm-bindgen", "web-sys", "wgpu-types", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -5924,12 +5873,6 @@ dependencies = [ "libc", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -5940,12 +5883,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -5958,7 +5895,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -6082,7 +6019,7 @@ dependencies = [ "wayland-client", "wayland-protocols", "web-sys", - "winapi 0.3.9", + "winapi", "x11-dl", ] diff --git a/crates/repl_cli/Cargo.toml b/crates/repl_cli/Cargo.toml index 632a4411a2..d9847b691b 100644 --- a/crates/repl_cli/Cargo.toml +++ b/crates/repl_cli/Cargo.toml @@ -23,7 +23,6 @@ rustyline = {git = "https://github.com/roc-lang/rustyline", rev = "e74333c"} rustyline-derive = {git = "https://github.com/roc-lang/rustyline", rev = "e74333c"} target-lexicon = "0.12.2" unicode-segmentation = "1.10.0" -termsize = "0.1.6" roc_build = {path = "../compiler/build"} roc_builtins = {path = "../compiler/builtins"} diff --git a/crates/repl_cli/src/lib.rs b/crates/repl_cli/src/lib.rs index 99dc2bce2a..418c23b618 100644 --- a/crates/repl_cli/src/lib.rs +++ b/crates/repl_cli/src/lib.rs @@ -22,7 +22,7 @@ pub const WELCOME_MESSAGE: &str = concatcp!( // 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"; +pub const SHORT_INSTRUCTIONS: &str = "Enter an expression, or :help, or :q to quit.\n\n"; pub fn main() -> i32 { use rustyline::error::ReadlineError; @@ -42,9 +42,10 @@ pub fn main() -> i32 { Ok(line) => { editor.add_history_entry(line.trim()); + let dimensions = editor.dimensions(); let repl_helper = editor.helper_mut().expect("Editor helper was not set"); - match repl_helper.step(&line) { + match repl_helper.step(&line, dimensions) { Ok(output) => { // If there was no output, don't print a blank line! // (This happens for something like a type annotation.) diff --git a/crates/repl_cli/src/repl_state.rs b/crates/repl_cli/src/repl_state.rs index 0d76460728..1ae85b5b7d 100644 --- a/crates/repl_cli/src/repl_state.rs +++ b/crates/repl_cli/src/repl_state.rs @@ -17,9 +17,8 @@ use rustyline::validate::{self, ValidationContext, ValidationResult, Validator}; use rustyline_derive::{Completer, Helper, Hinter}; use std::borrow::Cow; use target_lexicon::Triple; -use termsize::Size; -pub const PROMPT: &str = concatcp!("\n", BLUE, "»", END_COL, " "); +pub const PROMPT: &str = concatcp!(BLUE, "»", END_COL, " "); pub const CONT_PROMPT: &str = concatcp!(BLUE, "…", END_COL, " "); /// The prefix we use for the automatic variable names we assign to each expr, @@ -92,7 +91,7 @@ impl ReplState { } } - pub fn step(&mut self, line: &str) -> Result { + pub fn step(&mut self, line: &str, dimensions: Option<(usize, usize)>) -> Result { let arena = Bump::new(); match parse_src(&arena, line) { @@ -103,7 +102,7 @@ impl ReplState { // 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 // in a perpetual Incomplete state due to a syntax error. - Ok(self.eval_and_format(line)) + Ok(self.eval_and_format(line, dimensions)) } else { // The previous line wasn't blank, but the line isn't empty either. // This could mean that, for example, you're writing a multiline `when` @@ -119,7 +118,7 @@ impl ReplState { | ParseOutcome::ValueDef(_) | ParseOutcome::TypeDef(_) | ParseOutcome::SyntaxErr - | ParseOutcome::Incomplete => Ok(self.eval_and_format(line)), + | ParseOutcome::Incomplete => Ok(self.eval_and_format(line, dimensions)), ParseOutcome::Help => { // TODO add link to repl tutorial(does not yet exist). Ok(TIPS.to_string()) @@ -128,7 +127,7 @@ impl ReplState { } } - pub fn eval_and_format(&mut self, src: &str) -> String { + pub fn eval_and_format(&mut self, src: &str, dimensions: Option<(usize, usize)>) -> String { let arena = Bump::new(); let pending_past_def; let mut opt_var_name; @@ -281,7 +280,7 @@ impl ReplState { self.add_past_def(ident, src); } - format_output(output, problems, opt_var_name) + format_output(output, problems, opt_var_name, dimensions) } fn next_auto_ident(&mut self) -> u64 { @@ -550,6 +549,7 @@ fn format_output( opt_output: Option, problems: Problems, opt_var_name: Option, + dimensions: Option<(usize, usize)>, ) -> String { let mut buf = String::new(); @@ -587,10 +587,10 @@ fn format_output( use unicode_segmentation::UnicodeSegmentation; const VAR_NAME_PREFIX: &str = " # "; // e.g. in " # val1" - const VAR_NAME_COLUMN_MAX: u16 = 80; // Right-align the var_name at this column + const VAR_NAME_COLUMN_MAX: usize = 32; // Right-align the var_name at this column - let var_name_column = match termsize::get() { - Some(Size { cols, rows: _ }) => cols.min(VAR_NAME_COLUMN_MAX) as usize, + let term_width = match dimensions { + Some((width, _)) => width.min(VAR_NAME_COLUMN_MAX), None => VAR_NAME_COLUMN_MAX as usize, }; @@ -605,11 +605,11 @@ fn format_output( .count(); let var_name_len = var_name.graphemes(true).count() + VAR_NAME_PREFIX.graphemes(true).count(); - let spaces_needed = if last_line_len + var_name_len > var_name_column { + let spaces_needed = if last_line_len + var_name_len > term_width { buf.push('\n'); - var_name_column - var_name_len + term_width - var_name_len } else { - var_name_column - last_line_len - var_name_len + term_width - last_line_len - var_name_len }; for _ in 0..spaces_needed { @@ -620,6 +620,7 @@ fn format_output( buf.push_str(VAR_NAME_PREFIX); buf.push_str(&var_name); buf.push_str(END_COL); + buf.push('\n'); } } } diff --git a/crates/repl_test/src/state.rs b/crates/repl_test/src/state.rs index 625230d9f3..348b7c7180 100644 --- a/crates/repl_test/src/state.rs +++ b/crates/repl_test/src/state.rs @@ -88,7 +88,7 @@ fn exhaustiveness_problem() { #[test] fn tips() { assert!(!is_incomplete("")); - assert_eq!(ReplState::new().step(""), Ok(TIPS.to_string())); + assert_eq!(ReplState::new().step("", None), Ok(TIPS.to_string())); } #[test] @@ -98,7 +98,7 @@ fn standalone_annotation() { incomplete(&mut input); assert!(!is_incomplete(&input)); - assert_eq!(state.step(&input), Ok(String::new())); + assert_eq!(state.step(&input, None), Ok(String::new())); } /// validate and step the given input, then check the Result vs the output @@ -106,7 +106,7 @@ fn standalone_annotation() { fn complete(input: &str, state: &mut ReplState, expected_step_result: Result<(&str, &str), i32>) { assert!(!is_incomplete(input)); - match state.step(input) { + match state.step(input, None) { Ok(string) => { let escaped = std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap()) @@ -144,7 +144,7 @@ fn incomplete(input: &mut String) { fn error(input: &str, state: &mut ReplState, expected_step_result: String) { assert!(!is_incomplete(input)); - let escaped = state.step(input).map(|string| { + let escaped = state.step(input, None).map(|string| { std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap()).unwrap() });