From fc9595ab38c9af69a15182e62629a3f8612f4171 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Tue, 28 May 2019 18:06:23 -0500 Subject: [PATCH] FEATURE: Show line numbers for ucg statements in the repl. --- src/io/mod.rs | 4 ++++ src/main.rs | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/io/mod.rs b/src/io/mod.rs index 377ddeb..7fcbb58 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -24,6 +24,10 @@ impl StatementAccumulator { Self { acc: Vec::new() } } + pub fn next_line(&self) -> usize { + self.acc.len() + 1 + } + /// Tells you if the latest line ends in the statement terminator. /// /// Returns None if it wasn't a terminated statement and leaves the diff --git a/src/main.rs b/src/main.rs index e48219e..db08adb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -551,9 +551,11 @@ fn do_repl( let mut builder = build::FileBuilder::new(std::env::current_dir()?, import_paths, cache); // loop let mut lines = ucglib::io::StatementAccumulator::new(); + println!("Welcome to the UCG repl. Ctrl-D to exit"); + println!(""); loop { // print prompt - lines.push(editor.readline("ucg> ")?); + lines.push(editor.readline(&format!("{}> ", lines.next_line()))?); // check to see if that line is a statement loop { // read a statement @@ -573,7 +575,7 @@ fn do_repl( break; } // if not then keep accumulating lines without a prompt - lines.push(editor.readline(">> ")?); + lines.push(editor.readline(&format!("{}> ", lines.next_line()))?); } } }