summaryrefslogtreecommitdiff
path: root/src/misc/cli/indicator.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-07 19:19:00 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-07 19:19:00 +0900
commitaa4ef6745ad798bd7d4f05cb397ef1dd85279814 (patch)
treed34ded516f52b91c4ff1a5443776ce22d8f483f0 /src/misc/cli/indicator.ts
parentRefactorijg (diff)
downloadsharkey-aa4ef6745ad798bd7d4f05cb397ef1dd85279814.tar.gz
sharkey-aa4ef6745ad798bd7d4f05cb397ef1dd85279814.tar.bz2
sharkey-aa4ef6745ad798bd7d4f05cb397ef1dd85279814.zip
Refactorng
Diffstat (limited to 'src/misc/cli/indicator.ts')
-rw-r--r--src/misc/cli/indicator.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/misc/cli/indicator.ts b/src/misc/cli/indicator.ts
new file mode 100644
index 0000000000..3e23f9b274
--- /dev/null
+++ b/src/misc/cli/indicator.ts
@@ -0,0 +1,35 @@
+import * as readline from 'readline';
+
+/**
+ * Indicator
+ */
+export default class {
+ private clock: NodeJS.Timer;
+
+ constructor(text: string) {
+ let i = 0; // Dots counter
+
+ draw();
+ this.clock = setInterval(draw, 300);
+
+ function draw(): void {
+ cll();
+ i = (i + 1) % 4;
+ const dots = new Array(i + 1).join('.');
+ process.stdout.write(text + dots); // Write text
+ }
+ }
+
+ public end(): void {
+ clearInterval(this.clock);
+ cll();
+ }
+}
+
+/**
+ * Clear current line
+ */
+function cll(): void {
+ readline.clearLine(process.stdout, 0); // Clear current text
+ readline.cursorTo(process.stdout, 0, null); // Move cursor to the head of line
+}