pax_global_header00006660000000000000000000000064130347634260014522gustar00rootroot0000000000000052 comment=5a403335e6b3980a1235b71f8afe1d63ee8c3ce1 cli-cursor-2.1.0/000077500000000000000000000000001303476342600136045ustar00rootroot00000000000000cli-cursor-2.1.0/.editorconfig000066400000000000000000000002761303476342600162660ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 cli-cursor-2.1.0/.gitattributes000066400000000000000000000000351303476342600164750ustar00rootroot00000000000000* text=auto *.js text eol=lf cli-cursor-2.1.0/.gitignore000066400000000000000000000000151303476342600155700ustar00rootroot00000000000000node_modules cli-cursor-2.1.0/.travis.yml000066400000000000000000000000671303476342600157200ustar00rootroot00000000000000sudo: false language: node_js node_js: - '6' - '4' cli-cursor-2.1.0/index.js000066400000000000000000000010511303476342600152460ustar00rootroot00000000000000'use strict'; const restoreCursor = require('restore-cursor'); let hidden = false; exports.show = stream => { const s = stream || process.stderr; if (!s.isTTY) { return; } hidden = false; s.write('\u001b[?25h'); }; exports.hide = stream => { const s = stream || process.stderr; if (!s.isTTY) { return; } restoreCursor(); hidden = true; s.write('\u001b[?25l'); }; exports.toggle = (force, stream) => { if (force !== undefined) { hidden = force; } if (hidden) { exports.show(stream); } else { exports.hide(stream); } }; cli-cursor-2.1.0/license000066400000000000000000000021371303476342600151540ustar00rootroot00000000000000The MIT License (MIT) 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-2.1.0/package.json000066400000000000000000000013331303476342600160720ustar00rootroot00000000000000{ "name": "cli-cursor", "version": "2.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": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "cli", "cursor", "ansi", "toggle", "display", "show", "hide", "term", "terminal", "console", "tty", "shell", "command-line" ], "dependencies": { "restore-cursor": "^2.0.0" }, "devDependencies": { "ava": "*", "xo": "*" }, "xo": { "esnext": true } } cli-cursor-2.1.0/readme.md000066400000000000000000000013601303476342600153630ustar00rootroot00000000000000# 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 --save 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` is useful to show or hide the cursor based on a boolean. #### stream Type: `Stream`
Default: `process.stderr` ## License MIT © [Sindre Sorhus](https://sindresorhus.com) cli-cursor-2.1.0/test.js000066400000000000000000000022511303476342600151210ustar00rootroot00000000000000import childProcess from 'child_process'; import test from 'ava'; import cliCursor from './'; const write = process.stderr.write; const SHOW = '\u001b[?25h'; const HIDE = '\u001b[?25l'; process.stderr.isTTY = true; function getStderr(fn) { let ret = ''; process.stderr.setEncoding('utf8'); process.stderr.write = str => { ret += str; }; fn(); process.stderr.write = write; return ret; } 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'}), ''); });