From b022b25cea6a3c2802dbcce29249df4fb9f125d7 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Wed, 31 Aug 2022 00:56:19 +0800 Subject: [PATCH] :rocket: add colorful error info print. --- main.cpp | 4 ++-- nasal.h | 4 ---- nasal_err.h | 29 ++++++++++++++++++++++++++--- nasal_lexer.h | 4 ---- test/filesystem.nas | 4 ++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/main.cpp b/main.cpp index 732413c..7491977 100644 --- a/main.cpp +++ b/main.cpp @@ -61,7 +61,7 @@ void logo() <<" / \\/ / _` / __|/ _` | |\n" <<" / /\\ / (_| \\__ \\ (_| | |\n" <<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n" - <<"nasal ver : "<<__nasver<<" ("<<__DATE__<<" "<<__TIME__<<")\n" + <<"version : "<<__nasver<<" ("<<__DATE__<<" "<<__TIME__<<")\n" <<"c++ std : "<<__cplusplus<<"\n" <<"thanks to : https://github.com/andyross/nasal\n" <<"code repo : https://github.com/ValKmjolnir/Nasal-Interpreter\n" @@ -135,7 +135,7 @@ i32 main(i32 argc,const char* argv[]) { string s(argv[1]); if(s=="-v" || s=="--version") - logo(); + std::clog<<"nasal "<<__nasver<<" ("<<__DATE__<<" "<<__TIME__<<")\n"; else if(s=="-h" || s=="--help") help(); else if(s[0]!='-') diff --git a/nasal.h b/nasal.h index 6c4bf80..9102140 100644 --- a/nasal.h +++ b/nasal.h @@ -138,11 +138,7 @@ string rawstr(const string& str,const usize maxlen=0) case '\v': ret+="\\v"; break; case '\f': ret+="\\f"; break; case '\r': ret+="\\r"; break; -#ifdef _MSC_VER case '\033':ret+="\\e";break; -#else - case '\e': ret+="\\e"; break; -#endif case '\"': ret+="\\\"";break; case '\'': ret+="\\\'";break; case '\\': ret+="\\\\";break; diff --git a/nasal_err.h b/nasal_err.h index f7bf77a..2f6d69c 100644 --- a/nasal_err.h +++ b/nasal_err.h @@ -6,6 +6,10 @@ #include // MSVC need this to use std::getline #include +#ifdef _WIN32 +#include // use SetConsoleTextAttribute +#endif + class fstreamline { protected: @@ -45,18 +49,36 @@ class nasal_err:public fstreamline { private: u32 error; + void printstg(const char* stage) + { +#ifdef _WIN32 + CONSOLE_SCREEN_BUFFER_INFO scrinfo; + GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE),&scrinfo); + SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE),0x03); + std::cerr<<"["; + SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE),0x0c); + std::cerr<\e[0m"); + println("\e[34m",i==last?" └─":" ├─","\e[0m\e[33m[",f,"]\e[36m>\e[0m"); append(s,i==last?" ":" │ "); prt(s,path~"/"~f); pop(s); @@ -32,5 +32,5 @@ var prt=func(s,path){ if(os.platform()=="windows") system("chcp 65001"); -println("\e[36m[",unix.getcwd(),"]>\e[0m"); +println("\e[33m[",unix.getcwd(),"]\e[36m>\e[0m"); prt([""],"."); \ No newline at end of file