add example and minimal tests of blessed project-name generator, charlatan libraries

This commit is contained in:
lee2sman 2021-03-27 22:37:31 -04:00
parent 256b79e01b
commit 2d5f5a36e2
18 changed files with 340 additions and 272 deletions

View File

@ -982,3 +982,252 @@
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-12
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-13
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14
2021-2-14

View File

@ -1 +1 @@
{"position":{"x":10,"y":3},"avatar":"👳","movedToday":false,"life":24}
{"position":{"x":4,"y":0},"avatar":"@","movedToday":false,"life":24}

View File

@ -1 +1 @@
[{"name":"","symbol":"","description":"A breadbox that's bigger than a breadbox","position":{"x":7,"y":2}},{"name":" Safe Star","symbol":"📘","description":"Mainly dealing with Helpless Blow. Several pages have been torn out.\n By Zion Wehner.","position":{"x":1,"y":4}}]
[{"name":"","symbol":"h","description":"A breadbox that's bigger than a breadbox","position":{"x":31,"y":6}},{"name":"My Milky Sheet of Gray Gun","symbol":"⏍","description":"Probably the most complete book on Milky Sheet. Second edition.\n By Shirley Hagenes.","position":{"x":10,"y":2}},{"name":"A Cook's Guide to Furry Flowers","symbol":"⎅","description":"A turgid tale of Brawny Yak. It's rotting\n By Ms. Abdiel Ledner.","position":{"x":32,"y":6}}]

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@ advising
annoying
baking
bathing
behaveing
behaving
linking
oiling
breathing

27
examples/README.md Normal file
View File

@ -0,0 +1,27 @@
# Example tests
To use these examples you'll need to install the node.js libraries they rely on: blessed, charlatan and project-name-generator
Usage:
```
node keypress-blessed
```
### Blessed screen drawing library
keypress-blessed.js - This is a minimal (or as minimal as I could wrangle) example of using the blessed library for terminal screen drawing. It is capable of detecting keypresses, then redrawing over the entire screen and printing out whether you pressed any arrow key or directional vim-key. Or press 'q' to quit. And that's it!
example-blessed.js - This is the example program for Blessed. copyright 2013, Christopher Jeffrey (MIT License).
### Charlatan to generate names
create-graves.js - Charlatan is a node.js library for text generation with a focus on generating fake user data. create-graves.js is a minimal example of generating an epitaph, using node.js's built-in fs filesystem to ingest a hidden text file of verbs and Charlatan to generate a name, and then some simple madlibs-style parsing to generate the epitaph.
example-charlatan.js is the 'hello world' of using the charlatan library.
### project-name-generator to generate some random words for a title
createtown.js. - project-name-generator is a node.js library for generator heroku-style project names (a number of words in a row, separated by spaces, hyphens or a comma-separated list). In create-town.js I generate 3 to 6 example tiny village names, with an additional function to capitalize words.
generate-book-title.js - This is a minimal example to generate a book title. It doesn't have capitalization, but that could be added (see createtown.js).

View File

