Full Code of sindresorhus/yocto-spinner for AI

main 966be5ddf0bd cached
14 files
38.0 KB
10.5k tokens
37 symbols
1 requests
Download .txt
Repository: sindresorhus/yocto-spinner
Branch: main
Commit: 966be5ddf0bd
Files: 14
Total size: 38.0 KB

Directory structure:
gitextract_9wpuxrq1/

├── .editorconfig
├── .gitattributes
├── .github/
│   └── workflows/
│       └── main.yml
├── .gitignore
├── .npmrc
├── example-console-integration.js
├── example-non-interactive.js
├── example.js
├── index.d.ts
├── index.js
├── license
├── package.json
├── readme.md
└── test.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .editorconfig
================================================
root = 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


================================================
FILE: .gitattributes
================================================
* text=auto eol=lf


================================================
FILE: .github/workflows/main.yml
================================================
name: CI
on:
  - push
  - pull_request
jobs:
  test:
    name: Node.js ${{ matrix.node-version }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node-version:
          - 22
          - 20
          - 18
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm install
      - run: npm test


================================================
FILE: .gitignore
================================================
node_modules
yarn.lock


================================================
FILE: .npmrc
================================================
package-lock=false


================================================
FILE: example-console-integration.js
================================================
import {
	bold,
	dim,
	cyan,
	yellow,
	magenta,
	red,
	green,
	blue,
} from 'yoctocolors';
import yoctoSpinner from './index.js';

console.log(bold('\n🦄 Unicorn Console Integration Demo\n'));
console.log(dim('This example shows how yocto-spinner handles console.error/warn'));
console.log(dim('while the spinner is running. These write to stderr where the hook runs.\n'));

const collectUnicorns = yoctoSpinner({
	text: 'Searching for unicorns in the enchanted forest...',
	color: 'magenta',
}).start();

setTimeout(() => {
	console.error(cyan('✨ Found a baby unicorn near the crystal stream!'));
}, 500);

setTimeout(() => {
	console.error(yellow('✨ Spotted a golden unicorn on the rainbow bridge!'));
}, 1000);

setTimeout(() => {
	console.warn(yellow('⚠️  A wild unicorn is shy and hiding behind clouds'));
}, 1500);

setTimeout(() => {
	console.log(blue('🧭 Tracking hoofprints deeper into the meadow'));
}, 1800);

setTimeout(() => {
	console.error(magenta('✨ Discovered a unicorn herd in the meadow!'));
}, 2100);

setTimeout(() => {
	console.error(red('❌ Dark forest area is too dangerous to explore'));
}, 2600);

setTimeout(() => {
	collectUnicorns.success(green('Collected 3 magical unicorns! 🦄🦄🦄'));

	const processSpinner = yoctoSpinner({
		text: 'Processing unicorn magic...',
		color: 'cyan',
	}).start();

	setTimeout(() => {
		console.error(blue('🌟 Converting stardust to rainbow essence'));
	}, 500);

	setTimeout(() => {
		console.error(magenta('🌈 Brewing magical unicorn potion'));
	}, 1000);

	setTimeout(() => {
		console.error(yellow('✨ Enchanting unicorn horn fragments'));
	}, 1500);

	setTimeout(() => {
		processSpinner.success(green('Unicorn magic processed successfully!'));

		const deploySpinner = yoctoSpinner({
			text: 'Deploying unicorn powers to the world...',
			color: 'magenta',
		}).start();

		setTimeout(() => {
			console.error(magenta('💫 Spreading joy and sparkles'));
		}, 400);

		setTimeout(() => {
			console.error(blue('🎨 Painting rainbows across the sky'));
		}, 800);

		setTimeout(() => {
			console.error(yellow('⭐ Granting wishes to believers'));
		}, 1200);

		setTimeout(() => {
			deploySpinner.success(bold(green('🦄 Unicorn powers deployed! The world is more magical now! ✨')));

			console.log(dim('\n' + '─'.repeat(60)));
			console.log(bold('\n📊 Mission Summary:'));
			console.log('  • Unicorns collected: ' + bold('3'));
			console.log('  • Magic spells cast: ' + bold('6'));
			console.log('  • Rainbows created: ' + bold('∞'));
			console.log('  • World happiness: ' + bold(green('+1000%')));
			console.log(dim('\n' + '─'.repeat(60)));

			console.log(bold('\n✨ Notice how console.error/warn/log appeared cleanly above the spinner!'));
			console.log(dim('The spinner automatically clears, shows your message, then re-renders below.'));
			console.log(dim('Both console.log() and console.error/warn() work seamlessly while spinning!\n'));
		}, 1600);
	}, 2000);
}, 3000);


================================================
FILE: example-non-interactive.js
================================================
import process from 'node:process';
import yoctoSpinner from './index.js';

process.env.CI = 'true';

const spinner = yoctoSpinner({
	text: 'Attempt 1 failed. There are 100 retries left.',
}).start();

setTimeout(() => {
	spinner.text = 'Attempt 2 failed. There are 99 retries left.';
}, 1000);

setTimeout(() => {
	spinner.text = 'Attempt 3 failed. There are 98 retries left.';
}, 2000);

setTimeout(() => {
	spinner.success('Deploy completed successfully!');
}, 3000);


================================================
FILE: example.js
================================================
import yoctoSpinner from './index.js';

const spinner = yoctoSpinner({
	text: 'Loading unicorns\n  (And rainbows)',
}).start();

setTimeout(() => {
	spinner.text = 'Calculating splines';
}, 2000);

setTimeout(() => {
	spinner.success('Finished!');
}, 5000);


================================================
FILE: index.d.ts
================================================
import {type Writable} from 'node:stream';

export type SpinnerStyle = {
	readonly interval?: number;
	readonly frames: string[];
};

export type Color =
	| 'black'
	| 'red'
	| 'green'
	| 'yellow'
	| 'blue'
	| 'magenta'
	| 'cyan'
	| 'white'
	| 'gray';

export type Options = {
	/**
	Text to display next to the spinner.

	@default ''
	*/
	readonly text?: string;

	/**
	Customize the spinner animation with a custom set of frames and interval.

	```
	{
		frames: ['-', '\\', '|', '/'],
		interval: 100,
	}
	```

	Pass in any spinner from [`cli-spinners`](https://github.com/sindresorhus/cli-spinners).
	*/
	readonly spinner?: SpinnerStyle;

	/**
	The color of the spinner.

	@default 'cyan'
	*/
	readonly color?: Color;

	/**
	The stream to which the spinner is written.

	@default process.stderr
	*/
	readonly stream?: Writable;
};

export type Spinner = {
	/**
	Change the text displayed next to the spinner.

	@example
	```
	spinner.text = 'New text';
	```
	*/
	text: string;

	/**
	Change the spinner color.
	*/
	color: Color;

	/**
	Starts the spinner.

	Optionally, updates the text.

	@param text - The text to display next to the spinner.
	@returns The spinner instance.
	*/
	start(text?: string): Spinner;

	/**
	Stops the spinner.

	Optionally displays a final message.

	@param finalText - The final text to display after stopping the spinner.
	@returns The spinner instance.
	*/
	stop(finalText?: string): Spinner;

	/**
	Stops the spinner and displays a success symbol with the message.

	@param text - The success message to display.
	@returns The spinner instance.
	*/
	success(text?: string): Spinner;

	/**
	Stops the spinner and displays an error symbol with the message.

	@param text - The error message to display.
	@returns The spinner instance.
	*/
	error(text?: string): Spinner;

	/**
	Stops the spinner and displays a warning symbol with the message.

	@param text - The warning message to display.
	@returns The spinner instance.
	*/
	warning(text?: string): Spinner;

	/**
	Stops the spinner and displays an info symbol with the message.

	@param text - The info message to display.
	@returns The spinner instance.
	*/
	info(text?: string): Spinner;

	/**
	Clears the spinner.

	@returns The spinner instance.
	*/
	clear(): Spinner;

	/**
	Returns whether the spinner is currently spinning.
	*/
	get isSpinning(): boolean;
};

/**
Creates a new spinner instance.

@returns A new spinner instance.

@example
```
import yoctoSpinner from 'yocto-spinner';

const spinner = yoctoSpinner({text: 'Loading…'}).start();

setTimeout(() => {
	spinner.success('Success!');
}, 2000);
```
*/
export default function yoctoSpinner(options?: Options): Spinner;


================================================
FILE: index.js
================================================
import process from 'node:process';
import {stripVTControlCharacters} from 'node:util';
import yoctocolors from 'yoctocolors';

const isUnicodeSupported = process.platform !== 'win32'
	|| Boolean(process.env.WT_SESSION) // Windows Terminal
	|| process.env.TERM_PROGRAM === 'vscode';

const isInteractive = stream => Boolean(
	stream.isTTY
	&& process.env.TERM !== 'dumb'
	&& !('CI' in process.env),
);

const infoSymbol = yoctocolors.blue(isUnicodeSupported ? 'ℹ' : 'i');
const successSymbol = yoctocolors.green(isUnicodeSupported ? '✔' : '√');
const warningSymbol = yoctocolors.yellow(isUnicodeSupported ? '⚠' : '‼');
const errorSymbol = yoctocolors.red(isUnicodeSupported ? '✖' : '×');

const defaultSpinner = {
	frames: isUnicodeSupported
		? [
			'⠋',
			'⠙',
			'⠹',
			'⠸',
			'⠼',
			'⠴',
			'⠦',
			'⠧',
			'⠇',
			'⠏',
		]
		: [
			'-',
			'\\',
			'|',
			'/',
		],
	interval: 80,
};

const SYNCHRONIZED_OUTPUT_ENABLE = '\u001B[?2026h';
const SYNCHRONIZED_OUTPUT_DISABLE = '\u001B[?2026l';

const activeHooksPerStream = new Set();

class YoctoSpinner {
	#frames;
	#interval;
	#currentFrame = -1;
	#timer;
	#text;
	#stream;
	#color;
	#lines = 0;
	#exitHandlerBound;
	#isInteractive;
	#lastSpinnerFrameTime = 0;
	#isSpinning = false;
	#hookedStreams = new Map();
	#isInternalWrite = false;
	#isDeferringRender = false;

	constructor(options = {}) {
		const spinner = options.spinner ?? defaultSpinner;

		if (!Array.isArray(spinner.frames) || spinner.frames.length === 0 || spinner.frames.some(frame => typeof frame !== 'string')) {
			throw new Error('The `spinner.frames` option must be a non-empty array of strings');
		}

		if (spinner.interval !== undefined && !(Number.isInteger(spinner.interval) && spinner.interval > 0)) {
			throw new Error('The `spinner.interval` option must be a positive integer');
		}

		this.#frames = spinner.frames;
		this.#interval = spinner.interval ?? defaultSpinner.interval;
		this.#text = options.text ?? '';
		this.#stream = options.stream ?? process.stderr;
		this.#color = options.color ?? 'cyan';
		this.#isInteractive = isInteractive(this.#stream);
		this.#exitHandlerBound = this.#exitHandler.bind(this);
	}

	#internalWrite(action) {
		this.#isInternalWrite = true;
		try {
			return action();
		} finally {
			this.#isInternalWrite = false;
		}
	}

	#stringifyChunk(chunk, encoding) {
		if (chunk === undefined || chunk === null) {
			return '';
		}

		if (typeof chunk === 'string') {
			return chunk;
		}

		if (Buffer.isBuffer(chunk) || ArrayBuffer.isView(chunk)) {
			const normalizedEncoding = typeof encoding === 'string' && encoding !== '' && encoding !== 'buffer' ? encoding : 'utf8';
			return Buffer.from(chunk).toString(normalizedEncoding);
		}

		return String(chunk);
	}

	#withSynchronizedOutput(action) {
		if (!this.#isInteractive) {
			return action();
		}

		try {
			this.#write(SYNCHRONIZED_OUTPUT_ENABLE);
			return action();
		} finally {
			this.#write(SYNCHRONIZED_OUTPUT_DISABLE);
		}
	}

	#hookStream(stream) {
		if (!stream || this.#hookedStreams.has(stream) || typeof stream.write !== 'function') {
			return;
		}

		if (activeHooksPerStream.has(stream)) {
			return;
		}

		const originalWrite = stream.write;
		const hookedWrite = (...writeArguments) => this.#hookedWrite(stream, originalWrite, writeArguments);
		this.#hookedStreams.set(stream, {originalWrite, hookedWrite});
		activeHooksPerStream.add(stream);
		stream.write = hookedWrite;
	}

	#installHook() {
		if (!this.#isInteractive || this.#hookedStreams.size > 0) {
			return;
		}

		const streamsToHook = new Set([this.#stream]);

		if (this.#stream === process.stdout || this.#stream === process.stderr) {
			if (isInteractive(process.stdout)) {
				streamsToHook.add(process.stdout);
			}

			if (isInteractive(process.stderr)) {
				streamsToHook.add(process.stderr);
			}
		}

		for (const stream of streamsToHook) {
			this.#hookStream(stream);
		}
	}

	#uninstallHook() {
		for (const [stream, hookInfo] of this.#hookedStreams) {
			if (stream.write === hookInfo.hookedWrite) {
				stream.write = hookInfo.originalWrite;
			}

			activeHooksPerStream.delete(stream);
		}

		this.#hookedStreams.clear();
	}

	#hookedWrite(stream, originalWrite, writeArguments) {
		const [chunk, encoding, callback] = writeArguments;
		let resolvedEncoding = encoding;
		let resolvedCallback = callback;

		if (typeof resolvedEncoding === 'function') {
			resolvedCallback = resolvedEncoding;
			resolvedEncoding = undefined;
		}

		if (this.#isInternalWrite || !this.isSpinning) {
			return originalWrite.call(stream, chunk, resolvedEncoding, resolvedCallback);
		}

		if (this.#lines > 0) {
			this.clear();
		}

		const chunkString = this.#stringifyChunk(chunk, resolvedEncoding);
		const chunkTerminatesLine = chunkString.at(-1) === '\n';
		const writeResult = originalWrite.call(stream, chunk, resolvedEncoding, resolvedCallback);

		if (chunkTerminatesLine) {
			this.#isDeferringRender = false;
		} else if (chunkString !== '') {
			this.#isDeferringRender = true;
		}

		if (this.isSpinning && !this.#isDeferringRender) {
			this.#render();
		}

		return writeResult;
	}

	start(text) {
		if (text) {
			this.#text = text;
		}

		if (this.isSpinning) {
			return this;
		}

		this.#isSpinning = true;
		this.#hideCursor();
		this.#installHook();
		this.#render();
		this.#subscribeToProcessEvents();

		// Only start the timer in interactive mode
		if (this.#isInteractive) {
			this.#timer = setInterval(() => {
				this.#render();
			}, this.#interval);
		}

		return this;
	}

	stop(finalText) {
		if (!this.isSpinning) {
			return this;
		}

		const shouldWriteNewline = this.#isDeferringRender;
		this.#isSpinning = false;
		if (this.#timer) {
			clearInterval(this.#timer);
			this.#timer = undefined;
		}

		this.#isDeferringRender = false;
		this.#uninstallHook();
		this.#showCursor();
		this.clear();
		this.#unsubscribeFromProcessEvents();

		if (finalText) {
			const prefix = shouldWriteNewline ? '\n' : '';
			this.#stream.write(`${prefix}${finalText}\n`);
		}

		return this;
	}

	#symbolStop(symbol, text) {
		return this.stop(`${symbol} ${text ?? this.#text}`);
	}

	success(text) {
		return this.#symbolStop(successSymbol, text);
	}

	error(text) {
		return this.#symbolStop(errorSymbol, text);
	}

	warning(text) {
		return this.#symbolStop(warningSymbol, text);
	}

	info(text) {
		return this.#symbolStop(infoSymbol, text);
	}

	get isSpinning() {
		return this.#isSpinning;
	}

	get text() {
		return this.#text;
	}

	set text(value) {
		this.#text = value ?? '';
		this.#render();
	}

	get color() {
		return this.#color;
	}

	set color(value) {
		this.#color = value;
		this.#render();
	}

	clear() {
		if (!this.#isInteractive) {
			return this;
		}

		if (this.#lines === 0) {
			return this;
		}

		this.#internalWrite(() => {
			this.#stream.cursorTo(0);

			for (let index = 0; index < this.#lines; index++) {
				if (index > 0) {
					this.#stream.moveCursor(0, -1);
				}

				this.#stream.clearLine(1);
			}
		});

		this.#lines = 0;

		return this;
	}

	#render() {
		if (this.#isDeferringRender) {
			return;
		}

		const useSynchronizedOutput = this.#isInteractive;
		// Ensure we only update the spinner frame at the wanted interval,
		// even if the frame method is called more often.
		const now = Date.now();
		if (this.#currentFrame === -1 || now - this.#lastSpinnerFrameTime >= this.#interval) {
			this.#currentFrame = ++this.#currentFrame % this.#frames.length;
			this.#lastSpinnerFrameTime = now;
		}

		const applyColor = yoctocolors[this.#color] ?? yoctocolors.cyan;
		const frame = this.#frames[this.#currentFrame];
		let string = `${applyColor(frame)} ${this.#text}`;

		if (!this.#isInteractive) {
			string += '\n';
		}

		if (useSynchronizedOutput) {
			this.#withSynchronizedOutput(() => {
				this.clear();
				this.#write(string);
			});
		} else {
			this.#write(string);
		}

		if (this.#isInteractive) {
			this.#lines = this.#lineCount(string);
		}
	}

	#write(text) {
		this.#internalWrite(() => {
			this.#stream.write(text);
		});
	}

	#lineCount(text) {
		const width = this.#stream.columns ?? 80;
		const lines = stripVTControlCharacters(text).split('\n');

		let lineCount = 0;
		for (const line of lines) {
			lineCount += Math.max(1, Math.ceil(line.length / width));
		}

		return lineCount;
	}

	#hideCursor() {
		if (this.#isInteractive) {
			this.#write('\u001B[?25l');
		}
	}

	#showCursor() {
		if (this.#isInteractive) {
			this.#write('\u001B[?25h');
		}
	}

	#subscribeToProcessEvents() {
		process.once('SIGINT', this.#exitHandlerBound);
		process.once('SIGTERM', this.#exitHandlerBound);
	}

	#unsubscribeFromProcessEvents() {
		process.off('SIGINT', this.#exitHandlerBound);
		process.off('SIGTERM', this.#exitHandlerBound);
	}

	#exitHandler(signal) {
		if (this.isSpinning) {
			this.stop();
		}

		// SIGINT: 128 + 2
		// SIGTERM: 128 + 15
		const exitCode = signal === 'SIGINT' ? 130 : (signal === 'SIGTERM' ? 143 : 1);
		process.exit(exitCode);
	}
}

