-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathio.js
54 lines (44 loc) · 1.5 KB
/
io.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//responsible for writing request output
class ResponseWriter{
/*
* This class is responsible for outputting the http request responses to the terminal.
*
*/
constructor(demo,oa){
this.bLastOutputImportant=true;
this.demo = demo;
this.oa=oa;
}
write(message, clamp=process.stdout.columns-2){
/*
* write the message, delete last line if it was marked not important.
* Clamp to the length of second parameter if passed.
*/
//if message is longer than the clamp length, clamp it and append ...
if(message.length >=clamp)
message = (message.substring(0, clamp - 3) + "...")
//if demo mode is activated, hide base url
if(this.demo){
message = message.replace(/http(s)?:\/\/.*?\//, "https://[REDACTED]/")
}
//output all mode, write every response, even normal ones
if(this.oa){
process.stdout.write("\n" + message)
}else{
//if last output wasn't registered as important, delete the last line
if(!this.bLastOutputImportant){
this.deleteLastLine(true)
process.stdout.write(message)
}else{
process.stdout.write("\n" + message)
}
}
}
deleteLastLine(force=false){
if(!force && this.bLastOutputImportant) return
process.stdout.write("\r\x1b[K")
}
}
module.exports ={
OutputHandler: ResponseWriter
}