{"id":15690808,"url":"https://github.com/bubkoo/ansi.js","last_synced_at":"2025-07-13T18:33:50.995Z","repository":{"id":57180464,"uuid":"53048586","full_name":"bubkoo/ansi.js","owner":"bubkoo","description":"ansi escape sequences for terminal cursor positioning and coloring.","archived":false,"fork":false,"pushed_at":"2024-01-01T03:11:45.000Z","size":568,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-03T18:10:58.202Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bubkoo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-03T12:28:40.000Z","updated_at":"2024-06-15T12:48:06.000Z","dependencies_parsed_at":"2024-06-19T00:21:33.573Z","dependency_job_id":"4c9bc218-781f-453a-80b1-eae94aa88289","html_url":"https://github.com/bubkoo/ansi.js","commit_stats":{"total_commits":35,"total_committers":4,"mean_commits":8.75,"dds":"0.22857142857142854","last_synced_commit":"37aab6deb34d5ca30b0674c5830d7d73b9b67d2c"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bubkoo/ansi.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fansi.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fansi.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fansi.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fansi.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bubkoo","download_url":"https://codeload.github.com/bubkoo/ansi.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Fansi.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265186775,"owners_count":23724734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T18:16:26.629Z","updated_at":"2025-07-13T18:33:50.972Z","avatar_url":"https://github.com/bubkoo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eansi.js\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\u003cstrong\u003eansi escape sequences for terminal cursor positioning and coloring.\u003c/strong\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square\" alt=\"MIT License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.typescriptlang.org\"\u003e\u003cimg alt=\"Language\" src=\"https://img.shields.io/badge/language-TypeScript-blue.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/bubkoo/ansi.js/pulls\"\u003e\u003cimg alt=\"PRs Welcome\" src=\"https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`ansi.js` provides many easy-to-use methods for writing ANSI escape codes to `Stream` instances. ANSI escape codes are used to do fancy things in a terminal window, such as, positioning the cursor, coloring the text, erasing characters, lines or even the entire window, or hide and show the cursor, and many others.\n\n\n## Install\n\n```\n$ npm install ansi.js --save\n```\n\n\n## Usage\n\n```js\n\nconst ansi   = require('ansi.js');\nconst cursor = ansi(process.stdout);\n\n// You can chain your calls forever:\ncursor\n  .red()                 // set font color to red\n  .bg.grey()             // set background color to grey\n  .write('Hello World!') // write 'Hello World!' to stdout\n  .bg.reset().end()      // reset the bgcolor before writing the trailing \\n,\n                         // `end()` for chain calling.\n  .write('\\n');          // add a final \\n to wrap things up avoiding Terminal glitches\n\n// Rendering modes are persistent:\ncursor\n  .hex('#660000')\n  .bold()\n  .underline();\n\n// You can use the regular logging functions, text will be green:\nconsole.log('This is blood red, bold text.');\n\n// To reset just the foreground color:\ncursor.fg.reset();\n\nconsole.log('This will still be bold.');\n\n// move the cursor to an absolute location (x,y)\n// note: 1-indexed, not 0-indexed:\ncursor\n  .moveTo(10, 5)\n  .write('Five down, ten over.');\n\n// to clear the current line:\ncursor\n  .moveToColumn(0)\n  .eraseLine()\n  .write('Starting again');\n\n// to go to a different column on the current line:\ncursor\n  .moveToColumn(5)\n  .write('column five');\n\n// clean up\ncursor.reset();\n\n```\n\n\n## Constructor\n\n```js\nconst ansi   = require('ansi.js');\nconst cursor = ansi(stream, options);\n```\n\n### stream\n\nAny `Stream` instance, for terminal it would be `process.stdout`.\n\n\n### options\n- `enabled` - When `enabled` is `false` then all the methods are no-ops except for `forceWrite()`. Default `true`.\n- `buffering` - When `buffering` is true, then `write()` calls are buffered in memory until `flush()` is invoked. Default `false`.\n- `lineTrack` - Keep track of the number of `lineCount` that get encountered. Default `false`.\n\n\n## Properties\n\n- `stream` - The `Stream` instance.\n- `enabled` - Passed by `options`, when `enabled` is `false` then all the methods are no-ops except for `forceWrite()`.\n- `buffering` - Passed by `options`, when `buffering` is `true`, then `write()` calls are buffered in memory until `flush()` is invoked.\n- `lineCount` - The number of new line that get encountered when `options.lineTrack` is `true`.\n- `foreground` - Instance of `Color`, provides many useful methods for setting foreground color.\n  ```js\n  cursor\n    .blue()\n    .write('This is blue.')\n    .green()\n    .write('this is green.');\n\n  // same with the `foreground` property\n  cursor\n    .foreground.blue().end()\n    .write('This is blue.')\n    .foreground.green().end()\n    .write('this is green.');\n  ```\n- `background` - Instance of `Color`, provides many useful methods for setting background color. \nThis property has all the same methods of `foreground`, but these methods are not be \nattached on `Curosr` instance, you can use it like this:\n  ```js\n  cursor\n    .background.blue().end()\n    .write('This background is blue.')\n    .background.green().end()\n    .write('this background is green.');\n  ```\n- `font` - Instance of `Font`, for setting font styles with these methods:\n  - bold()\n  - italic()\n  - underline()\n  - inverse()\n  - resetBold()\n  - resetItalic()\n  - resetUnderline()\n  - resetInverse()\n  - end()\n\n  And these methods are attached on `Curosr` instance:\n\n  ```is\n  cursor\n    .font.bold().italic().end()\n    .write('This will be bold and italic.')\n    .resetItalic()\n    .underline()\n    .write('This will be bold and underline.');\n  ```\n\n\n- `display` - Instance of `Display`, setting the display mode with the these methods:\n  - dim()\n  - blink()\n  - hidden()\n  - bright()\n  - reverse()\n  - underscore()\n  - reset()\n\n## Methods\n\n\n- `enable()` \u0026 `disable()` - Update the `cursor.enabled`, When `cursor.enabled` is false then all the methods are no-ops except for `forceWrite()`.\n- `write(data)` - Helper method that calls `forceWrite()` when `enabled` is `true`.\n- `buffer()` - Set `cursor.buffering` truly, when `cursor.buffering` is `true`, then `write()` calls are buffered in memory until `flush()` is invoked.\n- `flush()` - Write out the in-memory buffer, then set `cursor.buffering` falsely.\n- `move(x, y)` - Move the cursor position by the relative coordinates `x`, `y`.\n- `moveTo(x, y)` - Set the cursor position to the absolute coordinates `x`, `y`.\n- `moveUp(count)` - Move the cursor up by `count` (default `1`) rows.\n- `moveDown(count)` - Move the cursor down by `count` (default `1`) rows.\n- `backward(count)` - Move the cursor backward by `count` (default `1`) columns.\n- `forward(count)` - Move the cursor forward by `count` (default `1`) columns.\n- `nextLine(n)` - Move cursor to beginning of the line `n` (default `1`) lines down.\n- `prevLine(n)` - Move cursor to beginning of the line `n` (default `1`) lines up.\n- `moveToColumn(n)` - Moves the cursor to column `n` (default `1`).\n- `scrollUp(n)` - Scroll whole page up by `n` (default `1`) lines. New lines are added at the bottom.\n- `scrollDown()` - Scroll whole page down by `n` (default `1`) lines. New lines are added at the top.\n- `erase(type)` - Clear part of the screen or line defined by the string `type`:\n  - end - clear from the cursor to the end of the line\n  - start - clear from the cursor to the start of the line\n  - line - clear the current line\n  - down - clear everything below the current line\n  - up - clear everything above the current line\n  - screen - clear the entire screen\n- `eraseRight()` - Clear from cursor to the end of the line. Cursor position does not change.\n- `eraseLeft()` - Clear from cursor to the start of the line. Cursor position does not change.\n- `eraseLine()` - Clear the current line. Cursor position does not change.\n- `eraseUp()` - Clear from cursor to beginning of the screen.\n- `eraseDown()`- Clear from cursor to end of screen.\n- `eraseScreen()` - Clear entire screen. And moves cursor to upper left on DOS.\n- `delete(mode, n)` - Delete 'line' or 'char's. `delete` differs from `erase` because it does not write over the deleted characters with whitesapce, but instead removes the deleted space. `mode` can be `'line'` or `'char'`. `n` is the number of items to be deleted. And `n` must be a positive integer. **Node: the cursor position is not updated after deletion**.\n- `deleteLine(n)`\n- `deleteChar(n)`\n- `insert(mode, n)` - Insert space into the terminal. `insert` is the opposite of `delete`, and the arguments are the same.\n- `beep()` - Play a beeping sound.\n- `show()` \u0026 `hide()` - Show/Hide the cursor.\n- `save(withAttributes)` \u0026 `restore(withAttributes)` - Save/Restore the cursor position and optionally the attribute state.\n- `reset()` - Reset all terminal settings to default.\n\n\n### Attached methods of `foreground` property\n\nThese methods are used for setting the foreground color.\n\n- black()\n- red()\n- green()\n- yellow()\n- blue()\n- magenta()\n- cyan()\n- white()\n- grey()\n- brightBlack()\n- brightRed()\n- brightGreen()\n- brightYellow()\n- brightBlue()\n- brightMagenta()\n- brightCyan()\n- brightWhite()\n- rgb(r, g, b)\n- hex(color)\n\n\n### Attached methods of `font` property\n\nThese methods are used for setting the font style.\n\n- bold()\n- italic()\n- underline()\n- inverse()\n- resetBold()\n- resetItalic()\n- resetUnderline()\n- resetInverse()\n\n\n### Attached methods of `display` property\n\nThese methods are used for setting the display mode.\n\n- dim()\n- blink()\n- hidden()\n- bright()\n- reverse()\n- underscore()\n\n\n## Contributing\n\nPlease let us know how can we help. Do check out [issues](https://github.com/bubkoo/ansi.js/issues) for bug reports or suggestions first.\n\nTo become a contributor, please follow our [contributing guide](/CONTRIBUTING.md).\n\n\u003ca href=\"https://github.com/bubkoo/ansi.js/graphs/contributors\"\u003e\n  \u003cimg src=\"/CONTRIBUTORS.svg\" alt=\"Contributors\" width=\"740\" /\u003e\n\u003c/a\u003e\n\n\n## License\n\nThe scripts and documentation in this project are released under the [MIT License](LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Fansi.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbubkoo%2Fansi.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Fansi.js/lists"}