blessed-life
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -12,51 +12,43 @@ #!/usr/bin/env node | ||
process.argv[1] = 'blessed-life'; | ||
program | ||
.version('1.0.0') | ||
program._name = 'blessed-life'; | ||
program.usage('[options] <config>') | ||
.option('--width <width>', | ||
'specify the width of the grid', parseInt, 0) | ||
'specify the width of the grid', parseInt) | ||
.option('--height <height>', | ||
'specify the height of the grid', parseInt, 0) | ||
.option('--livecell <ch>', 'specify the char to use for live cells') | ||
.option('--deadcell <ch>', 'specify the char to use for dead cells') | ||
.option('-c, --config <path>', 'specify the config file to read from') | ||
'specify the height of the grid', parseInt) | ||
.option('--livecell <ch>', | ||
'specify the char to use for live cells') | ||
.option('--deadcell <ch>', | ||
'specify the char to use for dead cells') | ||
.option('--fg <color>', | ||
'specify the foreground color of the simulation.') | ||
.option('--bg <color>', | ||
'specify the background color of the simulation.') | ||
.option('--speed <speed>', | ||
'specify the speed in milliseconds for each tick') | ||
.option('-a, --autostart', | ||
'whether or not to automatically start the simulation') | ||
.parse(process.argv); | ||
console.log(program); | ||
var configFile = {}; | ||
if (program.args.length > 0) { | ||
var configPath = path.resolve(program.args[0]); | ||
var json = fs.readFileSync(configPath, { encoding: 'utf-8' }); | ||
configFile = JSON.parse(json); | ||
} | ||
var config = { | ||
width: program.width, | ||
height: program.height, | ||
liveCell: program.livecell, | ||
deadCell: program.deadcell, | ||
liveCells: [] | ||
width: (!isNaN(program.width) ? program.width : configFile.width || 0), | ||
height: (!isNaN(program.height) ? program.height : configFile.height || 0), | ||
liveCell: program.livecell || configFile.livecell || '█', | ||
deadCell: program.deadcell || configFile.deadcell || ' ', | ||
speed: program.speed || configFile.speed || 250, | ||
fg: program.fg || configFile.fg || 'white', | ||
bg: program.bg || configFile.bg || 'black', | ||
liveCells: configFile.liveCells || [] | ||
}; | ||
if (program.config) { | ||
program.config = path.resolve(program.config); | ||
var json = fs.readFileSync(program.config, { encoding: 'utf-8' }); | ||
var configData = JSON.parse(json); | ||
config.width = configData.width; | ||
config.height = configData.height; | ||
if (!config.liveCell) { | ||
config.liveCell = configData.liveCell; | ||
} | ||
if (!config.deadCell) { | ||
config.deadCell = configData.deadCell; | ||
} | ||
config.liveCells = configData.liveCells; | ||
} | ||
if (!config.liveCell) { | ||
config.liveCell = '0'; | ||
} | ||
if (!config.deadCell) { | ||
config.deadCell = ' '; | ||
} | ||
var screen = blessed.screen(); | ||
if (config.width === 0) { | ||
config.width = screen.width; | ||
} | ||
if (config.height === 0) { | ||
config.height = screen.height; | ||
} | ||
config.width = config.width || screen.width; | ||
config.height = config.height || screen.height; | ||
@@ -74,4 +66,4 @@ var app = new App(config); | ||
style: { | ||
fg: 'white', | ||
bg: 'black' | ||
fg: config.fg, | ||
bg: config.bg | ||
} | ||
@@ -107,3 +99,6 @@ }); | ||
var ticker = new Ticker(250, onTick); | ||
var ticker = new Ticker(config.speed, onTick); | ||
if (program.autostart) { | ||
ticker.start(); | ||
} | ||
@@ -110,0 +105,0 @@ screen.key(['space'], function(ch, key) { |
{ | ||
"name": "blessed-life", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A simple game of life simulation using the blessed node module.", | ||
@@ -5,0 +5,0 @@ "keywords": ["game", "life", "conway", "simulation", "blessed"], |
@@ -1,3 +0,48 @@ | ||
# blessed-life | ||
blessed-life | ||
============ | ||
A simple game of life simulation using the blessed node module. | ||
This is a simple simulation of Conway's game of life. It's written in javascript for nodejs and targets the command line. It utilizes the following nodejs modules: | ||
- [commander] for the command-line interface. | ||
- [blessed]: a curses-like library. | ||
Getting Started | ||
--------------- | ||
### Installation | ||
Make sure you have [node.js][nodejs] properly installed. Then use `npm` to install: | ||
$ npm install -g blessed-life | ||
You will probably have to run this command as root like so: | ||
$ sudo npm install -g blessed-life | ||
### Configuration | ||
You can write configurations for blessed-life in json. Some examples are given in the `example` directory in this repo. | ||
### Running | ||
You can start the program by opening a terminal and entering: | ||
$ blessed-life | ||
There are many command line switches that can be used (use `-h` or `--help` for more information). You can specify a certain configuration file to use by using the `-c` or `--config` switch: | ||
$ blessed-life -c example/glider.json | ||
Make sure the value for this switch is a valid path. An [asciicast][asciinema] can be found [here][asciicast]. | ||
### Further Reading | ||
If you want to know a bit more about blessed-life, visit the [wiki]. Also, feel free to read more about [Conway's game of life][gof] if you're interested in the theory. | ||
[commander]: https://npmjs.org/package/commander | ||
[blessed]: https://npmjs.org/package/blessed | ||
[nodejs]: http://nodejs.org/ | ||
[asciinema]: http://asciinema.org | ||
[asciicast]: http://asciinema.org/a/5984 | ||
[wiki]: https://github.com/Coalman/blessed-life/wiki | ||
[gof]: http://en.wikipedia.org/wiki/Conway's_Game_of_Life |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10554
14
363
48