neo-blessed/test/widget-unicode.js

112 lines
2.7 KiB
JavaScript
Raw Normal View History

2015-05-02 00:52:20 +00:00
var fs = require('fs')
, blessed = require('../')
, unicode = blessed.unicode;
2015-05-02 00:52:20 +00:00
var screen = blessed.screen({
dump: __dirname + '/logs/unicode.log',
smartCSR: true,
dockBorders: true,
2015-04-16 21:38:36 +00:00
useBCE: true,
2015-07-22 02:23:57 +00:00
fullUnicode: ~process.argv.indexOf('-') ? false : true,
warnings: true
});
2015-05-02 00:52:20 +00:00
/**
* Unicode Characters
*/
2015-04-26 12:36:30 +00:00
// var DU = '杜';
var DU = unicode.fromCodePoint(0x675C);
2015-04-26 12:36:30 +00:00
// var JUAN = '鹃';
var JUAN = unicode.fromCodePoint(0x9E43);
// one flew over the 杜鹃's nest.
2015-04-26 12:36:30 +00:00
// var DOUBLE = '杜鹃';
var DOUBLE = DU + JUAN;
// var SURROGATE_DOUBLE = '𰀀';
// var SURROGATE_DOUBLE = String.fromCharCode(0xD880, 0xDC00);
// var SURROGATE_DOUBLE = unicode.fromCodePoint(0x30000);
// var SURROGATE_DOUBLE = '𠀀';
// var SURROGATE_DOUBLE = String.fromCharCode(0xd840, 0xdc00);
var SURROGATE_DOUBLE = unicode.fromCodePoint(0x20000);
// var SURROGATE_DOUBLE = '🉐';
// var SURROGATE_DOUBLE = String.fromCharCode(0xD83C, 0xDE50);
// var SURROGATE_DOUBLE = unicode.fromCodePoint(0x1F250);
2015-04-26 12:36:30 +00:00
// var SURROGATE_SINGLE = '𝌆';
// var SURROGATE_SINGLE = String.fromCharCode(0xD834, 0xDF06);
var SURROGATE_SINGLE = unicode.fromCodePoint(0x1D306);
2015-04-26 12:36:30 +00:00
// var COMBINE_NONSURROGATE = 's̀'.substring(1); // s + combining
var COMBINE_NONSURROGATE = unicode.fromCodePoint(0x0300);
2015-04-26 12:36:30 +00:00
// var COMBINE = 's𐨁'.substring(1); // s + combining
// var COMBINE = String.fromCharCode(0xD802, 0xDE01);
var COMBINE = unicode.fromCodePoint(0x10A01);
2015-05-02 00:52:20 +00:00
/**
* Content
*/
var lorem = fs.readFileSync(__dirname + '/lorem.txt', 'utf8');
lorem = lorem.replace(/e/gi, DOUBLE);
//lorem = lorem.replace(/e/gi, DU);
//lorem = lorem.replace(/r/gi, JUAN);
lorem = lorem.replace(/a/gi, SURROGATE_DOUBLE);
lorem = lorem.replace(/o/gi, SURROGATE_SINGLE);
if (~process.argv.indexOf('s')) {
lorem = lorem.replace(/s/gi, 's' + COMBINE);
2015-05-02 00:52:20 +00:00
} else {
lorem = lorem.replace('s', 's' + COMBINE);
}
// Surrogate pair emoticons from the SMP:
lorem += '\n';
lorem += 'emoticons: ';
for (var point = 0x1f600; point <= 0x1f64f; point++) {
// These are technically single-width,
// but they _look_ like they should be
// double-width in gnome-terminal (they overlap).
var emoticon = unicode.fromCodePoint(point);
lorem += emoticon + ' ';
}
2015-05-02 00:52:20 +00:00
/**
* UI
*/
var main = blessed.box({
parent: screen,
left: 'center',
top: 'center',
width: '50%',
height: '50%',
style: {
2015-05-02 00:52:20 +00:00
bg: 'grey'
},
border: 'line',
draggable: true,
tags: true,
2015-04-26 12:51:56 +00:00
// content: '{black-bg}{blue-fg}{bold}' + lorem + '{/}',
// XXX {bold} breaks JUAN!
content: '{black-bg}{light-blue-fg}' + lorem + '{/}',
scrollable: true,
alwaysScroll: true,
keys: true,
vi: true,
mouse: true
});
main.focus();
screen.key('q', function() {
return process.exit(0);
});
screen.render();