termenv
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

termenv

npm version npm downloads jsr version

📦 Installation

npm install termenv

📚 Usage

import {
  getSupportedLevel,
  is16ColorSupported,
  is256ColorSupported,
  isColorsSupported,
  isTrueColorSupported,
  isUnicodeSupported,
} from "termenv";

console.log(getSupportedLevel()); // => 3 | 2 | 1 | 0
// 3: 24-bit color support (16m colors)
// 2: 8-bit color support (256 colors)
// 1: 4-bit color support (16 colors)
// 0: no color support

console.log(isColorsSupported()); // => true | false
console.log(is16ColorSupported()); // => true | false
console.log(is256ColorSupported()); // => true | false
console.log(isTrueColorSupported()); // => true | false

console.log(isUnicodeSupported()); // => true | false

Utilities

import {
  ERASE_LINE,
  ERASE_LINE_LEFT,
  ERASE_LINE_RIGHT,
  ERASE_SCREEN,
  ERASE_SCREEN_LEFT,
  ERASE_SCREEN_RIGHT,
  RESET,
  strip
} from "termenv/utils";

// strip ansi escape codes from a string
console.log(strip("\u001B[31mHello world!\u001B[39m")); // => Hello world!

process.stdout.write(RESET); // reset the terminal
process.stdout.write(ERASE_LINE); // erase the current line
process.stdout.write(ERASE_LINE_LEFT); // erase the line to the left of the cursor
process.stdout.write(ERASE_LINE_RIGHT); // erase the line to the right of the cursor
process.stdout.write(ERASE_SCREEN); // erase the screen
process.stdout.write(ERASE_SCREEN_LEFT); // erase the screen to the left of the cursor
process.stdout.write(ERASE_SCREEN_RIGHT); // erase the screen to the right of the cursor

Window Size

import { getWindowSize } from "termenv/window-size";

console.log(getWindowSize()); // => { width: 40, height: 40 }

📄 License

Published under MIT License.

Package Sidebar

Install

npm i termenv

Weekly Downloads

2

Version

0.3.3

License

MIT

Unpacked Size

29.4 kB

Total Files

27

Last publish

Collaborators

  • luxass