https://github.com/tj/node-term-css
style terminal output using CSS
https://github.com/tj/node-term-css
Last synced: 7 months ago
JSON representation
style terminal output using CSS
- Host: GitHub
- URL: https://github.com/tj/node-term-css
- Owner: tj
- Created: 2012-07-26T15:00:37.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-07-26T17:25:21.000Z (over 13 years ago)
- Last Synced: 2025-03-28T18:15:06.297Z (10 months ago)
- Language: JavaScript
- Size: 116 KB
- Stars: 117
- Watchers: 5
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# term-css
Terminal CSS styling using [node-css](https://github.com/visionmedia/node-css).
## Installation
$ npm install term-css
## Example
js:
```js
var css = require('term-css')
, fs = require('fs')
, style = fs.readFileSync('pet.css', 'utf8');
var tobi = {
name: 'tobi',
species: 'ferret',
age: 2
};
var loki = {
name: 'loki',
species: 'ferret',
age: 1
};
var fn = css.compile(' {name} is a {species}, he is {age} years old', style);
console.log();
console.log(fn(tobi));
console.log(fn(loki));
console.log();
```
css:
```css
name {
color: cyan;
font-weight: bold;
}
species {
color: white;
font-weight: bold;
background: black;
}
age {
color: red;
text-decoration: underline;
}
```
output:

## CSS properties
The following CSS properties / values are understood:
- `text-decoration: `
- `font-weight: `
- `font-style: `
- `color: `
- `background: `
## Substitution
term-css substitutes tokens with properties in the object passed,
for example `{name}` will access `{ name: "tobi" }`, whereas
`{labels.visits}` will access `{ labels: { visits: 'Visits' } }`.
For styling purposes you may also assign a classname, for example
instead of styling "labels.visits", "labels.uptime" separately,
you may use `{label labels.visits}` and `{label labels.uptime}`.
## Omitting styles
To output a plain string but use the same format, simply omit the css
string from the `.compile(fmt, style)` call.
## License
(The MIT License)
Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
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.