Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu4k committed Aug 25, 2020
1 parent 62265b0 commit 0e207a1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
7 changes: 3 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { showCursorSync } from "./tty_sync.ts";

const mac =
(await Deno.permissions.query({ name: "env" })).state === "granted"
? Deno.env.get("TERM_PROGRAM") === "Apple_Terminal"
: false;
const mac = (await Deno.permissions.query({ name: "env" })).state === "granted"
? Deno.env.get("TERM_PROGRAM") === "Apple_Terminal"
: false;

export const ESC = "\u001B[";

Expand Down
40 changes: 20 additions & 20 deletions tty_async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,92 +29,92 @@ export async function write(str: string, writer: AsyncStream): Promise<void> {
}

export async function restore(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await write(RESTORE, writer);
}

export async function cursor(
action: string,
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await write(ESC + action, writer);
}

export async function position(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(POSITION, writer);
}

export async function hideCursor(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(HIDE, writer);
}

export async function showCursor(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(SHOW, writer);
}

export async function scrollUp(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(SCROLL_UP, writer);
}

export async function scrollDown(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(SCROLL_DOWN, writer);
}

export async function clearUp(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_UP, writer);
}

export async function clearDown(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_DOWN, writer);
}

export async function clearLeft(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_LEFT, writer);
}

export async function clearRight(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_RIGHT, writer);
}

export async function clearLine(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_LINE, writer);
}

export async function clearScreen(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_SCREEN, writer);
}

export async function nextLine(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(NEXT_LINE, writer);
}

export async function prevLine(
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(PREV_LINE, writer);
}
Expand All @@ -125,36 +125,36 @@ export async function goHome(writer: AsyncStream = Deno.stdout): Promise<void> {

export async function goUp(
y = 1,
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(y + UP, writer);
}

export async function goDown(
y = 1,
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(y + DOWN, writer);
}

export async function goLeft(
x = 1,
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(x + LEFT, writer);
}

export async function goRight(
x = 1,
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(x + RIGHT, writer);
}

export async function goTo(
x: number,
y: number,
writer: AsyncStream = Deno.stdout
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await write(ESC + y + ";" + x + HOME, writer);
}
4 changes: 2 additions & 2 deletions tty_sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function restoreSync(writer: SyncStream = Deno.stdout): void {

export function cursorSync(
action: string,
writer: SyncStream = Deno.stdout
writer: SyncStream = Deno.stdout,
): void {
writeSync(ESC + action, writer);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ export function goRightSync(x = 1, writer: SyncStream = Deno.stdout): void {
export function goToSync(
x: number,
y: number,
writer: SyncStream = Deno.stdout
writer: SyncStream = Deno.stdout,
): void {
writeSync(ESC + y + ";" + x + HOME, writer);
}
26 changes: 13 additions & 13 deletions wcwidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type Defaults = {
*/
export function wcswidth(
str: any,
{ nul = 0, control = 0 }: Defaults = {}
{ nul = 0, control = 0 }: Defaults = {},
): number {
const opts = { nul, control };
if (typeof str !== "string") return wcwidth(str, opts);
Expand All @@ -57,18 +57,18 @@ function wcwidth(ucs: any, { nul = 0, control = 0 }: Defaults = {}): number {
return (
1 +
(ucs >= 0x1100 &&
(ucs <= 0x115f || // Hangul Jamo init. consonants
ucs == 0x2329 ||
ucs == 0x232a ||
(ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || // CJK ... Yi
(ucs >= 0xac00 && ucs <= 0xd7a3) || // Hangul Syllables
(ucs >= 0xf900 && ucs <= 0xfaff) || // CJK Compatibility Ideographs
(ucs >= 0xfe10 && ucs <= 0xfe19) || // Vertical forms
(ucs >= 0xfe30 && ucs <= 0xfe6f) || // CJK Compatibility Forms
(ucs >= 0xff00 && ucs <= 0xff60) || // Fullwidth Forms
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
(ucs >= 0x30000 && ucs <= 0x3fffd))
(ucs <= 0x115f || // Hangul Jamo init. consonants
ucs == 0x2329 ||
ucs == 0x232a ||
(ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || // CJK ... Yi
(ucs >= 0xac00 && ucs <= 0xd7a3) || // Hangul Syllables
(ucs >= 0xf900 && ucs <= 0xfaff) || // CJK Compatibility Ideographs
(ucs >= 0xfe10 && ucs <= 0xfe19) || // Vertical forms
(ucs >= 0xfe30 && ucs <= 0xfe6f) || // CJK Compatibility Forms
(ucs >= 0xff00 && ucs <= 0xff60) || // Fullwidth Forms
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
(ucs >= 0x30000 && ucs <= 0x3fffd))
? 1
: 0)
);
Expand Down

0 comments on commit 0e207a1

Please sign in to comment.