mirror of
https://github.com/antonmedv/fx
synced 2024-11-03 15:40:12 +00:00
Separate regexp generation
This commit is contained in:
parent
935857230d
commit
beedbfd36a
18
fx.js
18
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()
|
||||
}
|
||||
|
11
print.js
11
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()
|
||||
|
Loading…
Reference in New Issue
Block a user