From c5887cea28faac6b400afccbde97eef6ba7482cf Mon Sep 17 00:00:00 2001 From: "Harry Peach (Personal Signing Key)" Date: Wed, 16 Sep 2020 20:55:59 +0100 Subject: [PATCH] Added .getText() and .getFrame() --- README.md | 12 +++++++++--- egg.json | 2 +- kia.test.ts | 15 ++++++++++++++- kia.ts | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 192b9cb..4ed2107 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > Simple terminal spinners for Deno 🦕 -`Version 0.3.0` +`Version 0.4.0` ![](https://github.com/HarryPeach/kia/workflows/CI/badge.svg) @@ -15,7 +15,7 @@ ```typescript -import Kia from "https://deno.land/x/kia@0.3.0/mod.ts"; +import Kia from "https://deno.land/x/kia@0.4.0/mod.ts"; // Just a function to async sleep function sleep(ms: number) { @@ -156,12 +156,18 @@ Stops the spinner and holds it in a static state. Returns the instance. Renders the next frame of the spinner when it is stopped (i.e. can only be run after .stopAndPersist()). +#### .getText() +Returns the current text of the spinner + +#### .getFrame() +Returns the current spinner frame + ### forPromise(action, text) ### forPromise(action, options) ```typescript -import { forPromise } from "https://deno.land/x/kia@0.3.0/mod.ts"; +import { forPromise } from "https://deno.land/x/kia@0.4.0/mod.ts"; forPromise( async () => { diff --git a/egg.json b/egg.json index ca262a4..d2adae0 100644 --- a/egg.json +++ b/egg.json @@ -1,7 +1,7 @@ { "name": "kia", "description": "Simple terminal spinners for Deno 🦕", - "version": "0.3.0", + "version": "0.4.0", "unstable": false, "entry": "/mod.ts", "repository": "https://github.com/HarryPeach/kia", diff --git a/kia.test.ts b/kia.test.ts index 0702bd8..0d855fd 100644 --- a/kia.test.ts +++ b/kia.test.ts @@ -1,4 +1,4 @@ -import Kia, { forPromise } from "./mod.ts"; +import Kia, { forPromise, Spinners } from "./mod.ts"; import { assertThrows } from "https://deno.land/std@0.52.0/testing/asserts.ts"; import { expect } from "https://deno.land/x/expect/mod.ts"; class TestWriter implements Deno.WriterSync { @@ -145,3 +145,16 @@ Deno.test("hidden cursor is returned", () => { .includes("\x1b[?25h") ).toBe(true); }); + +Deno.test("getFrame gets the correct frame", async () => { + const testWriter = new TestWriter(); + const kia = new Kia({writer: testWriter, spinner: Spinners.windows}); + expect(kia.getFrame()).toBe("/"); +}); + +Deno.test("getText gets the correct text", async () => { + const TEST_TEXT = "This is sample text"; + const testWriter = new TestWriter(); + const kia = new Kia({writer: testWriter, text: TEST_TEXT}); + expect(kia.getText()).toEqual(TEST_TEXT); +}); \ No newline at end of file diff --git a/kia.ts b/kia.ts index 394ac38..1b13715 100644 --- a/kia.ts +++ b/kia.ts @@ -66,6 +66,7 @@ export default class Kia { if (this.spinning) { this.stop(); } + this.spinning = true; if (text) this.set(text); @@ -188,6 +189,20 @@ export default class Kia { return this.spinning; } + /** + * Returns the current spinner frame + */ + getFrame(): string { + return this.options.spinner.frames[this.currentFrame]; + } + + /** + * Gets the current text + */ + getText(): string { + return this.options.text; + } + /** * Renders each frame of the spinner */