working on logging in cli...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-09 03:53:57 +03:00
parent dafeedbaaf
commit 040f3a7e3a
3 changed files with 58 additions and 14 deletions

View File

@ -64,8 +64,12 @@ var CLIActions = actions.Actions({
__progress: null, __progress: null,
showProgress: ['- System/', showProgress: ['- System/',
function(text, value, max){ function(text, value, max){
var msg = text instanceof Array ? text.slice(1).join(': ') : null var msg = text instanceof Array ?
text = text instanceof Array ? text[0] : text text.slice(1).join(': ')
: null
text = text instanceof Array ?
text[0]
: text
var state = this.__progress = this.__progress || {} var state = this.__progress = this.__progress || {}
state = state[text] = state[text] || {} state = state[text] = state[text] || {}
@ -86,16 +90,20 @@ var CLIActions = actions.Actions({
msg = msg ? ': '+msg : '' msg = msg ? ': '+msg : ''
msg = ' '+ msg msg = ' '+ msg
//+ (value && value >= (max || 0) ? ' ('+value+' done)' //+ (value && value >= (max || 0) ? ' ('+value+' done)'
+ (value && value >= (max || 0) ? ' (done)' + (value && value >= (max || 0) ?
: value && max && value != max ? ' ('+ value +' of '+ max +')' ' (done)'
: value && max && value != max ?
' ('+ value +' of '+ max +')'
: '...') : '...')
// XXX do a better printout -- ncurses???
msg != state.msg msg != state.msg
&& console.log(msg) && console.log(text + msg)
state.msg = msg state.msg = msg
}], }],
startREPL: ['- System/Start CLI interpreter', startREPL: ['- System/Start CLI interpreter',
{cli: '@repl'}, {cli: '@repl'},
function(){ function(){
@ -127,6 +135,7 @@ var CLIActions = actions.Actions({
.on('exit', function(){ .on('exit', function(){
//ig.stop() //ig.stop()
process.exit() }) }], process.exit() }) }],
// XXX
startGUI: ['- System/Start viewer GUI', startGUI: ['- System/Start viewer GUI',
{cli: '@gui'}, {cli: '@gui'},
function(){ function(){
@ -134,6 +143,8 @@ var CLIActions = actions.Actions({
}], }],
// XXX this is reletively generic, might be useful globally... // XXX this is reletively generic, might be useful globally...
// XXX add support for cwd and relative paths...
// XXX should we use a clean index or do this in-place???
makeIndex: ['- System/Make index', makeIndex: ['- System/Make index',
{cli: { {cli: {
name: '@make', name: '@make',
@ -144,8 +155,8 @@ var CLIActions = actions.Actions({
var that = this var that = this
path = util.normalizePath(path) path = util.normalizePath(path)
// XXX is cloning index here the correct way to go??? // XXX should we use a clean index or do this in-place???
//var index = this.clone() //var index = this.constructor()
var index = this var index = this
return index.loadImages(path) return index.loadImages(path)
// save base index... // save base index...
@ -184,6 +195,13 @@ module.CLI = core.ImageGridFeatures.Feature({
actions: CLIActions, actions: CLIActions,
handlers: [ handlers: [
// supress logging by default...
['start.pre',
function(){
this.logger
&& (this.logger.quiet = true) }],
// handle args...
['ready', ['ready',
function(){ function(){
var that = this var that = this
@ -197,6 +215,12 @@ module.CLI = core.ImageGridFeatures.Feature({
version: pkg.version, version: pkg.version,
license: pkg.license, license: pkg.license,
'-verbose': {
doc: 'Enable verbose output',
handler: function(){
that.logger
&& (that.logger.quiet = false) } },
// XXX setup presets... // XXX setup presets...
// ...load sets of features and allow user // ...load sets of features and allow user
// to block/add specific features... // to block/add specific features...

View File

@ -414,13 +414,30 @@ var LoggerActions = actions.Actions({
Logger: object.Constructor('BaseLogger', { Logger: object.Constructor('BaseLogger', {
doc: `Logger object constructor...`, doc: `Logger object constructor...`,
quiet: false, root: null,
parent: null,
// Quiet mode...
//
// NOTE: if local mode is not defined this will get the mode of
// the nearest parent...
// XXX need these to be persistent...
// XXX add support for log levels...
__quiet: null,
get quiet(){
var cur = this
while(cur.__quiet == null && cur.parent){
cur = cur.parent }
return !!cur.__quiet },
set quiet(value){
value == null ?
(delete this.__quiet)
: (this.__quiet = !!value) },
__context: null, __context: null,
get context(){ get context(){
return this.__context || this.root.__context }, return this.__context || this.root.__context },
root: null,
get isRoot(){ get isRoot(){
return this === this.root }, return this === this.root },
@ -520,7 +537,8 @@ var LoggerActions = actions.Actions({
// .push(str, ..., attrs) // .push(str, ..., attrs)
// //
push: function(...msg){ push: function(...msg){
attrs = typeof(msg.last()) != typeof('str') ? // settings...
var attrs = typeof(msg.last()) != typeof('str') ?
msg.pop() msg.pop()
: {} : {}
return msg.length == 0 ? return msg.length == 0 ?
@ -530,6 +548,7 @@ var LoggerActions = actions.Actions({
attrs, attrs,
{ {
root: this.root, root: this.root,
parent: this,
path: this.path.concat(msg), path: this.path.concat(msg),
}) }, }) },
pop: function(){ pop: function(){
@ -580,6 +599,7 @@ var LoggerActions = actions.Actions({
handleLogItem: ['- System/', handleLogItem: ['- System/',
function(logger, path, status, ...rest){ function(logger, path, status, ...rest){
logger.quiet logger.quiet
|| logger.root.quiet
|| console.log( || console.log(
path.join(': ') + (path.length > 0 ? ': ' : '') path.join(': ') + (path.length > 0 ? ': ' : '')
+ status + status

View File

@ -58,7 +58,7 @@ var IndexFormatActions = actions.Actions({
// XXX should these be 'p' or 'px' (current)??? // XXX should these be 'p' or 'px' (current)???
'preview-sizes': [ 'preview-sizes': [
//75, //75,
//200, 200,
480, 480,
//900, //900,
1080, 1080,
@ -66,8 +66,8 @@ var IndexFormatActions = actions.Actions({
//2160, //2160,
], ],
'preview-sizes-priority': [ 'preview-sizes-priority': [
75, //75,
200, //200,
1080, 1080,
], ],