export default function yoctoSpinner(options) {
	return new YoctoSpinner(options);
}


================================================
FILE: license
================================================
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://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.


================================================
FILE: package.json
================================================
{
	"name": "yocto-spinner",
	"version": "1.1.0",
	"description": "Tiny terminal spinner",
	"license": "MIT",
	"repository": "sindresorhus/yocto-spinner",
	"funding": "https://github.com/sponsors/sindresorhus",
	"author": {
		"name": "Sindre Sorhus",
		"email": "sindresorhus@gmail.com",
		"url": "https://sindresorhus.com"
	},
	"type": "module",
	"exports": {
		"types": "./index.d.ts",
		"default": "./index.js"
	},
	"sideEffects": false,
	"engines": {
		"node": ">=18.19"
	},
	"scripts": {
		"test": "xo && ava && tsc index.d.ts"
	},
	"files": [
		"index.js",
		"index.d.ts"
	],
	"keywords": [
		"cli",
		"spinner",
		"spinners",
		"terminal",
		"term",
		"console",
		"ascii",
		"unicode",
		"loading",
		"indicator",
		"progress",
		"busy",
		"wait",
		"idle",
		"tiny",
		"yocto",
		"micro",
		"nano"
	],
	"dependencies": {
		"yoctocolors": "^2.1.1"
	},
	"devDependencies": {
		"ava": "^6.1.3",
		"get-stream": "^9.0.1",
		"strip-ansi": "^7.1.2",
		"typescript": "^5.5.4",
		"xo": "^0.59.3"
	},
	"xo": {
		"rules": {
			"unicorn/no-process-exit": "off"
		}
	}
}


