Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBax authored Dec 30, 2022
1 parent 47d8cdb commit 0e7d5f5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
36 changes: 36 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const readline = require('readline');
var config={"text":"Progress: ", "indicator":"=", "pLength":100};
function setProgress(progress){
let r1 = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let cursorPosition = readline.getCursorPos;
let step=(config.pLength*progress)/100; //pLength:100=x:progress
let text = config.text;
let indicator = config.indicator;
readline.cursorTo(process.stdout, 0, cursorPosition);
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0, cursorPosition);
r1.write(text + " |");
for(let i = 0; i<config.pLength; i++){
if(i>=Math.round(step)){
r1.write(" ");
}else{
r1.write(indicator);
}
}
r1.write("| " + progress + "%");
r1.close();
}
function setConfig(){
for(let i = 0; i<arguments.length; i++){
let splitted = arguments[i].split(":");
if(i==3){
config[splitted[0]] = parseInt(splitted[1])
}else{
config[splitted[0]] = splitted[1];
}
};
}
module.exports = {setProgress, setConfig};
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "ascii-progressbar",
"version": "1.0.1",
"description": "A simple ascii progressbar",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MatteoBax/ascii-progressbar.git"
},
"author": "matteobax",
"license": "ISC",
"bugs": {
"url": "https://github.com/MatteoBax/ascii-progressbar/issues"
},
"homepage": "https://github.com/MatteoBax/ascii-progressbar#readme"
}

0 comments on commit 0e7d5f5

Please sign in to comment.