📝 use bold font in test/watchdog.nas

This commit is contained in:
ValKmjolnir
2022-09-01 00:04:14 +08:00
parent 2da3be7fc4
commit 28fc1eb850
2 changed files with 13 additions and 13 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ std::ostream& bold_cyan(std::ostream& s)
std::ostream& bold_orange(std::ostream& s) std::ostream& bold_orange(std::ostream& s)
{ {
#ifdef _WIN32 #ifdef _WIN32
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE),0x0e); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0e);
#else #else
s<<"\033[93;1m"; s<<"\033[93;1m";
#endif #endif
@@ -47,7 +47,7 @@ std::ostream& bold_orange(std::ostream& s)
std::ostream& bold_white(std::ostream& s) std::ostream& bold_white(std::ostream& s)
{ {
#ifdef _WIN32 #ifdef _WIN32
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE),0x0f); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0f);
#else #else
s<<"\033[0m\033[1m"; s<<"\033[0m\033[1m";
#endif #endif
+11 -11
View File
@@ -1,47 +1,47 @@
var os_time=func(){ var os_time=func(){
return "[\e[33m"~os.time()~"\e[0m] "; return "[\e[33;1m"~os.time()~"\e[0m] ";
} }
var err_hd=func(){ var err_hd=func(){
return "[\e[91merror\e[0m] "; return "[\e[91;1merror\e[0m] ";
} }
var watching_hd=func(){ var watching_hd=func(){
return "[\e[96mwatching\e[0m] "; return "[\e[96;1mwatching\e[0m] ";
} }
var modified_hd=func(){ var modified_hd=func(){
return "[\e[92mmodified\e[0m] "; return "[\e[92;1mmodified\e[0m] ";
} }
var usage=func(){ var usage=func(){
println(os_time(),"[\e[92musage\e[0m] nasal watchdog.nas <filename>"); println(os_time(),"[\e[92;1musage\e[0m] \e[1mnasal watchdog.nas <filename>\e[0m");
} }
var argv=runtime.argv(); var argv=runtime.argv();
if(size(argv)!=1){ if(size(argv)!=1){
println(os_time(),err_hd(),"need correct file path to watch"); println(os_time(),err_hd(),"\e[1mneed correct file path to watch\e[0m");
usage(); usage();
exit(-1); exit(-1);
} }
var filename=argv[0]; var filename=argv[0];
if(!io.exists(filename)){ if(!io.exists(filename)){
println(os_time(),err_hd(),"file <",filename,"> does not exist"); println(os_time(),err_hd(),"\e[1mfile <",filename,"> does not exist\e[0m");
usage(); usage();
exit(-1); exit(-1);
} }
var modified_time=fstat(filename).st_mtime; var modified_time=fstat(filename).st_mtime;
println(os_time(),watching_hd(),filename," .."); println(os_time(),watching_hd(),"\e[1m",filename," ..\e[0m");
while(1){ while(1){
unix.sleep(1); unix.sleep(1);
if(!io.exists(filename)){ if(!io.exists(filename)){
println(os_time(),err_hd(),"file <",filename,"> does not exist"); println(os_time(),err_hd(),"\e[1mfile <",filename,"> does not exist\e[0m");
break; break;
} }
var latest_modified_time=fstat(filename).st_mtime; var latest_modified_time=fstat(filename).st_mtime;
if(latest_modified_time!=modified_time){ if(latest_modified_time!=modified_time){
modified_time=latest_modified_time; modified_time=latest_modified_time;
println(os_time(),modified_hd(),filename); println(os_time(),modified_hd(),"\e[1m",filename,"\e[0m");
var ret=system((os.platform()=="windows"?"":"./")~"nasal "~filename); var ret=system((os.platform()=="windows"?"":"./")~"nasal "~filename);
if(ret!=0){ if(ret!=0){
println(os_time(),err_hd(),"process returned value ",ret); println(os_time(),err_hd(),"\e[1mprocess returned value ",ret,"\e[0m");
} }
} }
} }