Skip to content

Commit

Permalink
Merge pull request #7 from HarryPeach/dev
Browse files Browse the repository at this point in the history
Added .getText() and .getFrame(), and new tests
  • Loading branch information
HarryPeach authored Oct 4, 2020
2 parents 68652bd + c5887ce commit d325cc6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) {
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion egg.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 14 additions & 1 deletion kia.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Kia, { forPromise } from "./mod.ts";
import Kia, { forPromise, Spinners } from "./mod.ts";
import { assertThrows } from "https://deno.land/[email protected]/testing/asserts.ts";
import { expect } from "https://deno.land/x/expect/mod.ts";
class TestWriter implements Deno.WriterSync {
Expand Down Expand Up @@ -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);
});
15 changes: 15 additions & 0 deletions kia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default class Kia {
if (this.spinning) {
this.stop();
}

this.spinning = true;

if (text) this.set(text);
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit d325cc6

Please sign in to comment.