Skip to content
Permalink
Browse files

Show status bar if pattern not found

  • Loading branch information...
antonmedv committed Dec 15, 2018
1 parent 225239b commit ef77520f99bc7b403fc8a00324ee8687de58d863
Showing with 45 additions and 1 deletion.
  1. +1 −0 config.js
  2. +44 −1 fx.js
@@ -22,4 +22,5 @@ module.exports = {
list: global.FX_STYLE_LIST || list,
highlight: global.FX_STYLE_HIGHLIGHT || chalk.black.bgYellow,
highlightCurrent: global.FX_STYLE_HIGHLIGHT_CURRENT || chalk.inverse,
statusBar: global.FX_STYLE_STATUS_BAR || chalk.inverse,
}
45 fx.js
@@ -69,6 +69,15 @@ module.exports = function start(filename, source) {
width: '100%',
})

const statusBar = blessed.box({
parent: screen,
tags: false,
bottom: 0,
left: 0,
height: 1,
width: '100%',
})

const autocomplete = blessed.list({
parent: screen,
width: 6,
@@ -82,6 +91,7 @@ module.exports = function start(filename, source) {
box.focus()
input.hide()
search.hide()
statusBar.hide()
autocomplete.hide()

screen.key(['escape', 'q', 'C-c'], function () {
@@ -189,6 +199,7 @@ module.exports = function start(filename, source) {
})

box.key('.', function () {
hideStatusBar()
box.height = '100%-1'
input.show()
if (input.getValue() === '') {
@@ -200,6 +211,7 @@ module.exports = function start(filename, source) {
})

box.key('/', function () {
hideStatusBar()
box.height = '100%-1'
search.show()
search.setValue('/')
@@ -208,12 +220,14 @@ module.exports = function start(filename, source) {
})

box.key('e', function () {
hideStatusBar()
expanded.clear()
walk(json, path => expanded.size < 1000 && expanded.add(path))
render()
})

box.key('S-e', function () {
hideStatusBar()
expanded.clear()
expanded.add('')
render()
@@ -236,10 +250,12 @@ module.exports = function start(filename, source) {
})

box.key('n', function () {
hideStatusBar()
findNext()
})

box.key(['up', 'k'], function () {
hideStatusBar()
program.showCursor()
let rest = [...index.keys()]

@@ -264,6 +280,7 @@ module.exports = function start(filename, source) {
})

box.key(['down', 'j'], function () {
hideStatusBar()
program.showCursor()
let rest = [...index.keys()]

@@ -288,6 +305,7 @@ module.exports = function start(filename, source) {
})

box.key(['right', 'l'], function () {
hideStatusBar()
const [n, line] = getLine(program.y)
program.showCursor()
program.cursorPos(program.y, line.search(/\S/))
@@ -299,6 +317,7 @@ module.exports = function start(filename, source) {
})

box.key(['left', 'h'], function () {
hideStatusBar()
const [n, line] = getLine(program.y)
program.showCursor()
program.cursorPos(program.y, line.search(/\S/))
@@ -310,6 +329,7 @@ module.exports = function start(filename, source) {
})

box.on('click', function (mouse) {
hideStatusBar()
const [n, line] = getLine(mouse.y)
if (mouse.x >= stringWidth(line)) {
return
@@ -328,6 +348,10 @@ module.exports = function start(filename, source) {
render()
})

box.on('scroll', function () {
hideStatusBar()
})

function getLine(y) {
const dy = box.childBase + y
const n = box.getNumber(dy)
@@ -465,8 +489,13 @@ module.exports = function start(filename, source) {
if (!findGen) {
return
}

const {value: path, done} = findGen.next()
if (!done) {

if (done) {
showStatusBar('Pattern not found')
} else {

currentPath = ''
for (let p of path) {
expanded.add(currentPath += p)
@@ -489,6 +518,20 @@ module.exports = function start(filename, source) {
}
}

function showStatusBar(status) {
statusBar.show()
statusBar.setContent(config.statusBar(` ${status} `))
screen.render()
}

function hideStatusBar() {
if (!statusBar.hidden) {
statusBar.hide()
statusBar.setContent('')
screen.render()
}
}

function render() {
let content
[content, index] = print(json, {expanded, highlight, currentPath})

0 comments on commit ef77520

Please sign in to comment.
You can’t perform that action at this time.