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

View File

@ -414,13 +414,30 @@ var LoggerActions = actions.Actions({
Logger: object.Constructor('BaseLogger', {
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,
get context(){
return this.__context || this.root.__context },
root: null,
get isRoot(){
return this === this.root },
@ -520,7 +537,8 @@ var LoggerActions = actions.Actions({
// .push(str, ..., attrs)
//
push: function(...msg){
attrs = typeof(msg.last()) != typeof('str') ?
// settings...
var attrs = typeof(msg.last()) != typeof('str') ?
msg.pop()
: {}
return msg.length == 0 ?
@ -530,6 +548,7 @@ var LoggerActions = actions.Actions({
attrs,
{
root: this.root,
parent: this,
path: this.path.concat(msg),
}) },
pop: function(){
@ -579,7 +598,8 @@ var LoggerActions = actions.Actions({
// XXX move this to console-logger???
handleLogItem: ['- System/',
function(logger, path, status, ...rest){
logger.quiet
logger.quiet
|| logger.root.quiet
|| console.log(
path.join(': ') + (path.length > 0 ? ': ' : '')
+ status

View File

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