pax_global_header00006660000000000000000000000064134777565600014536gustar00rootroot0000000000000052 comment=49edacfb841a9dac691972c2aa5d40dba8e0b56b cli-cursor-3.1.0/000077500000000000000000000000001347775656000136215ustar00rootroot00000000000000cli-cursor-3.1.0/.editorconfig000066400000000000000000000002571347775656000163020ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 cli-cursor-3.1.0/.gitattributes000066400000000000000000000000231347775656000165070ustar00rootroot00000000000000* text=auto eol=lf cli-cursor-3.1.0/.github/000077500000000000000000000000001347775656000151615ustar00rootroot00000000000000cli-cursor-3.1.0/.github/funding.yml000066400000000000000000000001641347775656000173370ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/cli-cursor custom: https://sindresorhus.com/donate cli-cursor-3.1.0/.github/security.md000066400000000000000000000002631347775656000173530ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. cli-cursor-3.1.0/.gitignore000066400000000000000000000000271347775656000156100ustar00rootroot00000000000000node_modules yarn.lock cli-cursor-3.1.0/.npmrc000066400000000000000000000000231347775656000147340ustar00rootroot00000000000000package-lock=false cli-cursor-3.1.0/.travis.yml000066400000000000000000000000651347775656000157330ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' cli-cursor-3.1.0/index.d.ts000066400000000000000000000014341347775656000155240ustar00rootroot00000000000000/// /** Show cursor. @param stream - Default: `process.stderr`. @example ``` import * as cliCursor from 'cli-cursor'; cliCursor.show(); ``` */ export function show(stream?: NodeJS.WritableStream): void; /** Hide cursor. @param stream - Default: `process.stderr`. @example ``` import * as cliCursor from 'cli-cursor'; cliCursor.hide(); ``` */ export function hide(stream?: NodeJS.WritableStream): void; /** Toggle cursor visibility. @param force - Is useful to show or hide the cursor based on a boolean. @param stream - Default: `process.stderr`. @example ``` import * as cliCursor from 'cli-cursor'; const unicornsAreAwesome = true; cliCursor.toggle(unicornsAreAwesome); ``` */ export function toggle(force?: boolean, stream?: NodeJS.WritableStream): void; cli-cursor-3.1.0/index.js000066400000000000000000000011511347775656000152640ustar00rootroot00000000000000'use strict'; const restoreCursor = require('restore-cursor'); let isHidden = false; exports.show = (writableStream = process.stderr) => { if (!writableStream.isTTY) { return; } isHidden = false; writableStream.write('\u001B[?25h'); }; exports.hide = (writableStream = process.stderr) => { if (!writableStream.isTTY) { return; } restoreCursor(); isHidden = true; writableStream.write('\u001B[?25l'); }; exports.toggle = (force, writableStream) => { if (force !== undefined) { isHidden = force; } if (isHidden) { exports.show(writableStream); } else { exports.hide(writableStream); } }; cli-cursor-3.1.0/index.test-d.ts000066400000000000000000000003351347775656000165000ustar00rootroot00000000000000import * as cliCursor from '.'; cliCursor.hide(); cliCursor.hide(process.stderr); cliCursor.show(); cliCursor.show(process.stderr); cliCursor.toggle(); cliCursor.toggle(false); cliCursor.toggle(false, process.stderr); cli-cursor-3.1.0/license000066400000000000000000000021251347775656000151660ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cli-cursor-3.1.0/package.json000066400000000000000000000013131347775656000161050ustar00rootroot00000000000000{ "name": "cli-cursor", "version": "3.1.0", "description": "Toggle the CLI cursor", "license": "MIT", "repository": "sindresorhus/cli-cursor", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "cli", "cursor", "ansi", "toggle", "display", "show", "hide", "term", "terminal", "console", "tty", "shell", "command-line" ], "dependencies": { "restore-cursor": "^3.1.0" }, "devDependencies": { "@types/node": "^12.0.7", "ava": "^2.1.0", "tsd": "^0.7.2", "xo": "^0.24.0" } } cli-cursor-3.1.0/readme.md000066400000000000000000000021571347775656000154050ustar00rootroot00000000000000# cli-cursor [![Build Status](https://travis-ci.org/sindresorhus/cli-cursor.svg?branch=master)](https://travis-ci.org/sindresorhus/cli-cursor) > Toggle the CLI cursor The cursor is [gracefully restored](https://github.com/sindresorhus/restore-cursor) if the process exits. ## Install ``` $ npm install cli-cursor ``` ## Usage ```js const cliCursor = require('cli-cursor'); cliCursor.hide(); const unicornsAreAwesome = true; cliCursor.toggle(unicornsAreAwesome); ``` ## API ### .show(stream?) ### .hide(stream?) ### .toggle(force?, stream?) #### force Useful for showing or hiding the cursor based on a boolean. #### stream Type: `stream.Writable`
Default: `process.stderr` ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
cli-cursor-3.1.0/test.js000066400000000000000000000022661347775656000151440ustar00rootroot00000000000000import childProcess from 'child_process'; import test from 'ava'; import cliCursor from '.'; const {stderr: {write}} = process; const SHOW = '\u001B[?25h'; const HIDE = '\u001B[?25l'; process.stderr.isTTY = true; function getStderr(fn) { let result = ''; process.stderr.setEncoding('utf8'); process.stderr.write = string => { result += string; }; fn(); process.stderr.write = write; return result; } test('show', t => { t.is(getStderr(cliCursor.show), SHOW); }); test('hide', t => { t.is(getStderr(cliCursor.hide), HIDE); }); test('toggle', t => { cliCursor.hide(); t.is(getStderr(cliCursor.toggle), SHOW); }); test('toggle 2', t => { cliCursor.show(); t.is(getStderr(cliCursor.toggle), HIDE); }); test('toggle force', t => { cliCursor.show(); t.is(getStderr(cliCursor.toggle.bind(null, true)), SHOW); }); test('toggle force 2', t => { cliCursor.hide(); t.is(getStderr(cliCursor.toggle.bind(null, true)), SHOW); }); test('toggle force 3', t => { cliCursor.show(); t.is(getStderr(cliCursor.toggle.bind(null, false)), HIDE); }); // Used to fail, see sindresorhus/log-update#2 test('require', t => { t.is(childProcess.execSync('node index.js', {encoding: 'utf8'}), ''); });