🚀 add high resolution progress bar
This commit is contained in:
parent
6ef22d3228
commit
946aa020a5
|
@ -91,11 +91,7 @@ If you think `-O3` isn't that safe and stable, you could choose:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
If your system is `Windows` and you want to output unicode,please use this command before running nasal:
|
If your system is `Windows` and you want to output unicode, you could write this in nasal code:
|
||||||
|
|
||||||
> chcp 65001
|
|
||||||
|
|
||||||
or you could write this in nasal code:
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
if(os.platform()=="windows")
|
if(os.platform()=="windows")
|
||||||
|
|
|
@ -80,11 +80,7 @@ __注意__: 如果你想直接下载发行版提供的zip/tar.gz压缩包来构
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
如果你的操作系统是 `Windows` 且想输出unicode,请保证控制台代码页支持utf-8,使用下面这个命令启用代码页:
|
如果你是 `Windows` 用户且想正常输出unicode,在nasal代码里写这个来开启unicode代码页:
|
||||||
|
|
||||||
> chcp 65001
|
|
||||||
|
|
||||||
或者直接在nasal代码里写这个来开启:
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
if(os.platform()=="windows")
|
if(os.platform()=="windows")
|
||||||
|
|
|
@ -276,8 +276,7 @@ std::ostream& operator<<(std::ostream& out,nas_vec& vec)
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
vec.printed=true;
|
vec.printed=true;
|
||||||
usize iter=0;
|
usize iter=0,size=vec.elems.size();
|
||||||
usize size=vec.elems.size();
|
|
||||||
out<<'[';
|
out<<'[';
|
||||||
for(auto& i:vec.elems)
|
for(auto& i:vec.elems)
|
||||||
out<<i<<",]"[(++iter)==size];
|
out<<i<<",]"[(++iter)==size];
|
||||||
|
@ -331,8 +330,7 @@ std::ostream& operator<<(std::ostream& out,nas_hash& hash)
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
hash.printed=true;
|
hash.printed=true;
|
||||||
usize iter=0;
|
usize iter=0,size=hash.elems.size();
|
||||||
usize size=hash.elems.size();
|
|
||||||
out<<'{';
|
out<<'{';
|
||||||
for(auto& i:hash.elems)
|
for(auto& i:hash.elems)
|
||||||
out<<i.first<<':'<<i.second<<",}"[(++iter)==size];
|
out<<i.first<<':'<<i.second<<",}"[(++iter)==size];
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
|
|
||||||
var process_bar={
|
var process_bar={
|
||||||
bar:nil,
|
bar:nil,
|
||||||
|
high_resolution_bar:nil,
|
||||||
spinner:nil
|
spinner:nil
|
||||||
};
|
};
|
||||||
|
|
||||||
process_bar.bar=func(){
|
process_bar.bar=func(){
|
||||||
var bar={
|
var bar={
|
||||||
solid_triangle_right:"▶",
|
solid_triangle_right:"▶",
|
||||||
|
@ -62,6 +64,45 @@ process_bar.bar=func(){
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
# return a high resolution progress bar
|
||||||
|
# example:
|
||||||
|
# var bar=process_bar.high_resolution_bar(40);
|
||||||
|
# for(var i=0;i<=1;i+=0.001){
|
||||||
|
# print(bar.bar(i,40),'\r');
|
||||||
|
# unix.sleep(0.001);
|
||||||
|
# }
|
||||||
|
# println();
|
||||||
|
process_bar.high_resolution_bar=func(){
|
||||||
|
var block=["▏","▎","▍","▌","▋","▊","▉","█"];
|
||||||
|
return func(length){
|
||||||
|
return {
|
||||||
|
bar: func(number){
|
||||||
|
if(number>1)
|
||||||
|
number=1;
|
||||||
|
if(number<0)
|
||||||
|
number=0;
|
||||||
|
var block_len=number*length;
|
||||||
|
var complete_block=int(block_len);
|
||||||
|
var decimal=block_len-complete_block;
|
||||||
|
var progress=complete_block+(decimal!=0);
|
||||||
|
var s="|";
|
||||||
|
for(var i=0;i<complete_block;i+=1){
|
||||||
|
s~="█";
|
||||||
|
}
|
||||||
|
if(decimal!=0){
|
||||||
|
s~=block[int(decimal*10)/10*size(block)];
|
||||||
|
}
|
||||||
|
for(var i=0;i<length-progress;i+=1){
|
||||||
|
s~=" ";
|
||||||
|
}
|
||||||
|
s~="|";
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
|
||||||
process_bar.spinner=func(){
|
process_bar.spinner=func(){
|
||||||
var generate_scrolling_spinner=func(s){
|
var generate_scrolling_spinner=func(s){
|
||||||
if(typeof(s)!="str")
|
if(typeof(s)!="str")
|
||||||
|
|
|
@ -106,7 +106,7 @@ var count=func(s,c){
|
||||||
}
|
}
|
||||||
|
|
||||||
var column=func(number){
|
var column=func(number){
|
||||||
number=number>=1000?int(number/1000)~'k':str(number);
|
number=number>=1000?substr(str(number/1000),0,3)~'k':str(number);
|
||||||
return rightpad(number,6);
|
return rightpad(number,6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,10 @@ var total=1000; # ms
|
||||||
var co=coroutine.create(productor);
|
var co=coroutine.create(productor);
|
||||||
var tm=maketimestamp();
|
var tm=maketimestamp();
|
||||||
|
|
||||||
|
if(os.platform()=="windows")
|
||||||
|
system("chcp 65001");
|
||||||
var counter=0;
|
var counter=0;
|
||||||
var bar=process_bar.bar("block","point","line",40);
|
var bar=process_bar.high_resolution_bar(40);
|
||||||
var consumer=func(){
|
var consumer=func(){
|
||||||
counter+=1;
|
counter+=1;
|
||||||
for(var i=0;i<5;i+=1)
|
for(var i=0;i<5;i+=1)
|
||||||
|
|
|
@ -13,7 +13,7 @@ var compare=func(){
|
||||||
var total=end-begin;
|
var total=end-begin;
|
||||||
var timestamp=maketimestamp();
|
var timestamp=maketimestamp();
|
||||||
timestamp.stamp();
|
timestamp.stamp();
|
||||||
var bar=process_bar.bar(front:os.platform()=="windows"?"sharp":"block",back:"point",sep:"line",length:50);
|
var bar=process_bar.high_resolution_bar(50);
|
||||||
for(var i=begin;i<end;i+=1){
|
for(var i=begin;i<end;i+=1){
|
||||||
var s="";
|
var s="";
|
||||||
for(var j=0;j<i;j+=1){
|
for(var j=0;j<i;j+=1){
|
||||||
|
@ -76,7 +76,7 @@ var filechecksum=func(){
|
||||||
var total=size(files);
|
var total=size(files);
|
||||||
var timestamp=maketimestamp();
|
var timestamp=maketimestamp();
|
||||||
timestamp.stamp();
|
timestamp.stamp();
|
||||||
var bar=process_bar.bar(front:os.platform()=="windows"?"sharp":"block",back:"point",sep:"line",length:50);
|
var bar=process_bar.high_resolution_bar(50);
|
||||||
forindex(var i;files){
|
forindex(var i;files){
|
||||||
var f=io.fin(files[i]);
|
var f=io.fin(files[i]);
|
||||||
var res=md5(f);
|
var res=md5(f);
|
||||||
|
@ -94,5 +94,7 @@ var randomchecksum=func(){
|
||||||
compare(i,i+512);
|
compare(i,i+512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(os.platform()=="windows")
|
||||||
|
system("chcp 65001");
|
||||||
filechecksum();
|
filechecksum();
|
||||||
randomchecksum();
|
randomchecksum();
|
|
@ -47,7 +47,7 @@ func(){
|
||||||
var mem_occ=(mem.MemTotal-mem.MemFree)/mem.MemTotal*100;
|
var mem_occ=(mem.MemTotal-mem.MemFree)/mem.MemTotal*100;
|
||||||
var cpu_occ=cpu_occupation();
|
var cpu_occ=cpu_occupation();
|
||||||
var key=libkey.nonblock();
|
var key=libkey.nonblock();
|
||||||
var bar=process_bar.bar("block","point","line",25);
|
var bar=process_bar.high_resolution_bar(25);
|
||||||
if(key!=nil and chr(key)=="q")
|
if(key!=nil and chr(key)=="q")
|
||||||
break;
|
break;
|
||||||
println("\e[1;1H\e[1m Memory total(GB) : \e[0m\e[36m",mem.MemTotal/1024/1024,"\e[0m");
|
println("\e[1;1H\e[1m Memory total(GB) : \e[0m\e[36m",mem.MemTotal/1024/1024,"\e[0m");
|
||||||
|
|
|
@ -15,7 +15,9 @@ var ppm=func(filename,width,height,RGB){
|
||||||
|
|
||||||
var width=1280;
|
var width=1280;
|
||||||
var height=720;
|
var height=720;
|
||||||
var bar=process_bar.bar(front:os.platform()=="windows"?"sharp":"block",back:"point",sep:"line",length:50);
|
var bar=(os.platform()=="windows")?
|
||||||
|
process_bar.bar(front:"sharp",back:"point",sep:"line",length:50):
|
||||||
|
process_bar.high_resolution_bar(50);
|
||||||
var f=func(i,j){
|
var f=func(i,j){
|
||||||
var (yMin,yMax,xMin,xMax)=(-1.35,1.35,-3.3,1.5);
|
var (yMin,yMax,xMin,xMax)=(-1.35,1.35,-3.3,1.5);
|
||||||
var (yDel,xDel)=(yMax-yMin,xMax-xMin);
|
var (yDel,xDel)=(yMax-yMin,xMax-xMin);
|
||||||
|
|
Loading…
Reference in New Issue