mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-26 00:55:08 +01:00
added small help text system with simple formatting
This commit is contained in:
36
install/generator-cyphernode/generators/app/help.json
Normal file
36
install/generator-cyphernode/generators/app/help.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"features": "",
|
||||
"net": "",
|
||||
"username": "",
|
||||
"xpub": "",
|
||||
"derivation_path": "",
|
||||
"gatekeeper_clientkeyspassword": "",
|
||||
"gatekeeper_recreatekeys": "",
|
||||
"gatekeeper_edit_ipwhitelist": "",
|
||||
"gatekeeper_ipwhitelist": "",
|
||||
"gatekeeper_edit_apiproperties": "",
|
||||
"gatekeeper_apiproperties": "",
|
||||
"bitcoin_mode": "",
|
||||
"bitcoin_node_ip": "",
|
||||
"bitcoin_rpcuser": "",
|
||||
"bitcoin_rpcpassword": "",
|
||||
"bitcoin_prune": "",
|
||||
"bitcoin_uacomment": "",
|
||||
"lightning_implementation": "",
|
||||
"lightning_external_ip": "",
|
||||
"lightning_nodename": "",
|
||||
"lightning_nodecolor": "",
|
||||
"electrum_implementation": "",
|
||||
"proxy_datapath": "",
|
||||
"bitcoin_datapath": "",
|
||||
"lightning_datapath": "",
|
||||
"bitcoin_expose": "",
|
||||
"docker_mode": "",
|
||||
"__default__": "Lorem ipsum dolor sit amet,<br> consetetur <font color='#ff0000'>sadipscing elitr</font>, sed diam<br>nonumy eirmod tempor invidunt ut labore et <font italic='true'>dolore</font> magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
'use strict';
|
||||
const Generator = require('yeoman-generator');
|
||||
const chalk = require('chalk');
|
||||
const wrap = require('wrap-ansi');
|
||||
const html2ansi = require('./lib/html2ansi.js');
|
||||
const fs = require('fs');
|
||||
const validator = require('validator');
|
||||
const path = require("path");
|
||||
const featureChoices = require(path.join(__dirname, "features.json"));
|
||||
const coinstring = require('coinstring');
|
||||
const Archive = require('./lib/archive.js');
|
||||
const ApiKey = require('./lib/apikey.js');
|
||||
const help = require('./lib/help.js');
|
||||
|
||||
const featureChoices = require('./features.json');
|
||||
const uaCommentRegexp = /^[a-zA-Z0-9 \.,:_\-\?\/@]+$/; // TODO: look for spec of unsafe chars
|
||||
const userRegexp = /^[a-zA-Z0-9\._\-]+$/;
|
||||
|
||||
const reset = '\u001B8\u001B[u';
|
||||
const clear = '\u001Bc';
|
||||
|
||||
@@ -203,6 +203,10 @@ module.exports = class extends Generator {
|
||||
|
||||
this.props.enablehelp = r.enablehelp;
|
||||
|
||||
if( this.props.enablehelp ) {
|
||||
this.help = require('./help.json');
|
||||
}
|
||||
|
||||
let prompts = [];
|
||||
for( let m of prompters ) {
|
||||
prompts = prompts.concat(m.prompts(this));
|
||||
@@ -404,13 +408,18 @@ module.exports = class extends Generator {
|
||||
}
|
||||
|
||||
_getHelp( topic ) {
|
||||
if( !this.props.enablehelp )
|
||||
if( !this.props.enablehelp || !this.help ) {
|
||||
return '';
|
||||
const helpText = help.text( topic );
|
||||
}
|
||||
|
||||
// TODO: remove default later:
|
||||
const helpText = this.help[topic] || this.help['__default__'];
|
||||
|
||||
if( !helpText ||helpText === '' ) {
|
||||
return '';
|
||||
}
|
||||
return "\n\n"+helpText+"\n\n";
|
||||
|
||||
return "\n\n"+wrap( html2ansi(helpText),82 )+"\n\n";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
43
install/generator-cyphernode/generators/app/lib/html2ansi.js
Normal file
43
install/generator-cyphernode/generators/app/lib/html2ansi.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const parse5 = require('parse5');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const options = {
|
||||
scriptingEnabled: false
|
||||
}
|
||||
|
||||
const convert = function(data){
|
||||
|
||||
// recursively flatten
|
||||
let v = data.childNodes && data.childNodes.length?
|
||||
data.childNodes.map(d=> convert(d)).join(''):
|
||||
data.value?data.value:'';
|
||||
|
||||
switch(data.tagName){
|
||||
case 'br':
|
||||
v += '\n'
|
||||
break
|
||||
case 'font':
|
||||
if( data.attrs && data.attrs.length ) {
|
||||
for( let attr of data.attrs ) {
|
||||
if( attr.name === 'color' && /^#[a-f0-9]{6}$/.test(attr.value) ) {
|
||||
v = chalk.hex(attr.value)(v);
|
||||
}
|
||||
if( attr.name === 'bold' && attr.value === 'true' ) {
|
||||
v = chalk.bold(v);
|
||||
}
|
||||
if( attr.name === 'italic' && attr.value === 'true' ) {
|
||||
v = chalk.italic(v);
|
||||
}
|
||||
if( attr.name === 'strikethrough' && attr.value === 'true' ) {
|
||||
v = chalk.strikethrough(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
module.exports = function(html){
|
||||
return convert(parse5.parseFragment(html, options));
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
"@rauschma/stringio": "^1.4.0",
|
||||
"chalk": "^2.1.0",
|
||||
"coinstring": "^2.3.0",
|
||||
"parse5": "^5.1.0",
|
||||
"validator": "^10.8.0",
|
||||
"wrap-ansi": "^4.0.0",
|
||||
"yeoman-generator": "^2.0.1"
|
||||
|
||||
Reference in New Issue
Block a user