feat: 초기 프로젝트 설정 및 룰.md 파일 추가

This commit is contained in:
2025-07-28 09:53:31 +09:00
commit 09a4d38512
8165 changed files with 1021855 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
Copyright (c) 2015, Christopher Jeffrey
https://github.com/chjj/
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.

View File

@@ -0,0 +1,17 @@
# ansi-viewer
A terminal app to view ANSI art from http://artscene.textfiles.com/ansi/.
![ansi-viewer](https://raw.githubusercontent.com/chjj/blessed/master/img/ansi-viewer.png)
## Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. `</legalese>`
## License
Copyright (c) 2015, Christopher Jeffrey. (MIT License)
See LICENSE for more info.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,292 @@
/**
* ansi-viewer
* ANSI art viewer for node.
* Copyright (c) 2015, Christopher Jeffrey and contributors (MIT License).
* https://github.com/chjj/blessed
*/
var blessed = require('blessed')
, request = require('request')
, singlebyte = require('./singlebyte')
, fs = require('fs');
// $ wget -r -o log --tries=10 'http://artscene.textfiles.com/ansi/'
// $ grep 'http.*\.ans$' log | awk '{ print $3 }' > ansi-art.list
var urls = fs.readFileSync(__dirname + '/ansi-art.list', 'utf8').trim().split('\n');
var map = urls.reduce(function(map, url) {
map[/([^.\/]+\/[^.\/]+)\.ans$/.exec(url)[1]] = url;
return map;
}, {});
var max = Object.keys(map).reduce(function(out, text) {
return Math.max(out, text.length);
}, 0) + 6;
var screen = blessed.screen({
smartCSR: true,
dockBorders: true
});
var art = blessed.terminal({
parent: screen,
left: 0,
top: 0,
height: 60,
// some are 78/80, some are 80/82
width: 82,
border: 'line',
tags: true,
label: ' {bold}{cyan-fg}ANSI Art{/cyan-fg}{/bold} (Drag Me) ',
handler: function() {},
draggable: true
});
var list = blessed.list({
parent: screen,
label: ' {bold}{cyan-fg}Art List{/cyan-fg}{/bold} (Drag Me) ',
tags: true,
draggable: true,
top: 0,
right: 0,
width: max,
height: '50%',
keys: true,
vi: true,
mouse: true,
border: 'line',
scrollbar: {
ch: ' ',
track: {
bg: 'cyan'
},
style: {
inverse: true
}
},
style: {
item: {
hover: {
bg: 'blue'
}
},
selected: {
bg: 'blue',
bold: true
}
},
search: function(callback) {
prompt.input('Search:', '', function(err, value) {
if (err) return;
return callback(null, value);
});
}
});
var status = blessed.box({
parent: screen,
bottom: 0,
right: 0,
height: 1,
width: 'shrink',
style: {
bg: 'blue'
},
content: 'Select your piece of ANSI art (`/` to search).'
});
var loader = blessed.loading({
parent: screen,
top: 'center',
left: 'center',
height: 5,
align: 'center',
width: '50%',
tags: true,
hidden: true,
border: 'line'
});
var msg = blessed.message({
parent: screen,
top: 'center',
left: 'center',
height: 'shrink',
width: '50%',
align: 'center',
tags: true,
hidden: true,
border: 'line'
});
var prompt = blessed.prompt({
parent: screen,
top: 'center',
left: 'center',
height: 'shrink',
width: 'shrink',
keys: true,
vi: true,
mouse: true,
tags: true,
border: 'line',
hidden: true
});
list.setItems(Object.keys(map));
list.on('select', function(el, selected) {
if (list._.rendering) return;
var name = el.getText();
var url = map[name];
status.setContent(url);
list._.rendering = true;
loader.load('Loading...');
request({
uri: url,
encoding: null
}, function(err, res, body) {
list._.rendering = false;
loader.stop();
if (err) {
return msg.error(err.message);
}
if (!body) {
return msg.error('No body.');
}
return cp437ToUtf8(body, function(err, body) {
if (err) {
return msg.error(err.message);
}
if (process.argv[2] === '--debug') {
var filename = name.replace(/\//g, '.') + '.ans';
fs.writeFileSync(__dirname + '/' + filename, body);
}
// Remove text:
body = body.replace('Downloaded From P-80 International Information Systems 304-744-2253', '');
// Remove MCI codes:
body = body.replace(/%[A-Z0-9]{2}/g, '');
// ^A (SOH) seems to need to produce CRLF in some cases??
// body = body.replace(/\x01/g, '\r\n');
// Reset and write the art:
art.term.reset();
art.term.write(body);
art.term.cursorHidden = true;
screen.render();
if (process.argv[2] === '--debug' || process.argv[2] === '--save') {
takeScreenshot(name);
}
});
});
});
list.items.forEach(function(item, i) {
var text = item.getText();
item.setHover(map[text]);
});
list.focus();
list.enterSelected(0);
screen.key('h', function() {
list.toggle();
if (list.visible) list.focus();
});
screen.key('r', function() {
shuffle();
});
screen.key('S-s', function() {
takeScreenshot(list.ritems[list.selected]);
});
screen.key('s', function() {
slideshow();
});
screen.key('q', function() {
return process.exit(0);
});
screen.render();
/**
* Helpers
*/
// https://github.com/chjj/blessed/issues/127
// https://github.com/Mithgol/node-singlebyte
function cp437ToUtf8(buf, callback) {
try {
return callback(null, singlebyte.bufToStr(buf, 'cp437'));
} catch (e) {
return callback(e);
}
}
// Animating ANSI art doesn't work for screenshots.
var ANIMATING = [
'bbs/void3',
'holiday/xmasfwks',
'unsorted/diver',
'unsorted/mash-chp',
'unsorted/ryans47',
'unsorted/xmasfwks'
];
function takeScreenshot(name) {
var filename = name.replace(/\//g, '.') + '.ans.sgr';
var image;
// Animating art hangs terminal during screenshot as of right now.
if (~ANIMATING.indexOf(name)) {
image = blessed.element.prototype.screenshot.call(art,
0 - art.ileft, art.width - art.iright,
0 - art.itop, art.height - art.ibottom);
} else {
image = art.screenshot();
}
fs.writeFileSync(__dirname + '/' + filename, image);
msg.display('Screenshot taken.');
}
function slideshow() {
if (!screen._.slideshow) {
screen._.slideshow = setInterval(function slide() {
if (screen.lockKeys) return;
var i = (list.items.length - 1) * Math.random() | 0;
list.enterSelected(i);
return slide;
}(), 3000);
msg.display('Slideshow started.');
} else {
clearInterval(screen._.slideshow);
delete screen._.slideshow;
msg.display('Slideshow stopped.');
}
}
function shuffle() {
var items = Object.keys(map).sort(function(key) {
return Math.random() > 0.5 ? 1 : -1;
});
list.setItems(items);
screen.render();
msg.display('Shuffled items.');
}

View File

@@ -0,0 +1,19 @@
{
"name": "ansi-viewer",
"description": "ANSI art viewer for node",
"author": "Christopher Jeffrey",
"version": "0.0.1",
"main": "./index.js",
"bin": "./index.js",
"preferGlobal": false,
"repository": "git://github.com/chjj/blessed.git",
"homepage": "https://github.com/chjj/blessed",
"bugs": { "url": "http://github.com/chjj/blessed/issues" },
"keywords": ["ansi", "art"],
"tags": ["ansi", "art"],
"dependencies": {
"blessed": ">=0.1.5",
"term.js": "0.0.4",
"request": "2.55.0"
}
}

View File

@@ -0,0 +1,406 @@
/**
* node-singlebyte
*/
// The MIT License (MIT)
//
// Copyright (c) 2013, Sergey Sokoloff (aka Mithgol the Webmaster).
// https://github.com/Mithgol/node-singlebyte
//
// 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.
var extend = function(target) {
target = target || {};
Array.prototype.slice.call(arguments, 1).forEach(function(obj) {
Object.keys(obj || {}).forEach(function(key) {
target[key] = obj[key];
});
});
return target;
};
var singlebyte = function(){
/* jshint indent: false */
if(!( this instanceof singlebyte )){
return new singlebyte();
}
this.encodings = [];
// CP437
this.learnEncoding('cp437', this.extendASCII([
0xC7, 0xFC, 0xE9, 0xE2, 0xE4, 0xE0, 0xE5, 0xE7,
0xEA, 0xEB, 0xE8, 0xEF, 0xEE, 0xEC, 0xC4, 0xC5,
0xC9, 0xE6, 0xC6, 0xF4, 0xF6, 0xF2, 0xFB, 0xF9,
0xFF, 0xD6, 0xDC, 0xA2, 0xA3, 0xA5, 0x20A7, 0x192,
0xE1, 0xED, 0xF3, 0xFA, 0xF1, 0xD1, 0xAA, 0xBA,
0xBF, 0x2310, 0xAC, 0xBD, 0xBC, 0xA1, 0xAB, 0xBB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x3B1, 0x3B2, 0x393, 0x3C0, 0x3A3, 0x3C3, 0x3BC, 0x3C4,
0x3A6, 0x398, 0x3A9, 0x3B4, 0x221E, 0x3C6, 0x3B5, 0x2229,
0x2261, 0xB1, 0x2265, 0x2264, 0x2320, 0x2321, 0xF7, 0x2248,
0xB0, 0x2219, 0xB7, 0x221A, 0x207F, 0xB2, 0x25A0, 0xA0
]));
// CP850
this.learnEncoding('cp850', this.extendASCII([
0xC7, 0xFC, 0xE9, 0xE2, 0xE4, 0xE0, 0xE5, 0xE7,
0xEA, 0xEB, 0xE8, 0xEF, 0xEE, 0xEC, 0xC4, 0xC5,
0xC9, 0xE6, 0xC6, 0xF4, 0xF6, 0xF2, 0xFB, 0xF9,
0xFF, 0xD6, 0xDC, 0xF8, 0xA3, 0xD8, 0xD7, 0x192,
0xE1, 0xED, 0xF3, 0xFA, 0xF1, 0xD1, 0xAA, 0xBA,
0xBF, 0xAE, 0xAC, 0xBD, 0xBC, 0xA1, 0xAB, 0xBB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0xC1, 0xC2, 0xC0,
0xA9, 0x2563, 0x2551, 0x2557, 0x255D, 0xA2, 0xA5, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0xE3, 0xC3,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0xA4,
0xF0, 0xD0, 0xCA, 0xCB, 0xC8, 0x131, 0xCD, 0xCE,
0xCF, 0x2518, 0x250C, 0x2588, 0x2584, 0xA6, 0xCC, 0x2580,
0xD3, 0xDF, 0xD4, 0xD2, 0xF5, 0xD5, 0xB5, 0xFE,
0xDE, 0xDA, 0xDB, 0xD9, 0xFD, 0xDD, 0xAF, 0xB4,
0xAD, 0xB1, 0x2017, 0xBE, 0xB6, 0xA7, 0xF7, 0xB8,
0xB0, 0xA8, 0xB7, 0xB9, 0xB3, 0xB2, 0x25A0, 0xA0
]));
// CP858
this.learnEncoding('cp858', this.extendASCII([
0xC7, 0xFC, 0xE9, 0xE2, 0xE4, 0xE0, 0xE5, 0xE7,
0xEA, 0xEB, 0xE8, 0xEF, 0xEE, 0xEC, 0xC4, 0xC5,
0xC9, 0xE6, 0xC6, 0xF4, 0xF6, 0xF2, 0xFB, 0xF9,
0xFF, 0xD6, 0xDC, 0xF8, 0xA3, 0xD8, 0xD7, 0x192,
0xE1, 0xED, 0xF3, 0xFA, 0xF1, 0xD1, 0xAA, 0xBA,
0xBF, 0xAE, 0xAC, 0xBD, 0xBC, 0xA1, 0xAB, 0xBB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0xC1, 0xC2, 0xC0,
0xA9, 0x2563, 0x2551, 0x2557, 0x255D, 0xA2, 0xA5, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0xE3, 0xC3,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0xA4,
0xF0, 0xD0, 0xCA, 0xCB, 0xC8, 0x20AC, 0xCD, 0xCE,
0xCF, 0x2518, 0x250C, 0x2588, 0x2584, 0xA6, 0xCC, 0x2580,
0xD3, 0xDF, 0xD4, 0xD2, 0xF5, 0xD5, 0xB5, 0xFE,
0xDE, 0xDA, 0xDB, 0xD9, 0xFD, 0xDD, 0xAF, 0xB4,
0xAD, 0xB1, 0x2017, 0xBE, 0xB6, 0xA7, 0xF7, 0xB8,
0xB0, 0xA8, 0xB7, 0xB9, 0xB3, 0xB2, 0x25A0, 0xA0
]));
// CP808
this.learnEncoding('cp808', this.extendASCII([
0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417,
0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F,
0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427,
0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F,
0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437,
0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447,
0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F,
0x401, 0x451, 0x404, 0x454, 0x407, 0x457, 0x40E, 0x45E,
0xB0, 0x2219, 0xB7, 0x221A, 0x2116, 0x20AC, 0x25A0, 0xA0
]));
// CP866
this.learnEncoding('cp866', this.extendASCII([
0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417,
0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F,
0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427,
0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F,
0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437,
0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447,
0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F,
0x401, 0x451, 0x404, 0x454, 0x407, 0x457, 0x40E, 0x45E,
0xB0, 0x2219, 0xB7, 0x221A, 0x2116, 0xA4, 0x25A0, 0xA0
]));
// CP1125
this.learnEncoding('cp1125', this.extendASCII([
0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417,
0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F,
0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427,
0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F,
0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437,
0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447,
0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F,
0x401, 0x451, 0x490, 0x491, 0x404, 0x454, 0x406, 0x456,
0x407, 0x457, 0xB7, 0x221A, 0x2116, 0xA4, 0x25A0, 0xA0
]));
// KOI8-R
this.learnEncoding('koi8-r', this.extendASCII([
0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524,
0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590,
0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248,
0x2264, 0x2265, 0xA0, 0x2321, 0xB0, 0xB2, 0xB7, 0xF7,
0x2550, 0x2551, 0x2552, 0x451, 0x2553, 0x2554, 0x2555, 0x2556,
0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x255C, 0x255D, 0x255E,
0x255F, 0x2560, 0x2561, 0x401, 0x2562, 0x2563, 0x2564, 0x2565,
0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x256B, 0x256C, 0xA9,
0x44E, 0x430, 0x431, 0x446, 0x434, 0x435, 0x444, 0x433,
0x445, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x043E,
0x43F, 0x44F, 0x440, 0x441, 0x442, 0x443, 0x436, 0x432,
0x44C, 0x44B, 0x437, 0x448, 0x44D, 0x449, 0x447, 0x44A,
0x42E, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413,
0x425, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E,
0x41F, 0x42F, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412,
0x42C, 0x42B, 0x417, 0x428, 0x42D, 0x429, 0x427, 0x42A
]));
// KOI8-U
this.learnEncoding('koi8-u', this.extendASCII([
0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524,
0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590,
0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248,
0x2264, 0x2265, 0xA0, 0x2321, 0xB0, 0xB2, 0xB7, 0xF7,
0x2550, 0x2551, 0x2552, 0x451, 0x454, 0x2554, 0x456, 0x457,
0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x491, 0x255D, 0x255E,
0x255F, 0x2560, 0x2561, 0x401, 0x404, 0x2563, 0x406, 0x407,
0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x490, 0x256C, 0xA9,
0x44E, 0x430, 0x431, 0x446, 0x434, 0x435, 0x444, 0x433,
0x445, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x043E,
0x43F, 0x44F, 0x440, 0x441, 0x442, 0x443, 0x436, 0x432,
0x44C, 0x44B, 0x437, 0x448, 0x44D, 0x449, 0x447, 0x44A,
0x42E, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413,
0x425, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E,
0x41F, 0x42F, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412,
0x42C, 0x42B, 0x417, 0x428, 0x42D, 0x429, 0x427, 0x42A
]));
// KOI8-RU
this.learnEncoding('koi8-ru', this.extendASCII([
0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524,
0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590,
0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248,
0x2264, 0x2265, 0xA0, 0x2321, 0xB0, 0xB2, 0xB7, 0xF7,
0x2550, 0x2551, 0x2552, 0x451, 0x454, 0x2554, 0x456, 0x457,
0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x491, 0x45E, 0x255E,
0x255F, 0x2560, 0x2561, 0x401, 0x404, 0x2563, 0x406, 0x407,
0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x490, 0x40E, 0xA9,
0x44E, 0x430, 0x431, 0x446, 0x434, 0x435, 0x444, 0x433,
0x445, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x043E,
0x43F, 0x44F, 0x440, 0x441, 0x442, 0x443, 0x436, 0x432,
0x44C, 0x44B, 0x437, 0x448, 0x44D, 0x449, 0x447, 0x44A,
0x42E, 0x410, 0x411, 0x426, 0x414, 0x415, 0x424, 0x413,
0x425, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E,
0x41F, 0x42F, 0x420, 0x421, 0x422, 0x423, 0x416, 0x412,
0x42C, 0x42B, 0x417, 0x428, 0x42D, 0x429, 0x427, 0x42A
]));
// LATIN-1 aka ISO 8859-1 (Western European)
this.learnEncoding('latin-1', this.extendASCII([
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
]));
// Windows-1252
this.learnEncoding('cp1252', this.extendASCII([
0x20AC, 0x81, 0x201A, 0x192, 0x201E, 0x2026, 0x2020, 0x2021,
0x2C6, 0x2030, 0x160, 0x2039, 0x152, 0x8D, 0x017D, 0x8F,
0x90, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x161, 0x203A, 0x0153, 0x9D, 0x17E, 0x178,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
]));
};
singlebyte.prototype.isEncoding = function(encodingName){
if( Buffer.isEncoding(encodingName) ) return true;
for( var i = 0; i < this.encodings.length; i++ ){
if( this.encodings[i].name === encodingName ) return true;
}
return false;
};
singlebyte.prototype.learnEncoding = function(encodingName, encodingTable){
/*jshint bitwise: false */
if( Buffer.isEncoding(encodingName) ){
throw new Error(this.errors.BUFFER_ENCODING);
}
if( encodingTable.length !== 256 ){
throw new Error(this.errors.INVALID_TABLE_LENGTH);
}
var _this = this;
encodingTable = encodingTable.map(function(item){
var nextCode = item |0;
if( 0 > nextCode || nextCode > 0x10FFFF ){
throw new Error(_this.errors.OUT_OF_UNICODE);
}
return item;
});
if( this.isEncoding(encodingName) ){
for( var i = 0; i < this.encodings.length; i++ ){
if( this.encodings[i].name === encodingName ){
this.encodings[i].table = encodingTable;
return;
}
}
} else {
this.encodings.push({
name: encodingName,
table: encodingTable
});
}
};
singlebyte.prototype.getEncodingTable = function(encodingName){
for( var i = 0; i < this.encodings.length; i++ ){
if( this.encodings[i].name === encodingName ){
return this.encodings[i].table;
}
}
return null;
};
singlebyte.prototype.extendASCII = function(extensionTable){
if( extensionTable.length !== 128 ){
throw new Error(this.errors.INVALID_EXTENSION);
}
var output = [];
for( var i = 0; i < 128; i++ ) output.push(i);
return output.concat(extensionTable);
};
singlebyte.prototype.bufToStr = function(buf, encoding, start, end){
/* jshint bitwise: false */
if(!( Buffer.isBuffer(buf) )){
throw new Error(this.errors.NOT_A_BUFFER);
}
if( Buffer.isEncoding(encoding) ){
return buf.toString(encoding, start, end);
}
var table = this.getEncodingTable(encoding);
if( table === null ) throw new Error(this.errors.UNKNOWN_ENCODING);
if( typeof end === 'undefined' ) end = buf.length;
if( typeof start === 'undefined' ) start = 0;
var output = '';
var sourceValue;
for( var i = start; i < end; i++ ){
sourceValue = table[ buf[i] ];
if( sourceValue <= 0xFFFF ){
output += String.fromCharCode(sourceValue);
} else if( 0x10000 <= sourceValue && sourceValue <= 0x10FFFF ){
sourceValue -= 0x10000;
output += String.fromCharCode( 0xD800 + (sourceValue >> 10) );
output += String.fromCharCode( 0xDC00 + (sourceValue & 0x3FF) );
} else throw new Error(this.errors.OUT_OF_UNICODE);
}
return output;
};
var strToBufDefaults = {
defaultCode: 0x3F // '?'
};
singlebyte.prototype.strToBuf = function(str, encoding, encodingOptions){
if( Buffer.isEncoding(encoding) ){
return new Buffer(str, encoding);
}
str = '' + str;
var options = extend({}, strToBufDefaults, encodingOptions);
var table = this.getEncodingTable(encoding);
if( table === null ) throw new Error(this.errors.UNKNOWN_ENCODING);
var output = [];
for( var i = 0; i < str.length; i++ ){
var charUnicode;
var thisCharCode = str.charCodeAt(i);
if( 0xD800 <= thisCharCode && thisCharCode <= 0xDBFF &&
i+1 < str.length
){
var nextCharCode = str.charCodeAt(i+1);
if( 0xDC00 <= nextCharCode && nextCharCode <= 0xDFFF ){
charUnicode = 0x10000 + (thisCharCode - 0xD800)*0x400 +
(nextCharCode - 0xDC00);
i++;
} else {
charUnicode = thisCharCode;
}
} else {
charUnicode = thisCharCode;
}
var codeFoundIndex = table.indexOf(charUnicode);
if( codeFoundIndex < 0 ){
output.push(options.defaultCode);
} else {
output.push(codeFoundIndex);
}
}
return new Buffer(output);
};
singlebyte.prototype.errors = {
NOT_A_BUFFER : 'The given source is not a buffer!',
UNKNOWN_ENCODING : 'The given encoding is not defined!',
INVALID_TABLE_LENGTH : 'The encoding table must have 256 elements!',
INVALID_EXTENSION : 'The ASCII extension table must have 128 elements!',
BUFFER_ENCODING : "Cannot redefine a Node's encoding!",
OUT_OF_UNICODE : "An encoding table's element is greater than 0x10FFFF!"
};
module.exports = singlebyte();

View File

@@ -0,0 +1,139 @@
#!/usr/bin/env node
/**
* blessed-telnet.js
* https://github.com/chjj/blessed
* Copyright (c) 2013-2015, Christopher Jeffrey (MIT License)
* A blessed telnet server.
* See: https://github.com/TooTallNate/node-telnet
*/
process.title = 'blessed-telnet';
var fs = require('fs');
var path = require('path');
var blessed = require('blessed');
var telnet = require('telnet');
var server = telnet.createServer(function(client) {
client.do.transmit_binary();
client.do.terminal_type();
client.do.window_size();
client.do.environment_variables();
client.on('debug', function(msg) {
console.error(msg);
});
client.on('environment variables', function(data) {
if (data.command === 'sb') {
if (data.name === 'TERM') {
screen.terminal = data.value;
} else {
// Clear the screen since they may have used `env send [var]`.
screen.realloc();
}
screen.render();
}
});
client.on('terminal type', function(data) {
if (data.command === 'sb' && data.name) {
screen.terminal = data.name;
screen.render();
}
});
client.on('window size', function(data) {
if (data.command === 'sb') {
client.columns = data.columns;
client.rows = data.rows;
client.emit('resize');
}
});
// Make the client look like a tty:
client.setRawMode = function(mode) {
client.isRaw = mode;
if (!client.writable) return;
if (mode) {
client.do.suppress_go_ahead();
client.will.suppress_go_ahead();
client.will.echo();
} else {
client.dont.suppress_go_ahead();
client.wont.suppress_go_ahead();
client.wont.echo();
}
};
client.isTTY = true;
client.isRaw = false;
client.columns = 80;
client.rows = 24;
var screen = blessed.screen({
smartCSR: true,
input: client,
output: client,
terminal: 'xterm-256color',
fullUnicode: true
});
client.on('close', function() {
if (!screen.destroyed) {
screen.destroy();
}
});
screen.on('destroy', function() {
if (client.writable) {
client.destroy();
}
});
if (test === 'widget-simple') {
return simpleTest(screen);
}
loadTest(screen, test);
});
function simpleTest(screen) {
screen.data.main = blessed.box({
parent: screen,
width: '80%',
height: '90%',
border: 'line',
content: 'Welcome to my server. Here is your own private session.',
style: {
bg: 'red'
}
});
screen.key('i', function() {
screen.data.main.style.bg = 'blue';
screen.render();
});
screen.key(['C-c', 'q'], function(ch, key) {
screen.destroy();
});
screen.render();
}
var test = process.argv[2] || path.resolve(__dirname, '../test/widget-shadow.js');
if (~test.indexOf('widget-png.js')) process.argv.length = 2;
test = path.resolve(process.cwd(), test);
function loadTest(screen, name) {
var Screen = blessed.screen;
blessed.screen = function() { return screen; };
var path = require.resolve(name);
delete require.cache[path];
require(name);
blessed.screen = Screen;
}
server.listen(2300);
console.log('Listening on 2300...');

77
api.hyungi.net/node_modules/blessed/example/index.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
/**
* Example Program for Blessed
* Copyright (c) 2013, Christopher Jeffrey (MIT License).
* https://github.com/chjj/blessed
*/
var blessed = require('../')
, program = blessed.program();
process.title = 'blessed';
program.on('keypress', function(ch, key) {
if (key.name === 'q') {
program.clear();
program.disableMouse();
program.showCursor();
program.normalBuffer();
process.exit(0);
}
});
program.on('mouse', function(data) {
if (data.action === 'mouseup') return;
program.move(1, program.rows);
program.eraseInLine('right');
if (data.action === 'wheelup') {
program.write('Mouse wheel up at: ' + data.x + ', ' + data.y);
} else if (data.action === 'wheeldown') {
program.write('Mouse wheel down at: ' + data.x + ', ' + data.y);
} else if (data.action === 'mousedown' && data.button === 'left') {
program.write('Left button down at: ' + data.x + ', ' + data.y);
} else if (data.action === 'mousedown' && data.button === 'right') {
program.write('Right button down at: ' + data.x + ', ' + data.y);
} else {
program.write('Mouse at: ' + data.x + ', ' + data.y);
}
program.move(data.x, data.y);
program.bg('red');
program.write(' ');
program.bg('!red');
});
program.on('focus', function() {
program.move(1, program.rows);
program.write('Gained focus.');
});
program.on('blur', function() {
program.move(1, program.rows);
program.write('Lost focus.');
});
program.alternateBuffer();
program.enableMouse();
program.hideCursor();
program.clear();
program.move(1, 1);
program.bg('black');
program.write('Hello world', 'blue fg');
program.setx((program.cols / 2 | 0) - 4);
program.down(5);
program.write('Hi again!');
program.bg('!black');
program.feed();
program.getCursor(function(err, data) {
if (!err) {
program.write('Cursor is at: ' + data.x + ', ' + data.y + '.');
program.feed();
}
program.charset('SCLD');
program.write('abcdefghijklmnopqrstuvwxyz0123456789');
program.charset('US');
program.setx(1);
});

View File

@@ -0,0 +1,142 @@
#!/usr/bin/env node
/**
* multiplex.js
* https://github.com/chjj/blessed
* Copyright (c) 2013-2015, Christopher Jeffrey (MIT License)
* A terminal multiplexer created by blessed.
*/
process.title = 'multiplex.js';
var blessed = require('blessed')
, screen;
screen = blessed.screen({
smartCSR: true,
log: process.env.HOME + '/blessed-terminal.log',
fullUnicode: true,
dockBorders: true,
ignoreDockContrast: true
});
var topleft = blessed.terminal({
parent: screen,
cursor: 'line',
cursorBlink: true,
screenKeys: false,
label: ' multiplex.js ',
left: 0,
top: 0,
width: '50%',
height: '50%',
border: 'line',
style: {
fg: 'default',
bg: 'default',
focus: {
border: {
fg: 'green'
}
}
}
});
topleft.pty.on('data', function(data) {
screen.log(JSON.stringify(data));
});
var topright = blessed.terminal({
parent: screen,
cursor: 'block',
cursorBlink: true,
screenKeys: false,
label: ' multiplex.js ',
left: '50%-1',
top: 0,
width: '50%+1',
height: '50%',
border: 'line',
style: {
fg: 'red',
bg: 'black',
focus: {
border: {
fg: 'green'
}
}
}
});
var bottomleft = blessed.terminal({
parent: screen,
cursor: 'block',
cursorBlink: true,
screenKeys: false,
label: ' multiplex.js ',
left: 0,
top: '50%-1',
width: '50%',
height: '50%+1',
border: 'line',
style: {
fg: 'default',
bg: 'default',
focus: {
border: {
fg: 'green'
}
}
}
});
var bottomright = blessed.terminal({
parent: screen,
cursor: 'block',
cursorBlink: true,
screenKeys: false,
label: ' multiplex.js ',
left: '50%-1',
top: '50%-1',
width: '50%+1',
height: '50%+1',
border: 'line',
style: {
fg: 'default',
bg: 'default',
focus: {
border: {
fg: 'green'
}
}
}
});
[topleft, topright, bottomleft, bottomright].forEach(function(term) {
term.enableDrag(function(mouse) {
return !!mouse.ctrl;
});
term.on('title', function(title) {
screen.title = title;
term.setLabel(' ' + title + ' ');
screen.render();
});
term.on('click', term.focus.bind(term));
});
topleft.focus();
screen.key('C-q', function() {
topleft.kill();
topright.kill();
bottomleft.kill();
bottomright.kill();
return screen.destroy();
});
screen.program.key('S-tab', function() {
screen.focusNext();
screen.render();
});
screen.render();

448
api.hyungi.net/node_modules/blessed/example/ping generated vendored Normal file
View File

@@ -0,0 +1,448 @@
#!/usr/bin/env node
/**
* ping
* https://github.com/chjj/blessed
* Copyright (c) 2013, Christopher Jeffrey (MIT License)
* Online (ping)pong in your terminal.
*/
// Example Usage:
// Server: $ ./example/ping 3000
// Client: $ ./example/ping 127.0.0.1 3000
// Demo: $ ./example/ping
process.title = 'ping';
if (/^(-h|--help|-\?)$/.test(process.argv[2])) {
console.log('node-ping');
console.log('Example Usage:');
console.log('Server: $ node-ping 3000');
console.log('Client: $ node-ping 127.0.0.1 3000');
console.log('Demo: $ node-ping');
return process.exit(0);
}
var blessed = require('blessed')
, nssocket;
try {
nssocket = require('nssocket');
} catch (e) {
;
}
var server
, socket;
/**
* Screen Layout
*/
var screen = blessed.screen();
var table = blessed.box({
left: 0,
top: 0,
width: screen.width,
height: screen.height
});
var ball = blessed.box({
width: 1,
height: 1,
bg: 'white',
top: 0,
left: 0
});
var lpaddle = blessed.box({
width: 1,
height: 3,
bg: 'yellow',
top: 0,
left: 0
});
var rpaddle = blessed.box({
width: 1,
height: 3,
bg: 'yellow',
top: 0,
right: 0
});
var score = blessed.box({
top: 0,
left: 4,
height: 3,
width: 'shrink',
border: {
type: 'line'
},
//align: 'center',
style: {
bold: true
},
tags: true
});
score.lwins = 0;
score.rwins = 0;
var net = blessed.box({
width: 1,
height: '100%',
bg: 'yellow',
top: 0,
left: 'center'
});
var message = blessed.box({
width: '50%',
height: 3,
border: {
type: 'line'
},
top: 'center',
left: 'center'
});
var text = blessed.box({
top: 'center',
left: 1,
right: 1,
height: 1,
align: 'center',
content: 'Waiting for players to connect...'
});
message.append(text);
screen.append(table);
table.append(score);
table.append(lpaddle);
table.append(rpaddle);
table.append(net);
table.append(ball);
table.append(message);
screen.on('resize', function() {
table.width = screen.width;
table.height = screen.height;
[ball, lpaddle, rpaddle].forEach(function(el) {
if (el.rbottom < 0) el.rtop = table.height - 1 - el.height;
if (el.rright < 0) el.rleft = table.width - 1;
});
screen.render();
sync();
});
/**
* Options
*/
ball.speed = 2;
ball.unpredictable = true;
lpaddle.speed = 2;
rpaddle.speed = 2;
/**
* Game
*/
function sync() {
if (!socket) return;
socket.send(['update'], {
table: { width: table.width, height: table.height },
lpaddle: { rleft: lpaddle.rleft, rtop: lpaddle.rtop, speed: lpaddle.speed },
rpaddle: { rleft: rpaddle.rleft, rtop: rpaddle.rtop, speed: rpaddle.speed },
score: { lwins: score.lwins, rwins: score.rwins }
});
}
function reset() {
text.setContent('Waiting for players to connect...');
message.hide();
ball.moving = true;
ball.direction = 'right';
ball.angle = 'down';
ball.rtop = 1;
ball.rleft = 1;
if ((score.lwins + score.rwins) % 2 !== 0) {
ball.direction = 'left';
ball.rleft = table.width - 1;
}
lpaddle.rtop = 0;
rpaddle.rtop = 0;
score.setContent('{green-fg}Score:{/} ' + score.lwins + ' | ' + score.rwins);
rpaddle.movable = true;
screen.render();
if (server && socket) {
socket.send(['reset']);
}
}
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function startGame() {
reset();
if (startGame._bound) return;
startGame._bound = true;
screen.on('keypress', function(ch, key) {
if (!ball.moving) return;
if (key.name === 'up' || key.name === 'k') {
if (socket) socket.send(['up']);
if (lpaddle.rtop > 0) lpaddle.rtop -= lpaddle.speed;
if (!socket) if (rpaddle.rtop > 0) rpaddle.rtop -= rpaddle.speed;
if (lpaddle.rtop < 0) lpaddle.rtop = 0;
if (rpaddle.rtop < 0) rpaddle.rtop = 0;
screen.render();
} else if (key.name === 'down' || key.name === 'j') {
if (socket) socket.send(['down']);
if (lpaddle.rbottom > 0) lpaddle.rtop += lpaddle.speed;
if (!socket) if (rpaddle.rbottom > 0) rpaddle.rtop += rpaddle.speed;
if (lpaddle.rbottom < 0) lpaddle.rtop = table.height - lpaddle.height - 1;
if (rpaddle.rbottom < 0) rpaddle.rtop = table.height - rpaddle.height - 1;
screen.render();
}
});
setInterval(function() {
if (!ball.moving) return;
if (ball.direction === 'right') {
if (ball.rright > 1) {
ball.rleft += ball.speed;
} else {
if (ball.rtop >= rpaddle.rtop && ball.rtop <= rpaddle.rtop + rpaddle.height) {
ball.direction = 'left';
ball.rleft -= ball.speed;
ball.rleft -= rand(0, 3);
if (ball.angle === 'down') ball.rtop += rand(0, 3);
else if (ball.angle === 'up') ball.rtop -= rand(0, 3);
} else {
// Right loses
score.lwins++;
ball.rleft = table.width - 1;
if (socket) socket.send(['lose']);
ball.moving = false;
text.setContent('Right player loses!');
message.show();
setTimeout(reset, 3000);
screen.render();
return;
}
}
if (ball.rright < 1) ball.rleft = table.width - 2;
} else if (ball.direction === 'left') {
if (ball.rleft > 1) {
ball.rleft -= ball.speed;
} else {
if (ball.rtop >= lpaddle.rtop && ball.rtop <= lpaddle.rtop + lpaddle.height) {
ball.direction = 'right';
ball.rleft += ball.speed;
ball.rleft += rand(0, 3);
if (ball.angle === 'down') ball.rtop += rand(0, 3);
else if (ball.angle === 'up') ball.rtop -= rand(0, 3);
} else {
// Left loses
score.rwins++;
ball.rleft = 0;
if (socket) socket.send(['win']);
ball.moving = false;
text.setContent('Left player loses!');
message.show();
setTimeout(reset, 3000);
screen.render();
return;
}
}
if (ball.rleft < 1) ball.rleft = 1;
}
if (ball.angle === 'down') {
if (ball.rbottom > 0) {
ball.rtop++;
if (ball.unpredictable) ball.rtop += rand(0, 3);
} else {
ball.angle = 'up';
ball.rtop--;
}
} else if (ball.angle === 'up') {
if (ball.rtop > 0) {
ball.rtop--;
if (ball.unpredictable) ball.rtop -= rand(0, 3);
} else {
ball.angle = 'down';
ball.rtop++;
}
}
if (ball.rtop < 0) ball.rtop = 0;
if (ball.rbottom < 0) ball.rtop = table.height - 1;
if (socket) socket.send(['ball'], { rleft: ball.rleft, rtop: ball.rtop });
screen.render();
}, 100);
}
function startServer() {
server = nssocket.createServer({}, function(socket_) {
socket = socket_;
sync();
socket.data(['up'], function() {
if (!ball.moving) return;
if (rpaddle.rtop > 0) rpaddle.rtop -= rpaddle.speed;
screen.render();
});
socket.data(['down'], function() {
if (!ball.moving) return;
if (rpaddle.rtop < table.height - 1) rpaddle.rtop += rpaddle.speed;
screen.render();
});
socket.on('error', function() {
socket = null;
reset();
ball.moving = false;
message.show();
screen.render();
});
startGame();
});
server.listen(+process.argv[2]);
}
function startClient() {
var socket = new nssocket.NsSocket({
reconnect: true,
maxRetries: Infinity,
retryInterval: 5000
});
socket.connect(+process.argv[3], process.argv[2]);
screen.on('keypress', function(ch, key) {
if (!rpaddle.movable) return;
if (key.name === 'up' || key.name === 'k') {
socket.send(['up']);
if (rpaddle.rtop > 0) rpaddle.rtop -= rpaddle.speed;
if (rpaddle.rtop < 0) rpaddle.rtop = 0;
screen.render();
} else if (key.name === 'down' || key.name === 'j') {
socket.send(['down']);
if (rpaddle.rbottom > 0) rpaddle.rtop += rpaddle.speed;
if (rpaddle.rbottom < 0) rpaddle.rtop = table.height - rpaddle.height - 1;
screen.render();
}
});
socket.data(['up'], function() {
if (lpaddle.rtop > 0) lpaddle.rtop -= lpaddle.speed;
screen.render();
});
socket.data(['down'], function() {
if (lpaddle.rtop < table.height - 1) lpaddle.rtop += lpaddle.speed;
screen.render();
});
socket.data(['ball'], function(data) {
ball.rleft = data.rleft;
ball.rtop = data.rtop;
screen.render();
});
socket.data(['update'], function(data) {
if (data.lpaddle) {
lpaddle.rleft = data.lpaddle.rleft;
lpaddle.rtop = data.lpaddle.rtop;
lpaddle.speed = data.lpaddle.speed;
}
if (data.rpaddle) {
rpaddle.rleft = data.rpaddle.rleft;
rpaddle.rtop = data.rpaddle.rtop;
rpaddle.speed = data.rpaddle.speed;
}
if (data.ball) {
ball.moving = data.ball.moving;
ball.rleft = data.ball.rleft;
ball.rtop = data.ball.rtop;
}
if (data.table) {
table.height = data.table.height;
table.width = data.table.width;
}
if (data.score) {
score.lwins = data.score.lwins;
score.rwins = data.score.rwins;
}
screen.render();
});
socket.data(['win'], function() {
rpaddle.movable = false;
score.rwins++;
text.setContent('Left player loses!');
message.show();
screen.render();
});
socket.data(['lose'], function() {
rpaddle.movable = false;
score.lwins++;
text.setContent('Right player loses!');
message.show();
screen.render();
});
socket.data(['reset'], reset);
reset();
}
/**
* Main
*/
function main() {
screen.on('keypress', function(ch, key) {
if (key.name === 'q' || key.name === 'escape') {
return process.exit(0);
}
});
screen.render();
// Demo Mode / Single Player
if (!nssocket || !process.argv[2]) return startGame();
// Server Mode
if (!process.argv[3]) return startServer();
// Client Mode
if (process.argv[2] && process.argv[3]) return startClient();
}
/**
* Execute
*/
main();

View File

@@ -0,0 +1,87 @@
var blessed = require('blessed')
, screen = blessed.screen();
var form = blessed.form({
parent: screen,
keys: true,
left: 0,
top: 0,
width: 30,
height: 4,
bg: 'green',
content: 'Submit or cancel?'
});
var submit = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 10,
top: 2,
shrink: true,
name: 'submit',
content: 'submit',
style: {
bg: 'blue',
focus: {
bg: 'red'
},
hover: {
bg: 'red'
}
}
});
var cancel = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 20,
top: 2,
shrink: true,
name: 'cancel',
content: 'cancel',
style: {
bg: 'blue',
focus: {
bg: 'red'
},
hover: {
bg: 'red'
}
}
});
submit.on('press', function() {
form.submit();
});
cancel.on('press', function() {
form.reset();
});
form.on('submit', function(data) {
form.setContent('Submitted.');
screen.render();
});
form.on('reset', function(data) {
form.setContent('Canceled.');
screen.render();
});
screen.key('q', function() {
process.exit(0);
});
screen.render();

1052
api.hyungi.net/node_modules/blessed/example/time.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

55
api.hyungi.net/node_modules/blessed/example/widget.js generated vendored Normal file
View File

@@ -0,0 +1,55 @@
var blessed = require('../');
// Create a screen object.
var screen = blessed.screen();
// Create a box perfectly centered horizontally and vertically.
var box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: 'Hello {bold}world{/bold}!',
tags: true,
border: {
type: 'line'
},
style: {
fg: 'white',
bg: 'magenta',
border: {
fg: '#ffffff'
},
hover: {
bg: 'green'
}
}
});
// Append our box to the screen.
screen.append(box);
// If our box is clicked, change the content.
box.on('click', function(data) {
box.setContent('{center}Some different {red-fg}content{/red-fg}.{/center}');
screen.render();
});
// If box is focused, handle `enter` and give us some more content.
box.key('enter', function() {
box.setContent('{right}Even different {black-fg}content{/black-fg}.{/right}\n');
box.setLine(1, 'bar');
box.insertLine(1, 'foo');
screen.render();
});
// Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
// Focus our element.
box.focus();
// Render the screen.
screen.render();