diff --git a/fx.js b/fx.js index 9487b73..faf06d6 100644 --- a/fx.js +++ b/fx.js @@ -164,7 +164,7 @@ module.exports = function start(filename, source) { search.on('submit', function (pattern) { let regex - const m = pattern.match(/^\/(.*)\/?([gimuy]*)$/) + let m = pattern.match(/^\/(.*)\/([gimuy]*)$/) if (m) { try { regex = new RegExp(m[1], m[2]) @@ -172,6 +172,14 @@ module.exports = function start(filename, source) { // Wrong regexp. } } + m = pattern.match(/^\/(.*)$/) + if (m) { + try { + regex = new RegExp(m[1], 'gi') + } catch (e) { + // Wrong regexp. + } + } highlight = regex if (highlight) { @@ -452,7 +460,13 @@ module.exports = function start(filename, source) { for (let [k, v] of index) { if (v === currentPath) { - const y = box.getScreenNumber(k) + let y = box.getScreenNumber(k) + + // Scroll one line up for better view and make sure it's not negative. + if (--y < 0) { + y = 0 + } + box.scrollTo(y) screen.render() } diff --git a/print.js b/print.js index 771ed61..1699f48 100644 --- a/print.js +++ b/print.js @@ -8,6 +8,7 @@ function print(input, options = {}) { let row = 0 function format(text, style, path) { + text = JSON.stringify(text) if (!highlight) { return style(text) } @@ -32,20 +33,20 @@ function print(input, options = {}) { } if (v === null) { - return format('null', config.null, path) + return format(v, config.null, path) } if (typeof v === 'number' && Number.isFinite(v)) { - return format(v.toString(), config.number, path) + return format(v, config.number, path) } if (typeof v === 'boolean') { - return format(v.toString(), config.boolean, path) + return format(v, config.boolean, path) } if (typeof v === 'string') { - return format(JSON.stringify(v), config.string, path) + return format(v, config.string, path) } if (Array.isArray(v)) { @@ -83,7 +84,7 @@ function print(input, options = {}) { output += eol() let i = 0 for (let [key, value] of entries) { - const part = format(JSON.stringify(key), config.key, path + '.' + key) + config.colon(':') + ' ' + doPrint(value, path + '.' + key) + const part = format(key, config.key, path + '.' + key) + config.colon(':') + ' ' + doPrint(value, path + '.' + key) output += indent(part, config.space) output += i++ < len - 1 ? config.comma(',') : '' output += eol()