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},
|
io::{IsTerminal, stdin},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn clear() {
|
||||||
|
print!("\x1b[H\x1b[2J\x1b[3J");
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
if stdin().is_terminal() {
|
if stdin().is_terminal() {
|
||||||
read_and("\x1b[32m", ".>", " >", |line| match line.trim_end() {
|
read_and("\x1b[32m", ".>", " >", |line| match line.trim_end() {
|
||||||
"" => Ok(Response::Continue),
|
"" => Ok(Response::Continue),
|
||||||
"exit" => Ok(Response::Break),
|
"exit" => Ok(Response::Break),
|
||||||
"clear" => {
|
"clear" => {
|
||||||
print!("\x1b[H\x1b[2J");
|
clear();
|
||||||
Ok(Response::Deny)
|
Ok(Response::Deny)
|
||||||
}
|
}
|
||||||
"lex" => {
|
"lex" => {
|
||||||
@@ -66,6 +70,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn lex() -> Result<(), Box<dyn Error>> {
|
fn lex() -> Result<(), Box<dyn Error>> {
|
||||||
|
clear();
|
||||||
read_and("\x1b[93m", " >", "?>", |line| {
|
read_and("\x1b[93m", " >", "?>", |line| {
|
||||||
let mut lexer = Lexer::new(line);
|
let mut lexer = Lexer::new(line);
|
||||||
if line.trim().is_empty() {
|
if line.trim().is_empty() {
|
||||||
@@ -90,6 +95,7 @@ fn lex() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn exprs() -> Result<(), Box<dyn Error>> {
|
fn exprs() -> Result<(), Box<dyn Error>> {
|
||||||
|
clear();
|
||||||
read_and("\x1b[93m", ".>", " >", |line| {
|
read_and("\x1b[93m", ".>", " >", |line| {
|
||||||
let mut parser = Parser::new(Lexer::new(line));
|
let mut parser = Parser::new(Lexer::new(line));
|
||||||
if line.trim().is_empty() {
|
if line.trim().is_empty() {
|
||||||
@@ -113,6 +119,7 @@ fn exprs() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn pats() -> Result<(), Box<dyn Error>> {
|
fn pats() -> Result<(), Box<dyn Error>> {
|
||||||
|
clear();
|
||||||
read_and("\x1b[94m", " >", "?>", |line| {
|
read_and("\x1b[94m", " >", "?>", |line| {
|
||||||
let mut parser = Parser::new(Lexer::new(line));
|
let mut parser = Parser::new(Lexer::new(line));
|
||||||
if line.trim().is_empty() {
|
if line.trim().is_empty() {
|
||||||
@@ -135,6 +142,7 @@ fn pats() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tys() -> Result<(), Box<dyn Error>> {
|
fn tys() -> Result<(), Box<dyn Error>> {
|
||||||
|
clear();
|
||||||
read_and("\x1b[94m", ".>", " >", |line| {
|
read_and("\x1b[94m", ".>", " >", |line| {
|
||||||
let mut parser = Parser::new(Lexer::new(line));
|
let mut parser = Parser::new(Lexer::new(line));
|
||||||
if line.trim().is_empty() {
|
if line.trim().is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user