回答編集履歴
4
追記
answer
CHANGED
@@ -101,4 +101,22 @@
|
|
101
101
|
rl.once("line",process.exit);
|
102
102
|
})();
|
103
103
|
g.next();
|
104
|
-
```
|
104
|
+
```
|
105
|
+
|
106
|
+
追記:
|
107
|
+
|
108
|
+
```js
|
109
|
+
> process.stdout
|
110
|
+
WriteStream {
|
111
|
+
...,
|
112
|
+
columns: 80,
|
113
|
+
rows: 25,
|
114
|
+
...,
|
115
|
+
destroy: [Function] }
|
116
|
+
|
117
|
+
> process.stdout.columns
|
118
|
+
80
|
119
|
+
```
|
120
|
+
|
121
|
+
process.stdoutを叩いてみたらその中にcolumns入ってました。
|
122
|
+
これで置換すればどのプラットフォームでも桁数を取得できるのではないでしょうか。
|
3
コード
answer
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
const widthNow=Math.floor(this.width*parcent);
|
41
41
|
|
42
42
|
const gauge=(">".repeat(widthNow)+" ".repeat(this.width-widthNow));
|
43
|
-
const output=`#[${gauge}]#(${
|
43
|
+
const output=`#[${gauge}]#(${(parcent*100).toFixed(1)}%<-${this.par}/${this.parMax})`;
|
44
44
|
|
45
45
|
//列数と文字数(半角のみ)から実際の行数を計算
|
46
46
|
const rows=Math.floor(message.length/this.columns)+2;
|
@@ -64,7 +64,7 @@
|
|
64
64
|
|
65
65
|
var gauge="=".repeat(sideLen)+lastMessage
|
66
66
|
gauge+="=".repeat(this.width-gauge.length)
|
67
|
-
const output=`#[${gauge}]#(100%
|
67
|
+
const output=`#[${gauge}]#(100%<-${this.parMax}/${this.parMax})`;
|
68
68
|
|
69
69
|
//最大列数に合うように空白埋めして表示
|
70
70
|
process.stdout.write(output+" ".repeat(this.columns-output.length)+"\r");
|
@@ -80,12 +80,12 @@
|
|
80
80
|
const thirdMsg="ThirdStep ThirdStep ThirdStep ThirdStep";
|
81
81
|
console.log("START!");
|
82
82
|
|
83
|
-
const width=
|
83
|
+
const width=55;
|
84
|
-
const works=
|
84
|
+
const works=270;
|
85
85
|
const prg=new Progress(width,works);
|
86
86
|
|
87
87
|
for(let i=0;i<=works;i++){
|
88
|
-
yield setTimeout(()=>g.next(),
|
88
|
+
yield setTimeout(()=>g.next(),90);
|
89
89
|
if(i<40){
|
90
90
|
prg.view(firstMsg);
|
91
91
|
}
|
2
コード
answer
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
const widthNow=Math.floor(this.width*parcent);
|
41
41
|
|
42
42
|
const gauge=(">".repeat(widthNow)+" ".repeat(this.width-widthNow));
|
43
|
-
const output=`#[${gauge}]#(${Math.floor(parcent*100)}%)`;
|
43
|
+
const output=`#[${gauge}]#(${Math.floor(parcent*100)}%|${this.par}/${this.parMax})`;
|
44
44
|
|
45
45
|
//列数と文字数(半角のみ)から実際の行数を計算
|
46
46
|
const rows=Math.floor(message.length/this.columns)+2;
|
@@ -64,7 +64,7 @@
|
|
64
64
|
|
65
65
|
var gauge="=".repeat(sideLen)+lastMessage
|
66
66
|
gauge+="=".repeat(this.width-gauge.length)
|
67
|
-
const output=`#[${gauge}]#(100%)`;
|
67
|
+
const output=`#[${gauge}]#(100%|${this.parMax}/${this.parMax})`;
|
68
68
|
|
69
69
|
//最大列数に合うように空白埋めして表示
|
70
70
|
process.stdout.write(output+" ".repeat(this.columns-output.length)+"\r");
|
@@ -81,15 +81,15 @@
|
|
81
81
|
console.log("START!");
|
82
82
|
|
83
83
|
const width=60;
|
84
|
-
const works=
|
84
|
+
const works=130;
|
85
85
|
const prg=new Progress(width,works);
|
86
86
|
|
87
87
|
for(let i=0;i<=works;i++){
|
88
88
|
yield setTimeout(()=>g.next(),100);
|
89
|
-
if(i<
|
89
|
+
if(i<40){
|
90
90
|
prg.view(firstMsg);
|
91
91
|
}
|
92
|
-
else if(i<
|
92
|
+
else if(i<90){
|
93
93
|
prg.view(secondMsg);
|
94
94
|
}
|
95
95
|
else{
|
1
コード
answer
CHANGED
@@ -13,16 +13,16 @@
|
|
13
13
|
|
14
14
|
```js
|
15
15
|
const readline=require("readline");
|
16
|
+
const exec=require("child_process").execSync;
|
16
17
|
const rl=readline.createInterface(process.stdin,process.stdout);
|
17
18
|
|
18
19
|
class Progress{
|
19
20
|
constructor(width,parMax){
|
20
21
|
//最大の列数
|
21
|
-
this.columns=require("child_process") //child_processの、
|
22
|
-
|
22
|
+
this.columns=exec("mode") //コマンドプロンプトからmodeを呼び出して、
|
23
|
-
.toString()
|
23
|
+
.toString() //文字列として取得して、
|
24
|
-
.split(/\r\n/)
|
24
|
+
.split(/\r\n/) //改行で分割し、
|
25
|
-
.filter(val=>{
|
25
|
+
.filter(val=>{ //文字化けした" 桁数: "(=" ����: ")を検索して、
|
26
26
|
if(val.replace(" ����: ","")!=val) return val;
|
27
27
|
})[0].replace(" ����: ","")|0 //無駄な文字を消して整数に変換。
|
28
28
|
|
@@ -101,5 +101,4 @@
|
|
101
101
|
rl.once("line",process.exit);
|
102
102
|
})();
|
103
103
|
g.next();
|
104
|
-
|
105
104
|
```
|