main: Clear screen on mode change
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -20,13 +20,17 @@ use std::{
|
||||
io::{IsTerminal, stdin},
|
||||
};
|
||||
|
||||
fn clear() {
|
||||
print!("\x1b[H\x1b[2J\x1b[3J");
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
if stdin().is_terminal() {
|
||||
read_and("\x1b[32m", ".>", " >", |line| match line.trim_end() {
|
||||
"" => Ok(Response::Continue),
|
||||
"exit" => Ok(Response::Break),
|
||||
"clear" => {
|
||||
print!("\x1b[H\x1b[2J");
|
||||
clear();
|
||||
Ok(Response::Deny)
|
||||
}
|
||||
"lex" => {
|
||||
@@ -66,6 +70,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
fn lex() -> Result<(), Box<dyn Error>> {
|
||||
clear();
|
||||
read_and("\x1b[93m", " >", "?>", |line| {
|
||||
let mut lexer = Lexer::new(line);
|
||||
if line.trim().is_empty() {
|
||||
@@ -90,6 +95,7 @@ fn lex() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
fn exprs() -> Result<(), Box<dyn Error>> {
|
||||
clear();
|
||||
read_and("\x1b[93m", ".>", " >", |line| {
|
||||
let mut parser = Parser::new(Lexer::new(line));
|
||||
if line.trim().is_empty() {
|
||||
@@ -113,6 +119,7 @@ fn exprs() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
fn pats() -> Result<(), Box<dyn Error>> {
|
||||
clear();
|
||||
read_and("\x1b[94m", " >", "?>", |line| {
|
||||
let mut parser = Parser::new(Lexer::new(line));
|
||||
if line.trim().is_empty() {
|
||||
@@ -135,6 +142,7 @@ fn pats() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
fn tys() -> Result<(), Box<dyn Error>> {
|
||||
clear();
|
||||
read_and("\x1b[94m", ".>", " >", |line| {
|
||||
let mut parser = Parser::new(Lexer::new(line));
|
||||
if line.trim().is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user