{"_id":"ansi-state","_rev":"14-e61b2db29338aee5f05093c68ff0997e","name":"ansi-state","description":"Save and restore your ANSI states.","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.0":{"name":"ansi-state","version":"1.0.0","description":"Save and restore your ANSI states.","main":"main.js","scripts":{"test":"nodeunit test/test.js"},"repository":{"type":"git","url":"https://github.com/arjunmehta/node-ansi-state.git"},"keywords":["ansi","state","colours","colors","color","colour","styles","save","restore","update"],"author":{"name":"Arjun Mehta"},"license":"MIT","bugs":{"url":"https://github.com/arjunmehta/node-ansi-state/issues"},"homepage":"https://github.com/arjunmehta/node-ansi-state","devDependencies":{"nodeunit":"~0.9.0"},"gitHead":"b576f227f8492f809de81ec5ca345cac2767c3bc","_id":"ansi-state@1.0.0","_shasum":"e9ae40c569bdcac7ff44367a954cf170ea594a0b","_from":".","_npmVersion":"2.2.0","_nodeVersion":"1.0.3","_npmUser":{"name":"arjunmehta","email":"arjunmeht@gmail.com"},"maintainers":[{"name":"arjunmehta","email":"arjunmeht@gmail.com"}],"dist":{"shasum":"e9ae40c569bdcac7ff44367a954cf170ea594a0b","tarball":"https://registry.npmjs.org/ansi-state/-/ansi-state-1.0.0.tgz","integrity":"sha512-y4xcxsuVWI9svIwBfP8JOiXhOTsSYJiV4O2OiNS5kPNK4Wx4RCZgYsI5D1PAEAO3q1QA9EphCHrq7DRTKJcPuA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCdz1yNwJ/lP+dIDNb7ZRR/OcAgcX5wdWD7XIbNPLEX1QIgIeQTUuwJdp495+pKuKrBss9/VHAKoXVCHPgln8otsHQ="}]}},"1.0.1":{"name":"ansi-state","version":"1.0.1","description":"Save and restore your ANSI states.","main":"main.js","scripts":{"test":"nodeunit test/test.js"},"repository":{"type":"git","url":"https://github.com/arjunmehta/node-ansi-state.git"},"keywords":["ansi","state","colours","colors","color","colour","styles","save","restore","update"],"author":{"name":"Arjun Mehta"},"license":"MIT","bugs":{"url":"https://github.com/arjunmehta/node-ansi-state/issues"},"homepage":"https://github.com/arjunmehta/node-ansi-state","devDependencies":{"nodeunit":"~0.9.0"},"gitHead":"6ecd9742135de82eacb01f2699534afc7164d6ca","_id":"ansi-state@1.0.1","_shasum":"c5772deabadbe0dba6ad9a602a7b6ce4749cbee2","_from":".","_npmVersion":"2.2.0","_nodeVersion":"1.0.3","_npmUser":{"name":"arjunmehta","email":"arjunmeht@gmail.com"},"maintainers":[{"name":"arjunmehta","email":"arjunmeht@gmail.com"}],"dist":{"shasum":"c5772deabadbe0dba6ad9a602a7b6ce4749cbee2","tarball":"https://registry.npmjs.org/ansi-state/-/ansi-state-1.0.1.tgz","integrity":"sha512-d6BZBj4TvL5+qFELzRBxqYbwgPtfiCTrFXNnbWPKECT/FqoJzjq05mT1jQ5yoKLj22+oWOa+1cmbJ6WWtSx8OQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHDuOpXFrEDLCKMnDlW9Zm/gdO07Ch2gG2/8C8euOjqlAiBma2gIzQNDNPSIUggsmR+sffwSkv/XrzfJsLYoFMlILA=="}]}},"1.0.2":{"name":"ansi-state","version":"1.0.2","description":"Save and restore your ANSI states.","main":"main.js","scripts":{"test":"nodeunit test/test.js"},"repository":{"type":"git","url":"https://github.com/arjunmehta/node-ansi-state.git"},"keywords":["ansi","state","colours","colors","color","colour","styles","save","restore","update"],"author":{"name":"Arjun Mehta"},"license":"MIT","bugs":{"url":"https://github.com/arjunmehta/node-ansi-state/issues"},"homepage":"https://github.com/arjunmehta/node-ansi-state","devDependencies":{"nodeunit":"~0.9.0"},"gitHead":"4f18f8c96eb6d54dedf05d1504f34d420fe08bf0","_id":"ansi-state@1.0.2","_shasum":"9087fc21269929a9983b284fb2aa5ca4985b7f49","_from":".","_npmVersion":"2.2.0","_nodeVersion":"1.0.3","_npmUser":{"name":"arjunmehta","email":"arjunmeht@gmail.com"},"maintainers":[{"name":"arjunmehta","email":"arjunmeht@gmail.com"}],"dist":{"shasum":"9087fc21269929a9983b284fb2aa5ca4985b7f49","tarball":"https://registry.npmjs.org/ansi-state/-/ansi-state-1.0.2.tgz","integrity":"sha512-QjqYLXz74JpPvyh4gzH+jG50ezg1SAHkCAKaHZbQ1HR2KYqGk8NCQiruR9joDzZJKsYaI7z/WnwqQ5CGzv/R5Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGtsltgDg8nvdO61Vi8y8p4sjzIx2VrelZqp55Rxo2kgAiBttxiElKk8MJAFJazB9Fn+bdtKF5upsYsrVLTePNUjVA=="}]}},"1.0.3":{"name":"ansi-state","version":"1.0.3","description":"Save and restore your ANSI states.","main":"main.js","scripts":{"test":"nodeunit test/test.js"},"repository":{"type":"git","url":"https://github.com/arjunmehta/node-ansi-state.git"},"keywords":["ansi","state","colours","colors","color","colour","styles","save","restore","update"],"author":{"name":"Arjun Mehta"},"license":"MIT","bugs":{"url":"https://github.com/arjunmehta/node-ansi-state/issues"},"homepage":"https://github.com/arjunmehta/node-ansi-state","devDependencies":{"nodeunit":"~0.9.0"},"gitHead":"b4f37a46ddd103b8dc4e9220ea18f678d235ae49","_id":"ansi-state@1.0.3","_shasum":"ea93f5f120e34a5903ced95049c972d6ad93e25c","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.35","_npmUser":{"name":"arjunmehta","email":"arjunmeht@gmail.com"},"maintainers":[{"name":"arjunmehta","email":"arjunmeht@gmail.com"}],"dist":{"shasum":"ea93f5f120e34a5903ced95049c972d6ad93e25c","tarball":"https://registry.npmjs.org/ansi-state/-/ansi-state-1.0.3.tgz","integrity":"sha512-Rcwq3ZgA/ljBVwi09ft1qqN6MthZUlEqWCBttc3fSRAdBRfy1pTreoo8g4rsABP4Zoes93rXtHccYmZt7VK+rw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCiVxcU3w+CZe2gBYmr7DWq8/hiPQTRytsQJwDXNzRvAQIhAOyCHZH5lvVWK4VoyeMPpzB5/ab+ajrwY8vc2It6hcHx"}]}},"1.0.5":{"name":"ansi-state","version":"1.0.5","description":"Save and restore your ANSI states.","main":"main.js","scripts":{"test":"nodeunit test/test.js"},"repository":{"type":"git","url":"https://github.com/arjunmehta/node-ansi-state.git"},"keywords":["ansi","state","colours","colors","color","colour","styles","save","restore","update"],"author":{"name":"Arjun Mehta"},"license":"MIT","bugs":{"url":"https://github.com/arjunmehta/node-ansi-state/issues"},"homepage":"https://github.com/arjunmehta/node-ansi-state","devDependencies":{"nodeunit":"~0.9.0"},"gitHead":"995e95551c7f3010d5493d559ef3e0c03c6c62ac","_id":"ansi-state@1.0.5","_shasum":"0aeda248409664ac16b589121ac831cd6f721aa7","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.35","_npmUser":{"name":"arjunmehta","email":"arjunmeht@gmail.com"},"maintainers":[{"name":"arjunmehta","email":"arjunmeht@gmail.com"}],"dist":{"shasum":"0aeda248409664ac16b589121ac831cd6f721aa7","tarball":"https://registry.npmjs.org/ansi-state/-/ansi-state-1.0.5.tgz","integrity":"sha512-1V9E5FId8xlZfmFJqp6/L/hHITeaCmEZKzNz/OCLkmWWy8r9B9Mjh/ynYGaWEXFeP4lXfenESJUyTZeqASqS5w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAoS2hO7JozRemyJ7xwWSByjpbr0skCBPvSx56SQo37zAiEA1DgT6y2hVcmCYvL8Lp6ka7tkr4LblmtWAHUfWRod5zw="}]}}},"readme":"# node-ansi-state\n[![Build Status](https://travis-ci.org/arjunmehta/node-ansi-state.svg?branch=master)](https://travis-ci.org/arjunmehta/node-ansi-state)\n\nUse this module to capture the state of your ANSI colors and styles, and restore them at another time and/or place.\n\nSometimes you need to keep track of multiple ANSI style states, though you may not know what they are. This module provides:\n\n- **Full ANSI style code capturing, including: foreground & background colour (xterm colours too!), intensity, italic, underline, blink, polarity, conceal, strikethrough, font, framed and overlined styles.**\n- **The ability to check all the state style attributes listed above.`**\n- **A streamable interface (pipe or write to update).**\n- **The ability to create multiple instances to save multiple style states.**\n- **Restore any state instance at any time.**\n\n## Installation\n```bash\nnpm install --save ansi-state\n```\n\n## Basic Usage\n\n### Include\n\n```javascript\nvar ANSIState = require('ansi-state')\n```\n\n### Create a New State\nInstantiate a new state with the constructor:\n\n```javascript\nvar state = new ANSIState()\n```\n\n### Manually Save ANSI Style Codes\nYou can `update` the state manually by calling the corresponding method on it and passing in a string or array that contains ansi style codes. Only the most recently received codes for various attributes will be kept (ie. you can only have one foreground colour at a time). This module keeps track of all of that for you!\n\n```javascript\nstate.update('\\033[32mHi there! \\033[31mRed text')\n//current state becomes: \\033[31m\n\nstate.update('\\033[1mBolding the text too')\n//current state becomes: \\033[1;31m\n\nstate.update('\\033[34;38;5;211mxterm colors too!')\n//current state becomes: \\033[1;38;5;211m\n```\n\n### Automatically Save by Writing/Piping\nBecause states are streamable, they can be fixed in your pipeline or written to like any other writeable stream. This is handy if you want to automatically capture codes that are on their way to a particular stream (ie. stdout).\n\n```javascript\nstate.write('\\033[32mHi there! This is some \\033[31mred text')\n// current state becomes: \\033[31m\n\nstate.write('\\033')\nstate.write('[3')\nstate.write('7m')\n// current state becomes: \\033[37m\n\nstate.write('\\033[1mBolded \\033[2mFaint \\033[22mNormal Intensity')\n// current state becomes: \\033[22;37m\n```\n\nOr piping from and to other streams:\n```javascript\nsome_stream.pipe(state).pipe(process.stdout);\nsome_stream.write('\\033[33mHi there!')\n// current state becomes: \\033[33m\n```\n\n### Check State Attributes\nYou can check certain style attributes at any time, easily:\n```javascript\nvar state = new ANSIState('\\033[32mHi there! \\033[31mRed text, \\033[1;48;5;21m')\nconsole.log(state.foreground) // red\nconsole.log(state.background, state.xterm_background) // xterm color definition, [5, 21]\nconsole.log(state.intensity) // bold\nconsole.log(state.blink) // null\n```\n\n### The Current ANSI State Code\nYour `ANSIState` instance holds an efficient ansi style escape code for the current ansi state, accessible by its `code` property:\n\n```javascript\nvar state = new ANSIState('\\033[32mHi there! \\033[31mRed text, \\033[1;48;5;21m')\nconsole.log(state.code + 'This is logged in the current ansi state.');\nconsole.log('The current ansi state is:', JSON.stringify(state.code)); // \"\\033[1;31;48;5;21m\"\n```\n\n### Restore ANSI State\nGreat, so you've been able to keep tabs on the current ansi state, now what if you want to restore that state some place? Well you can output the state's ansi code simply:\n\n```javascript\nprocess.stdout.write(state.code) // outputs current state code to stdout\n```\n\nOr if you've set a writeable stream to pipe to, you can just call the `restore` method.\n```javascript\nstate.pipe(process.stdout)\nstate.restore() // will push state.code to wherever it is piped (ie. stdout).\n```\n\n### Reset ANSI State\nYou can reset the state by simply calling the `reset` method on the state.\n\n```javascript\nstate.reset() // sets code to '\\033[0m'\n```\n\nYou may want to then write to the terminal with the reset code:\n```javascript\nprocess.stdout.write(state.reset().code)\n```\n\nAnd of course, if you are piping to another stream:\n```javascript\nstate.pipe(process.stdout)\nstate.reset().restore()\n```\n\n### Create a New ANSI State from an Old One\n\nFinally, you can fork your state from an existing one really easily:\n\n```javascript\nvar new_state = new ANSIState(state)\n// OR\nvar new_state = new ANSIState(state.code)\n```\n\n\n## API\n### new ANSIState(legacy) Constructor\nCreates a new instace of `ANSIState`. `data` can be any of type **String**, **Array** or another **ANSIState** instance.\n\n```javascript\nvar state = new ANSIState('\\033[1;32m');\n```\n\n### state.update(data)\nUpdates the ansi style state contained in the `ANSIState` instance. `data` can be any of type **String**, **Array** or another **ANSIState** instance. The array can be of the form `['\\033[32m', '\\033[1;22;34m']` (usually what is returned from a regex match) or `[32, 1, 22, 34]`.\n\n```javascript\nstate.update('\\033[32mHi there! \\033[31mRed text')\n//current state becomes: \\033[31m\n\nstate.update('\\033[1mBolding the text too')\n//current state becomes: \\033[1;31m\n\nstate.update('\\033[34;38;5;211mxterm colors too!')\n//current state becomes: \\033[1;38;5;211m\n```\n\n### state.write(data)\nThe stream class write method on the `ANSIState` instance. `data` must be of type `String`.\n\n```javascript\nstate.write('\\033[32mHi there! This is some \\033[31mred text')\n// current state becomes: \\033[31m\n\nstate.write('\\033')\nstate.write('[3')\nstate.write('7m')\n// current state becomes: \\033[37m\n```\n\n### state.pipe(stream)\nPipe any data passed into the `ANSIState` to the supplied stream. `stream` can be any writeable stream.\n\n```javascript\nsome_stream.pipe(state).pipe(process.stdout);\n```\n\n### state.reset()\nResets the current `ANSIState` instance to the ansi reset code `\\033[0m`.\n\n```javascript\nstate.reset()\n```\n\n### state.restore()\nPushes to any piped streams the `ANSIState` instance's code.\n\n```javascript\nstate.pipe(process.stdout)\nstate.restore() // will push state.code to wherever it is piped (ie. stdout).\n```\n\n### state.code\nReturns the current ansi code for the `ANSIState` instance.\n\n```javascript\nstate.update('\\033[32mHi there! \\033[31mRed text')\nconsole.log(JSON.stringfy(state.code)) // \"\\u001b[31m\"\n```\n\n### state[attribute_name]\nReturns the human readable value of the `attribute_name` for the `ANSIState` instance. You can use any of the following attributes:\n\n- **intensity**\n- **italic**\n- **underline**\n- **blink**\n- **polarity**\n- **conceal**\n- **strikethrough**\n- **font**\n- **foreground**\n- **background**\n- **framed**\n- **overlined**\n\nThe value of each will be `null` if not set. If the foreground or background is set to `xterm color definition` you can obtain the corresponding definition code by using `state.xterm_foreground` or `state.xterm_background` respectively.\n\n```javascript\nstate.update('\\033[32mHi there! \\033[31mRed text, \\033[1;48;5;21m')\nconsole.log(state['foreground']) // red\nconsole.log(state.background) // xterm color definition\nconsole.log(state.xterm_background) // [5, 21]\nconsole.log(state.intensity) // bold\n```\n\n### state.attributes\nReturns the current attribute set for the `ANSIState` instance.\n\n```javascript\nstate.update('\\033[32mHi there! \\033[31mRed text, \\033[1;48;5;21m')\nconsole.log(state.attributes)\n// {\n//     intensity: '1',\n//     italic: null,\n//     underline: null,\n//     blink: null,\n//     polarity: null,\n//     conceal: null,\n//     strikethrough: null,\n//     font: null,\n//     foreground: '31',\n//     background: '48',\n//     framed: null,\n//     overlined: null\n// }\n```\n\n## License\n`The MIT License (MIT)`\n`Copyright (c) 2014 Arjun Mehta`\n","maintainers":[{"name":"arjunmehta","email":"arjunmeht@gmail.com"}],"time":{"modified":"2022-06-13T03:05:26.437Z","created":"2015-01-26T18:39:55.247Z","1.0.0":"2015-01-26T18:39:55.247Z","1.0.1":"2015-01-26T18:46:17.842Z","1.0.2":"2015-01-26T18:53:57.436Z","1.0.3":"2015-01-27T13:45:25.674Z","1.0.5":"2015-01-27T13:58:47.794Z"},"homepage":"https://github.com/arjunmehta/node-ansi-state","keywords":["ansi","state","colours","colors","color","colour","styles","save","restore","update"],"repository":{"type":"git","url":"https://github.com/arjunmehta/node-ansi-state.git"},"author":{"name":"Arjun Mehta"},"bugs":{"url":"https://github.com/arjunmehta/node-ansi-state/issues"},"license":"MIT","readmeFilename":"README.md","users":{"whitelynx":true}}