mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Try printing #val1 at end of previous line
This commit is contained in:
parent
ca33e4f64c
commit
f4937e72cc
2 changed files with 15 additions and 33 deletions
|
@ -45,7 +45,9 @@ pub fn main() -> i32 {
|
|||
loop {
|
||||
match editor.readline(PROMPT) {
|
||||
Ok(line) => {
|
||||
editor.add_history_entry(line.trim());
|
||||
let line = line.trim();
|
||||
|
||||
editor.add_history_entry(line);
|
||||
|
||||
let dimensions = editor.dimensions();
|
||||
let repl_state = &mut editor
|
||||
|
@ -65,7 +67,9 @@ pub fn main() -> i32 {
|
|||
// If there was no output, don't print a blank line!
|
||||
// (This happens for something like a type annotation.)
|
||||
if !output.is_empty() {
|
||||
println!("{output}");
|
||||
// Overwrite the previous line so we can do things like
|
||||
// print " #val1" after what the user just entered.
|
||||
println!("\x1B[A{PROMPT}{line}{output}");
|
||||
}
|
||||
}
|
||||
ReplAction::Exit => {
|
||||
|
|
|
@ -145,45 +145,23 @@ pub fn format_output(
|
|||
if !expr.is_empty() && problems.errors.is_empty() {
|
||||
const EXPR_TYPE_SEPARATOR: &str = " : "; // e.g. in "5 : Num *"
|
||||
|
||||
// Print var_name on the line before the output
|
||||
if let Some(var_name) = opt_var_name {
|
||||
buf.push_str(style_codes.green);
|
||||
buf.push_str(" # ");
|
||||
buf.push_str(&var_name);
|
||||
buf.push_str(style_codes.reset);
|
||||
}
|
||||
|
||||
// Print the expr and its type
|
||||
{
|
||||
buf.push('\n');
|
||||
buf.push_str("\n\n");
|
||||
buf.push_str(&expr);
|
||||
buf.push_str(style_codes.magenta); // Color for the type separator
|
||||
buf.push_str(EXPR_TYPE_SEPARATOR);
|
||||
buf.push_str(style_codes.reset);
|
||||
buf.push_str(&expr_type);
|
||||
}
|
||||
|
||||
// Print var_name right-aligned on the last line of output.
|
||||
if let Some(var_name) = opt_var_name {
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
const VAR_NAME_COLUMN_MIN: usize = 16; // Always draw the line under the answer at least this wide
|
||||
|
||||
let term_width = match dimensions {
|
||||
Some((width, _)) => width.max(VAR_NAME_COLUMN_MIN),
|
||||
None => VAR_NAME_COLUMN_MIN,
|
||||
};
|
||||
|
||||
// Count graphemes because we care about what's *rendered* in the terminal
|
||||
let var_name_len = var_name.graphemes(true).count();
|
||||
|
||||
// Subtract 2 to make room for a space on either side of var_name
|
||||
let line_width = term_width.saturating_sub(var_name_len).saturating_sub(2);
|
||||
|
||||
buf.push('\n');
|
||||
buf.push_str(style_codes.white);
|
||||
|
||||
for _ in 0..line_width {
|
||||
buf.push('─');
|
||||
}
|
||||
|
||||
buf.push(' ');
|
||||
buf.push_str(&var_name);
|
||||
buf.push(' ');
|
||||
buf.push_str(style_codes.reset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue