print-tools-js
Advanced tools
Comparing version 1.0.9 to 1.1.0
@@ -36,2 +36,7 @@ var COLS, assert, escRepl, p, presetTest, should, styleTest; | ||
}); | ||
it('Proper length - timestamp overlap', function() { | ||
return (escRepl(func.bind(p)('*'.repeat(process.stdout.columns - 3), { | ||
ret: true | ||
})).length % COLS).should.equal(0); | ||
}); | ||
it('Proper length with args', function() { | ||
@@ -52,2 +57,10 @@ return escRepl(func.bind(p)('Test', { | ||
}); | ||
it('Proper length without log - timestamp overlap', function() { | ||
return (escRepl(func.bind(p)('*'.repeat(process.stdout.columns - 3), { | ||
ret: true, | ||
log: false, | ||
dec: 'arrow', | ||
indent: 2 | ||
})).length % COLS).should.equal(0); | ||
}); | ||
return it('Contains preset characters', function() { | ||
@@ -80,2 +93,7 @@ return assert.equal(func.bind(p)('Test', { | ||
}); | ||
it('Proper length - timestamp overlap', function() { | ||
return (escRepl(func.bind(p)('*'.repeat(process.stdout.columns - 3), { | ||
ret: true | ||
})).length % COLS).should.equal(0); | ||
}); | ||
it('Proper length with args', function() { | ||
@@ -94,2 +112,9 @@ return escRepl(func.bind(p)('Test', { | ||
}); | ||
it('Proper length without log - timestamp overlap', function() { | ||
return escRepl(func.bind(p)('*'.repeat(process.stdout.columns * 2 - 3), { | ||
ret: true, | ||
log: false, | ||
indent: 2 | ||
})).length.should.equal(`${styleChar} ${'*'.repeat(process.stdout.columns * 2 - 3)}`.length); | ||
}); | ||
return it('Contains preset characters', function() { | ||
@@ -157,2 +182,7 @@ return assert.equal(func.bind(p)('Test', { | ||
}); | ||
it('Proper length - timestamp overlap', function() { | ||
return (escRepl(p.log('*'.repeat(process.stdout.columns - 3), { | ||
ret: true | ||
})).length % COLS).should.equal(0); | ||
}); | ||
it('Proper length with emoji', function() { | ||
@@ -159,0 +189,0 @@ return escRepl(p.log('Test', { |
@@ -87,3 +87,3 @@ var Print, box, chalk, dateFormat, dec, decArgs, emoji, getEmote, logOrReturn, presetArgs, printDecoration, printPreset; | ||
}) { | ||
var cols, emote, output, space, time; | ||
var cols, emote, extLen, offsetLen, output, space, textLen, textLenMod, time; | ||
if (args.ret == null) { | ||
@@ -101,6 +101,18 @@ args.ret = false; | ||
time = chalk.gray(dateFormat(new Date(), 'HH:MM:ss')); | ||
if ((cols - text.replace(/\u001b\[.*?m/g, '').length - emote.length - time.replace(/\u001b\[.*?m/g, '').length - 1 - args.offset) < 0 && args.offset > 0) { | ||
args.offset -= 1; | ||
textLen = text.replace(/\u001b\[.*?m/g, '').length; | ||
textLenMod = textLen % cols; | ||
extLen = emote.length + time.replace(/\u001b\[.*?m/g, '').length + 1 + args.offset; | ||
offsetLen = cols - textLen - extLen; | ||
if (offsetLen < 0 && args.offset > 0) { | ||
extLen -= 1; | ||
} | ||
space = ' '.repeat(cols - (text.replace(/\u001b\[.*?m/g, '').length % cols) - emote.length - time.replace(/\u001b\[.*?m/g, '').length - 1 - args.offset); | ||
if ((cols - textLenMod - extLen) > 0) { | ||
space = ' '.repeat(cols - textLenMod - extLen); | ||
} else { | ||
if (offsetLen === 0) { | ||
space = ' '.repeat(cols + (cols - textLenMod - extLen) + 1); | ||
} else { | ||
space = ' '.repeat(cols + (cols - textLenMod - extLen)); | ||
} | ||
} | ||
output = `${text}${space}${emote} ${time}`; | ||
@@ -182,3 +194,3 @@ return logOrReturn(output, args.ret); | ||
printPreset = function(obj, text, presetText, emojiText, defaultOffset, args) { | ||
var cols, emote, output, space, styleMethods; | ||
var cols, emote, extLen, offsetLen, output, space, styleMethods, textLen, textLenMod; | ||
args = presetArgs(args, defaultOffset); | ||
@@ -213,6 +225,18 @@ output = `${presetText} ${text}`; | ||
cols = process.stdout.columns; | ||
if ((cols - output.replace(/\u001b\[.*?m/g, '').length - emote.length - args.offset) < 0 && args.offset > 0) { | ||
args.offset -= 1; | ||
textLen = output.replace(/\u001b\[.*?m/g, '').length; | ||
textLenMod = textLen % cols; | ||
extLen = emote.length + args.offset; | ||
offsetLen = cols - textLen - extLen; | ||
if (offsetLen < 0 && args.offset > 0) { | ||
extLen -= 1; | ||
} | ||
space = ' '.repeat(cols - (output.replace(/\u001b\[.*?m/g, '').length % cols) - emote.length - args.offset); | ||
if ((cols - textLenMod - extLen) > 0) { | ||
space = ' '.repeat(cols - textLenMod - extLen); | ||
} else { | ||
if (offsetLen === 0) { | ||
space = ' '.repeat(cols + (cols - textLenMod - extLen) + 1); | ||
} else { | ||
space = ' '.repeat(cols + (cols - textLenMod - extLen)); | ||
} | ||
} | ||
output = `${output}${space}${emote}`; | ||
@@ -219,0 +243,0 @@ return logOrReturn(output, args.ret); |
{ | ||
"name": "print-tools-js", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"description": "Easy-to-use console logging presets and formatting", | ||
@@ -5,0 +5,0 @@ "main": "./js/index.js", |
17818
483