================================================
FILE: readme.md
================================================
<h1 align="center" title="yocto-spinner">
	<img src="media/logo.jpg" alt="yocto-spinner logo">
</h1>

[![Install size](https://packagephobia.com/badge?p=yocto-spinner)](https://packagephobia.com/result?p=yocto-spinner)
![npm package minzipped size](https://img.shields.io/bundlejs/size/yocto-spinner)
<!-- [![Downloads](https://img.shields.io/npm/dm/yocto-spinner.svg)](https://npmjs.com/yocto-spinner) -->
<!-- ![Dependents](https://img.shields.io/librariesio/dependents/npm/yocto-spinner) -->

> Tiny terminal spinner

## Features

- Tiny and fast
- Customizable text and color options
- Customizable spinner animations
- Only one tiny dependency
- Supports both Unicode and non-Unicode environments
- Gracefully handles process signals (e.g., `SIGINT`, `SIGTERM`)
- Can display different status symbols (info, success, warning, error)
- Works well in CI environments

*Check out [`ora`](https://github.com/sindresorhus/ora) for more features.*

<br>
<p align="center">
	<br>
	<img src="https://raw.githubusercontent.com/sindresorhus/ora/3c63d5e8569d94564b5280525350724817e9ac26/screenshot.svg" width="500">
	<br>
</p>
<br>

## Install

```sh
npm install yocto-spinner
```

## Usage

```js
import yoctoSpinner from 'yocto-spinner';

const spinner = yoctoSpinner({text: 'Loading…'}).start();

setTimeout(() => {
	spinner.success('Success!');
}, 2000);
```

## API

### yoctoSpinner(options?)

Creates a new spinner instance.

#### options

Type: `object`

##### text

Type: `string`\
Default: `''`

The text to display next to the spinner.

##### spinner

Type: `object`\
Default: <img src="https://github.com/sindresorhus/ora/blob/main/screenshot-spinner.gif?raw=true" width="14">

Customize the spinner animation with a custom set of frames and interval.

```js
{
	frames: ['-', '\\', '|', '/'],
	interval: 100,
}
```

Pass in any spinner from [`cli-spinners`](https://github.com/sindresorhus/cli-spinners).

##### color

Type: `string`\
Default: `'cyan'`\
Values: `'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray'`

The color of the spinner.

##### stream

Type: `stream.Writable`\
Default: `process.stderr`

The stream to which the spinner is written.

### Instance methods

#### .start(text?)

Starts the spinner.

Returns the instance.

Optionally, updates the text:

```js
spinner.start('Loading…');
```

#### .stop(finalText?)

Stops the spinner.

Returns the instance.

Optionally displays a final message.

```js
spinner.stop('Stopped.');
```

#### .success(text?)

Stops the spinner and displays a success symbol with the message.

Returns the instance.

```js
spinner.success('Success!');
```

#### .error(text?)

Stops the spinner and displays an error symbol with the message.

Returns the instance.

```js
spinner.error('Error!');
```

#### .warning(text?)

Stops the spinner and displays a warning symbol with the message.

Returns the instance.

```js
spinner.warning('Warning!');
```

#### .clear()

Clears the spinner.

Returns the instance.

#### .info(text?)

Stops the spinner and displays an info symbol with the message.

Returns the instance.

```js
spinner.info('Info.');
```

#### .text <sup>get/set</sup>

Change the text displayed next to the spinner.

```js
spinner.text = 'New text';
```

#### .color <sup>get/set</sup>

Change the spinner color.

#### .isSpinning <sup>get</sup>

Returns whether the spinner is currently spinning.

## FAQ

### How do I change the color of the text?

Use [`yoctocolors`](https://github.com/sindresorhus/yoctocolors):

```js
import yoctoSpinner from 'yocto-spinner';
import {red} from 'yoctocolors';

const spinner = yoctoSpinner({text: `Loading ${red('unicorns')}`}).start();
```

### Can I log messages while the spinner is running?

Yes. The spinner clears itself, writes your message, and re-renders below. This works with `console.log()` and `console.error()` while the spinner is running:

```js
const spinner = yoctoSpinner({text: 'Processing…'}).start();

console.log('Step 1 complete');
console.error('Step 2 complete');

spinner.success('Done!');
```

> [!NOTE]
> Avoid running multiple spinners concurrently.

### Why does the spinner freeze?

JavaScript is single-threaded, so any synchronous operations will block the spinner's animation. To avoid this, prefer using asynchronous operations.

## Comparison with [`ora`](https://github.com/sindresorhus/ora)

Ora offers more options, greater customizability, [promise handling](https://github.com/sindresorhus/ora?tab=readme-ov-file#orapromiseaction-options), and better Unicode detection. It’s a more mature and feature-rich package that handles more edge cases but comes with additional dependencies and a larger size. In contrast, this package is smaller, simpler, and optimized for minimal overhead, making it ideal for lightweight projects where dependency size is important. However, Ora is generally the better choice for most use cases.

## Related

- [ora](https://github.com/sindresorhus/ora) - Comprehensive terminal spinner
- [yoctocolors](https://github.com/sindresorhus/yoctocolors) - Tiny terminal coloring
- [nano-spawn](https://github.com/sindresorhus/nano-spawn) - Tiny process execution for humans


================================================
FILE: test.js
================================================
import {setTimeout as delay} from 'node:timers/promises';
import process from 'node:process';
import {PassThrough} from 'node:stream';
import getStream from 'get-stream';
import test from 'ava';
import stripAnsi from 'strip-ansi';
import yoctocolors from 'yoctocolors';
import yoctoSpinner from './index.js';

delete process.env.CI;

const synchronizedOutputEnable = '\u001B[?2026h';
const synchronizedOutputDisable = '\u001B[?2026l';

const getPassThroughStream = () => {
	const stream = new PassThrough();
	stream.clearLine = () => {};
	stream.cursorTo = () => {};
	stream.moveCursor = () => {};
	return stream;
};

const runSpinner = async (function_, options = {}, testOptions = {}) => {
	const stream = testOptions.stream ?? getPassThroughStream();
	// Set isTTY to false by default for tests to get predictable newline behavior
	if (stream.isTTY === undefined) {
		stream.isTTY = false;
	}

	const output = getStream(stream);

	const spinner = yoctoSpinner({
		stream,
		text: testOptions.text ?? 'foo',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
		...options,
	});

	spinner.start();
	function_(spinner);
	stream.end();

	return stripAnsi(await output);
};

test('start and stop spinner', async t => {
	const output = await runSpinner(spinner => spinner.stop());
	t.is(output, '- foo\n');
});

test('spinner.success()', async t => {
	const output = await runSpinner(spinner => spinner.success());
	t.regex(output, /✔ foo\n$/);
});

test('spinner.error()', async t => {
	const output = await runSpinner(spinner => spinner.error());
	t.regex(output, /✖ foo\n$/);
});

test('spinner.warning()', async t => {
	const output = await runSpinner(spinner => spinner.warning());
	t.regex(output, /⚠ foo\n$/);
});

test('spinner.info()', async t => {
	const output = await runSpinner(spinner => spinner.info());
	t.regex(output, /ℹ foo\n$/);
});

test('spinner changes text', async t => {
	const output = await runSpinner(spinner => {
		spinner.text = 'bar';
		spinner.stop();
	});
	t.is(output, '- foo\n- bar\n');
});

test('spinner stops with final text', async t => {
	const output = await runSpinner(spinner => spinner.stop('final'));
	t.regex(output, /final\n$/);
});

test('spinner with non-TTY stream', t => {
	const stream = getPassThroughStream();
	stream.isTTY = false;
	const spinner = yoctoSpinner({stream, text: 'foo'});

	spinner.start();
	spinner.stop('final');
	t.pass();
});

test('spinner does not hook non-interactive streams', t => {
	const stream = getPassThroughStream();
	stream.isTTY = false;

	const spinner = yoctoSpinner({stream, text: 'foo'});
	const originalWrite = stream.write;

	spinner.start();
	t.is(stream.write, originalWrite);
	spinner.stop();
	t.is(stream.write, originalWrite);
});

test('spinner starts with custom text', async t => {
	const output = await runSpinner(spinner => spinner.stop(), {text: 'custom'});
	t.is(output, '- custom\n');
});

test('spinner uses synchronized output in interactive mode', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const output = getStream(stream);

	const spinner = yoctoSpinner({
		stream,
		text: 'foo',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
	});

	spinner.start();
	spinner.stop();
	stream.end();

	const result = await output;
	t.true(result.includes(synchronizedOutputEnable));
	t.true(result.includes(synchronizedOutputDisable));
	t.true(result.indexOf(synchronizedOutputEnable) < result.indexOf(synchronizedOutputDisable));
});

test('spinner starts and changes text multiple times', async t => {
	const output = await runSpinner(spinner => {
		spinner.text = 'bar';
		spinner.text = 'baz';
		spinner.stop();
	});
	t.is(output, '- foo\n- bar\n- baz\n');
});

test('spinner handles multiple start/stop cycles', async t => {
	const output = await runSpinner(spinner => {
		spinner.stop();
		spinner.start('bar');
		spinner.stop();
		spinner.start('baz');
		spinner.stop();
	});
	t.is(output, '- foo\n- bar\n- baz\n');
});

test('spinner stops with success symbol and final text', async t => {
	const output = await runSpinner(spinner => spinner.success('done'));
	t.regex(output, /✔ done\n$/);
});

test('spinner stops with error symbol and final text', async t => {
	const output = await runSpinner(spinner => spinner.error('failed'));
	t.regex(output, /✖ failed\n$/);
});

test('spinner accounts for ANSI escape codes when computing line breaks', async t => {
	const scenarios = [
		// 1 symbol + 1 space + 78 chars = 80 chars, max for one line
		{
			textLength: 78,
			clearLineCount: 1,
		},

		// 1 symbol + 1 space + 79 chars = 81 chars, split on two lines
		{
			textLength: 79,
			clearLineCount: 2,
		},
	];

	for (const scenario of scenarios) {
		let clearLineCount = 0;

		const stream = new PassThrough();
		stream.clearLine = () => {
			clearLineCount += 1;
		};

		stream.cursorTo = () => {};
		stream.moveCursor = () => {};
		stream.isTTY = true;

		let text = '';
		for (let i = 0; i < scenario.textLength; i++) {
			text += yoctocolors.blue('a');
		}

		// eslint-disable-next-line no-await-in-loop
		await runSpinner(spinner => spinner.stop(), {}, {
			stream,
			text,
		});
		t.is(clearLineCount, scenario.clearLineCount);
	}
});

test('spinner in non-interactive mode only renders on text changes', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = false;

	const output = getStream(stream);

	const spinner = yoctoSpinner({
		stream,
		text: 'initial text',
		spinner: {
			frames: ['-'],
			interval: 10,
		},
	});

	spinner.start();

	// Wait to ensure no additional renders happen
	await delay(50);

	spinner.text = 'changed text';

	await delay(50);

	spinner.stop('final text');
	stream.end();

	const result = stripAnsi(await output);
	const lines = result.trim().split('\n');

	// Should only have 3 lines: initial, changed, and final
	t.is(lines.length, 3);
	t.is(lines[0], '- initial text');
	t.is(lines[1], '- changed text');
	t.is(lines[2], 'final text');
});

test('spinner keeps output below external writes while spinning', t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const cursorToCalls = [];
	const writeEvents = [];

	const originalWrite = stream.write;
	stream.write = function (content, encoding, callback) {
		writeEvents.push(stripAnsi(String(content)));
		return originalWrite.call(this, content, encoding, callback);
	};

	stream.cursorTo = () => {
		cursorToCalls.push('cursorTo');
	};

	const spinner = yoctoSpinner({
		stream,
		text: 'spinning',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
	});

	spinner.start();

	const cursorToCountAfterStart = cursorToCalls.length;

	stream.write('External log\n');

	spinner.stop('done');
	stream.end();

	t.true(cursorToCalls.length > cursorToCountAfterStart, 'external write should clear the spinner before output');

	const externalWriteIndex = writeEvents.findIndex(event => event.includes('External log'));
	t.true(externalWriteIndex !== -1);

	const reRenderIndex = writeEvents.findIndex((event, index) => index > externalWriteIndex && event.includes('spinning'));
	t.true(reRenderIndex !== -1, 'spinner should re-render after external write');
});

test('external writes preserve chunk boundaries without injected newlines', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;
	const outputPromise = getStream(stream);

	const spinner = yoctoSpinner({
		stream,
		text: 'processing',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
	});

	spinner.start();

	stream.write('Downloading ');
	stream.write('42%');
	stream.write('\n');

	spinner.stop();
	stream.end();

	const output = stripAnsi(await outputPromise).replaceAll('\r', '');
	t.true(output.includes('Downloading 42%\n'));
	t.false(output.includes('Downloading \n42%'));
});

test('spinner defers renders until a newline completes the external line', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const writeEvents = [];

	const originalWrite = stream.write;
	stream.write = function (content, encoding, callback) {
		writeEvents.push(stripAnsi(String(content)));
		return originalWrite.call(this, content, encoding, callback);
	};

	const spinner = yoctoSpinner({
		stream,
		text: 'waiting',
		spinner: {
			frames: ['-'],
			interval: 20,
		},
	});

	spinner.start();
	const baselineWrites = writeEvents.length;

	stream.write('Partial without newline');
	await delay(80);

	t.is(writeEvents.length, baselineWrites + 1, 'spinner should not render while line is incomplete');

	stream.write('\n');
	await delay(40);

	t.true(writeEvents.length > baselineWrites + 1, 'spinner should render after newline');

	spinner.stop();
	stream.end();
});

test('spinner defers renders on carriage return updates', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const writeEvents = [];

	const originalWrite = stream.write;
	stream.write = function (content, encoding, callback) {
		writeEvents.push(stripAnsi(String(content)));
		return originalWrite.call(this, content, encoding, callback);
	};

	const spinner = yoctoSpinner({
		stream,
		text: 'waiting',
		spinner: {
			frames: ['-'],
			interval: 20,
		},
	});

	spinner.start();
	const baselineWrites = writeEvents.length;

	stream.write('\rProgress 1');
	await delay(80);

	t.is(writeEvents.length, baselineWrites + 1, 'spinner should not render while carriage return updates are in progress');

	stream.write('\n');
	await delay(40);

	t.true(writeEvents.length > baselineWrites + 1, 'spinner should render after newline');

	spinner.stop();
	stream.end();
});

test('spinner resumes after carriage return newline', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const writeEvents = [];

	const originalWrite = stream.write;
	stream.write = function (content, encoding, callback) {
		writeEvents.push(stripAnsi(String(content)));
		return originalWrite.call(this, content, encoding, callback);
	};

	const spinner = yoctoSpinner({
		stream,
		text: 'waiting',
		spinner: {
			frames: ['-'],
			interval: 20,
		},
	});

	spinner.start();
	const baselineWrites = writeEvents.length;

	stream.write('\rProgress 1\r\n');
	await delay(80);

	t.true(writeEvents.length > baselineWrites + 1, 'spinner should render after carriage return newline');

	spinner.stop();
	stream.end();
});

test('spinner defers when chunk ends with an incomplete line', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const writeEvents = [];

	const originalWrite = stream.write;
	stream.write = function (content, encoding, callback) {
		writeEvents.push(stripAnsi(String(content)));
		return originalWrite.call(this, content, encoding, callback);
	};

	const spinner = yoctoSpinner({
		stream,
		text: 'waiting',
		spinner: {
			frames: ['-'],
			interval: 20,
		},
	});

	spinner.start();
	const baselineWrites = writeEvents.length;

	stream.write('Step 1\nProgress 50%');
	await delay(80);

	t.is(writeEvents.length, baselineWrites + 1, 'spinner should not render while last line is incomplete');

	stream.write('\n');
	await delay(40);

	t.true(writeEvents.length > baselineWrites + 1, 'spinner should render after newline');

	spinner.stop();
	stream.end();
});

test('spinner stop preserves partial external lines', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;
	const outputPromise = getStream(stream);

	const spinner = yoctoSpinner({
		stream,
		text: 'waiting',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
	});

	spinner.start();

	stream.write('Downloading ');

	spinner.stop('done');
	stream.end();

	const output = stripAnsi(await outputPromise).replaceAll('\r', '');

	t.true(output.includes('Downloading \n'));
	t.regex(output, /Downloading \n[\s\S]*done\n/);
	t.false(output.includes('Downloading done'));
});

test('spinner stop without final text preserves partial external lines', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;
	const outputPromise = getStream(stream);

	const spinner = yoctoSpinner({
		stream,
		text: 'waiting',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
	});

	spinner.start();

	stream.write('Downloading ');

	spinner.stop();
	stream.end();

	const output = stripAnsi(await outputPromise).replaceAll('\r', '');

	t.true(output.includes('Downloading '));
	t.false(output.includes('Downloading \n'));
});

test('spinner does not defer when stdout is non-interactive', async t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const stdoutStream = getPassThroughStream();
	stdoutStream.isTTY = false;

	const outputPromise = getStream(stream);

	const spinner = yoctoSpinner({
		stream,
		text: 'waiting',
		spinner: {
			frames: ['-'],
			interval: 20,
		},
	});

	const originalStdoutWrite = process.stdout.write;
	process.stdout.write = stdoutStream.write.bind(stdoutStream);

	try {
		spinner.start();
		stdoutStream.write('chunk without newline');
		await delay(80);

		spinner.stop('done');
		stream.end();

		const output = stripAnsi(await outputPromise);
		t.true(output.includes('done\n'));
	} finally {
		process.stdout.write = originalStdoutWrite;
	}
});

test('spinner preserves external stream.write wrappers on stop', t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const spinner = yoctoSpinner({
		stream,
		text: 'wrapper',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
	});

	spinner.start();

	const originalWrite = stream.write;
	const wrappedWrite = function (content, encoding, callback) {
		return originalWrite.call(this, content, encoding, callback);
	};

	stream.write = wrappedWrite;
	spinner.stop();

	t.is(stream.write, wrappedWrite);
	stream.end();
});

test('spinner.interval rejects negative values', t => {
	t.throws(() => {
		yoctoSpinner({spinner: {frames: ['-'], interval: -100}});
	}, {message: /positive integer/});
});

test('spinner.interval rejects non-integer values', t => {
	t.throws(() => {
		yoctoSpinner({spinner: {frames: ['-'], interval: 1.5}});
	}, {message: /positive integer/});
});

test('spinner.interval rejects zero', t => {
	t.throws(() => {
		yoctoSpinner({spinner: {frames: ['-'], interval: 0}});
	}, {message: /positive integer/});
});

test('spinner.frames rejects empty array', t => {
	t.throws(() => {
		yoctoSpinner({spinner: {frames: []}});
	}, {message: /non-empty array of strings/});
});

test('spinner.frames rejects non-array', t => {
	t.throws(() => {
		yoctoSpinner({spinner: {frames: 'not-an-array'}});
	}, {message: /non-empty array of strings/});
});

test('spinner.frames rejects non-string elements', t => {
	t.throws(() => {
		yoctoSpinner({spinner: {frames: [123, 456]}});
	}, {message: /non-empty array of strings/});
});

test('spinner.interval defaults to 80 when not provided', t => {
	const stream = getPassThroughStream();
	stream.isTTY = false;

	const spinner = yoctoSpinner({
		stream,
		spinner: {frames: ['a', 'b']},
	});

	spinner.start();
	spinner.stop();
	t.pass();
});

test('spinner preserves pre-existing stream.write wrappers', t => {
	const stream = getPassThroughStream();
	stream.isTTY = true;

	const originalWrite = stream.write;
	const wrappedWrite = function (content, encoding, callback) {
		return originalWrite.call(this, content, encoding, callback);
	};

	stream.write = wrappedWrite;

	const spinner = yoctoSpinner({
		stream,
		text: 'wrapper',
		spinner: {
			frames: ['-'],
			interval: 10_000,
		},
	});

	spinner.start();
	spinner.stop();

	t.is(stream.write, wrappedWrite);
	stream.end();
});
Download .txt
gitextract_9wpuxrq1/

├── .editorconfig
├── .gitattributes
├── .github/
│   └── workflows/
│       └── main.yml
├── .gitignore
├── .npmrc
├── example-console-integration.js
├── example-non-interactive.js
├── example.js
├── index.d.ts
├── index.js
├── license
├── package.json
├── readme.md
└── test.js
Download .txt
SYMBOL INDEX (37 symbols across 2 files)

FILE: index.d.ts
  type SpinnerStyle (line 3) | type SpinnerStyle = {
  type Color (line 8) | type Color =
  type Options (line 19) | type Options = {
  type Spinner (line 56) | type Spinner = {

FILE: index.js
  constant SYNCHRONIZED_OUTPUT_ENABLE (line 43) | const SYNCHRONIZED_OUTPUT_ENABLE = '\u001B[?2026h';
  constant SYNCHRONIZED_OUTPUT_DISABLE (line 44) | const SYNCHRONIZED_OUTPUT_DISABLE = '\u001B[?2026l';
  class YoctoSpinner (line 48) | class YoctoSpinner {
    method constructor (line 65) | constructor(options = {}) {
    method #internalWrite (line 85) | #internalWrite(action) {
    method #stringifyChunk (line 94) | #stringifyChunk(chunk, encoding) {
    method #withSynchronizedOutput (line 111) | #withSynchronizedOutput(action) {
    method #hookStream (line 124) | #hookStream(stream) {
    method #installHook (line 140) | #installHook() {
    method #uninstallHook (line 162) | #uninstallHook() {
    method #hookedWrite (line 174) | #hookedWrite(stream, originalWrite, writeArguments) {
    method start (line 209) | start(text) {
    method stop (line 234) | stop(finalText) {
    method #symbolStop (line 260) | #symbolStop(symbol, text) {
    method success (line 264) | success(text) {
    method error (line 268) | error(text) {
    method warning (line 272) | warning(text) {
    method info (line 276) | info(text) {
    method isSpinning (line 280) | get isSpinning() {
    method text (line 284) | get text() {
    method text (line 288) | set text(value) {
    method color (line 293) | get color() {
    method color (line 297) | set color(value) {
    method clear (line 302) | clear() {
    method #render (line 328) | #render() {
    method #write (line 364) | #write(text) {
    method #lineCount (line 370) | #lineCount(text) {
    method #hideCursor (line 382) | #hideCursor() {
    method #showCursor (line 388) | #showCursor() {
    method #subscribeToProcessEvents (line 394) | #subscribeToProcessEvents() {
    method #unsubscribeFromProcessEvents (line 399) | #unsubscribeFromProcessEvents() {
    method #exitHandler (line 404) | #exitHandler(signal) {
  function yoctoSpinner (line 416) | function yoctoSpinner(options) {
Condensed preview — 14 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (43K chars).
[
  {
    "path": ".editorconfig",
    "chars": 175,
    "preview": "root = true\n\n[*]\nindent_style = tab\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newlin"
  },
  {
    "path": ".gitattributes",
    "chars": 19,
    "preview": "* text=auto eol=lf\n"
  },
  {
    "path": ".github/workflows/main.yml",
    "chars": 436,
    "preview": "name: CI\non:\n  - push\n  - pull_request\njobs:\n  test:\n    name: Node.js ${{ matrix.node-version }}\n    runs-on: ubuntu-la"
  },
  {
    "path": ".gitignore",
    "chars": 23,
    "preview": "node_modules\nyarn.lock\n"
  },
  {
    "path": ".npmrc",
    "chars": 19,
    "preview": "package-lock=false\n"
  },
  {
    "path": "example-console-integration.js",
    "chars": 2936,
    "preview": "import {\n\tbold,\n\tdim,\n\tcyan,\n\tyellow,\n\tmagenta,\n\tred,\n\tgreen,\n\tblue,\n} from 'yoctocolors';\nimport yoctoSpinner from './i"
  },
  {
    "path": "example-non-interactive.js",
    "chars": 471,
    "preview": "import process from 'node:process';\nimport yoctoSpinner from './index.js';\n\nprocess.env.CI = 'true';\n\nconst spinner = yo"
  },
  {
    "path": "example.js",
    "chars": 258,
    "preview": "import yoctoSpinner from './index.js';\n\nconst spinner = yoctoSpinner({\n\ttext: 'Loading unicorns\\n  (And rainbows)',\n}).s"
  },
  {
    "path": "index.d.ts",
    "chars": 2673,
    "preview": "import {type Writable} from 'node:stream';\n\nexport type SpinnerStyle = {\n\treadonly interval?: number;\n\treadonly frames: "
  },
  {
    "path": "index.js",
    "chars": 9062,
    "preview": "import process from 'node:process';\nimport {stripVTControlCharacters} from 'node:util';\nimport yoctocolors from 'yoctoco"
  },
  {
    "path": "license",
    "chars": 1117,
    "preview": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby grant"
  },
  {
    "path": "package.json",
    "chars": 1067,
    "preview": "{\n\t\"name\": \"yocto-spinner\",\n\t\"version\": \"1.1.0\",\n\t\"description\": \"Tiny terminal spinner\",\n\t\"license\": \"MIT\",\n\t\"repositor"
  },
  {
    "path": "readme.md",
    "chars": 5181,
    "preview": "<h1 align=\"center\" title=\"yocto-spinner\">\n\t<img src=\"media/logo.jpg\" alt=\"yocto-spinner logo\">\n</h1>\n\n[![Install size](h"
  },
  {
    "path": "test.js",
    "chars": 15516,
    "preview": "import {setTimeout as delay} from 'node:timers/promises';\nimport process from 'node:process';\nimport {PassThrough} from "
  }
]

About this extraction

This page contains the full source code of the sindresorhus/yocto-spinner GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 14 files (38.0 KB), approximately 10.5k tokens, and a symbol index with 37 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!