diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index c512856..7aa12ef 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -18,4 +18,4 @@ jobs: run: deno fmt --check - name: Run deno lint - run: deno lint --unstable + run: deno lint diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..bddf42e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +name: Publish +on: + workflow_dispatch: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@v4 + - name: Install Deno + uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + + - name: Publish package + run: deno publish diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index aff1c96..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: release - -on: - push: - tags: - - "*.*.*" -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Release - uses: softprops/action-gh-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - draft: true diff --git a/LICENSE b/LICENSE index fd029c9..3e5e81a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-present the denosaurs team +Copyright (c) 2020-2024 the denosaurs team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..121d901 --- /dev/null +++ b/deno.json @@ -0,0 +1,10 @@ +{ + "name": "@denosaurs/tty", + "version": "0.2.0", + "exports": { + ".": "./mod.ts" + }, + "tasks": { + "update": "deno run --allow-net --allow-write update.ts" + } +} diff --git a/is_interactive.ts b/is_interactive.ts index 18a90e3..0dc2f21 100644 --- a/is_interactive.ts +++ b/is_interactive.ts @@ -1,16 +1,16 @@ export async function isInteractiveAsync( - stream: { rid: number }, + stream: { isTerminal(): boolean }, ): Promise { if (await Deno.permissions.query({ name: "env" })) { return ( - Deno.isatty(stream.rid) && + stream.isTerminal() && Deno.env.get("TERM") !== "dumb" && !Deno.env.get("CI") ); } - return Deno.isatty(stream.rid); + return stream.isTerminal(); } -export function isInteractive(stream: { rid: number }): boolean { - return Deno.isatty(stream.rid); +export function isInteractive(stream: { isTerminal(): boolean }): boolean { + return stream.isTerminal(); } diff --git a/mod.ts b/mod.ts index b6c3eeb..330afa3 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,7 @@ -const mac = (await Deno.permissions.query({ name: "env" })).state === "granted" - ? Deno.env.get("TERM_PROGRAM") === "Apple_Terminal" - : false; +const mac: boolean = + (await Deno.permissions.query({ name: "env" })).state === "granted" + ? Deno.env.get("TERM_PROGRAM") === "Apple_Terminal" + : false; export const ESC = "\u001B["; @@ -31,8 +32,8 @@ export const PREV_LINE = "1F"; export const COLUMN = "1G"; // left? export const HOME = "H"; -export type SyncStream = Deno.WriterSync; -export type AsyncStream = Deno.Writer; +export type SyncStream = Pick; +export type AsyncStream = Pick; export * from "./tty_async.ts"; export * from "./tty_sync.ts"; diff --git a/tty_async.ts b/tty_async.ts index 31cf575..d75d8cd 100644 --- a/tty_async.ts +++ b/tty_async.ts @@ -1,7 +1,7 @@ import { encode } from "./util.ts"; import { - AsyncStream, + type AsyncStream, CLEAR_DOWN, CLEAR_LEFT, CLEAR_LINE, diff --git a/tty_sync.ts b/tty_sync.ts index 98cb0ab..4c10b40 100644 --- a/tty_sync.ts +++ b/tty_sync.ts @@ -20,7 +20,7 @@ import { SCROLL_DOWN, SCROLL_UP, SHOW, - SyncStream, + type SyncStream, UP, } from "./mod.ts";