@ -7,7 +7,6 @@ let pre = ["My Year of","A Guide To","Simply","A Cook's Guide to","The Book of",
let connector = [" of"," for"," for"," with"," and"," on",":",": on"," OR"];
let choose = arr => arr[Math.floor(Math.random()*arr.length)];
let book;
if (Math.random()<0.4){
@ -17,4 +16,5 @@ if (Math.random()<0.4){
} else {
book = choose(pre) + " " + secondSubject;
}
console.log(book);
console.log(book);

View File

@ -0,0 +1,58 @@
//'minimal' blessed example
//detects keypresses (arrow keys or vim-keys) or 'q' to quit
//does not move cursor but shows it on screen
const blessed = require('blessed')
, program = blessed.program();
process.title = 'blessed';
program.on('keypress', function(ch, key) {
program.clear();
program.bg('red');
switch(key.name) {
case 'q':
program.disableMouse();
program.showCursor();
program.normalBuffer();
process.exit(0);
//reminder: listing two cases without a break between makes them work like an OR operator
case 'right': //vim key 'l' or right-arrow
case 'l':
program.write('moved right');
break;
case 'left': //vim key 'h' OR left-arrow
case 'h':
program.write('moved left');
break;
case 'up': //vim key 'k' or up-arrow
case 'k':
program.write('moved up');
break;
case 'down': //vim key 'j' or down-arrow
case 'j':
program.write('moved down');
break;
default: //else
program.write('hit another key');
}
program.bg('!red');
});
program.alternateBuffer();
//program.enableMouse();
//program.hideCursor();
program.clear();
program.move(1, 1);
program.bg('green');
program.write('Hello world', 'red fg');
program.setx((program.cols / 4 | 0) );
program.down(5);
program.write('Test direction keys (vim or arrow keys)!');
program.bg('!black');
program.feed();

View File

View File

@ -1,71 +0,0 @@
var blessed = require('blessed');
// Create a screen object.
var screen = blessed.screen({
smartCSR: true
});
screen.title = 'my window title';
// 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: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
// Append our box to the screen.
screen.append(box);
// Add a png icon to the box
var icon = blessed.image({
parent: box,
top: 0,
left: 0,
type: 'overlay',
width: 'shrink',
height: 'shrink',
file: __dirname + '/my-program-icon.png',
search: false
});
// 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`/`return` and give us some more content.
box.key('enter', function(ch, key) {
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();

View File

@ -1,67 +0,0 @@
//source: https://recodes.co/being-blessed/
// Require the Blessed API.
var Blessed = require('blessed');
// Initialize the screen widget.
var screen = Blessed.screen({
// Example of optional settings:
smartCSR: true,
useBCE: true,
cursor: {
artificial: true,
blink: true,
shape: 'underline'
},
log: `${__dirname}/application.log`,
debug: true,
dockBorders: true
});
// Specify the title of the application.
screen.title = 'La pizza de Don Cangrejo.';
// Creating a textarea on the bottom of the screen.
var input = Blessed.textarea({
bottom: 0,
height: 3,
inputOnFocus: true,
padding: {
top: 1,
left: 2
},
style: {
fg: '#787878',
bg: '#454545',
focus: {
fg: '#f6f6f6',
bg: '#353535'
}
}
});
// Append the widget to the screen.
screen.append(input);
// Render the screen.
screen.render();
// Quit on `q`, or `Control-C` when the focus is on the screen.
screen.key(['q', 'C-c'], function(ch, key) {
process.exit(0);
});
// Focus on `escape` or `i` when focus is on the screen.
screen.key(['escape', 'i'], function() {
// Set the focus on the input.
input.focus();
});
// If box is focused, handle `Control+s`.
input.key('C-s', function(ch, key) {
var message = this.getValue();
// Send the message somehow.
this.clearValue();
screen.render();
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -1,88 +0,0 @@
var fs = require('fs');
var blessed = require('blessed');
let dungeon;
const descriptionsFile = "../.nonKittenItems.txt";
let itemDescriptions = fs.readFileSync(descriptionsFile).toString().split("\n");
let loadDungeon = () => {
const dungeonInput = fs.readFileSync(".dungeonfile.txt",'utf8')
dungeon = dungeonInput.split("\n");
}
loadDungeon();
// Create a screen object.
var screen = blessed.screen({
smartCSR: true
});
screen.title = 'my window title';
// Create a box perfectly centered horizontally and vertically.
var box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: dungeon[0],
tags: true,
border: {
type: 'line'
},
style: {
fg: 'cyan',
bg: 'white',
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
// Append our box to the screen.
screen.append(box);
// Add a png icon to the box
var icon = blessed.image({
parent: box,
top: 0,
left: 0,
type: 'overlay',
width: 'shrink',
height: 'shrink',
file: __dirname + '/my-program-icon.png',
search: false
});
// If our box is clicked, change the content.
box.on('click', function(data) {
screen.render();
});
// If box is focused, handle `enter`/`return` and give us some more content.
box.key('enter', function(ch, key) {
for (let i = 0; i < dungeon.length; i++){
box.setLine(i, dungeon[i]);
}
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();

View File

@ -1,40 +0,0 @@
var blessed = require('blessed')
, 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.alternateBuffer();
//program.enableMouse();
program.hideCursor();
program.clear();
program.move(1, 1);
program.bg('#0000ff');
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);
});