Skip to content

Commit 0e7d5f5

Browse files
authored
Add files via upload
1 parent 47d8cdb commit 0e7d5f5

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

main.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const readline = require('readline');
2+
var config={"text":"Progress: ", "indicator":"=", "pLength":100};
3+
function setProgress(progress){
4+
let r1 = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout
7+
});
8+
let cursorPosition = readline.getCursorPos;
9+
let step=(config.pLength*progress)/100; //pLength:100=x:progress
10+
let text = config.text;
11+
let indicator = config.indicator;
12+
readline.cursorTo(process.stdout, 0, cursorPosition);
13+
readline.clearLine(process.stdout, 0);
14+
readline.cursorTo(process.stdout, 0, cursorPosition);
15+
r1.write(text + " |");
16+
for(let i = 0; i<config.pLength; i++){
17+
if(i>=Math.round(step)){
18+
r1.write(" ");
19+
}else{
20+
r1.write(indicator);
21+
}
22+
}
23+
r1.write("| " + progress + "%");
24+
r1.close();
25+
}
26+
function setConfig(){
27+
for(let i = 0; i<arguments.length; i++){
28+
let splitted = arguments[i].split(":");
29+
if(i==3){
30+
config[splitted[0]] = parseInt(splitted[1])
31+
}else{
32+
config[splitted[0]] = splitted[1];
33+
}
34+
};
35+
}
36+
module.exports = {setProgress, setConfig};

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "ascii-progressbar",
3+
"version": "1.0.1",
4+
"description": "A simple ascii progressbar",
5+
"main": "main.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/MatteoBax/ascii-progressbar.git"
12+
},
13+
"author": "matteobax",
14+
"license": "ISC",
15+
"bugs": {
16+
"url": "https://github.com/MatteoBax/ascii-progressbar/issues"
17+
},
18+
"homepage": "https://github.com/MatteoBax/ascii-progressbar#readme"
19+
}

0 commit comments

Comments
 (0)