diff --git a/fx.js b/fx.js index 6bf547f..9313720 100644 --- a/fx.js +++ b/fx.js @@ -8,9 +8,9 @@ const print = require('./print') const find = require('./find') const config = require('./config') -module.exports = function start(filename, source) { +module.exports = function start(filename, source, prev = {}) { // Current rendered object on a screen. - let json = source + let json = prev.json || source // Contains map from row number to expand path. // Example: {0: '', 1: '.foo', 2: '.foo[0]'} @@ -18,7 +18,7 @@ module.exports = function start(filename, source) { // Contains expanded paths. Example: ['', '.foo'] // Empty string represents root path. - const expanded = new Set() + const expanded = prev.expanded || new Set() expanded.add('') // Current filter code. @@ -29,9 +29,9 @@ module.exports = function start(filename, source) { let findGen = null let currentPath = null + let ttyReadStream, ttyWriteStream + // Reopen tty - let ttyReadStream - let ttyWriteStream if (process.platform === 'win32') { const cfs = process.binding('fs') ttyReadStream = tty.ReadStream(cfs.open('conin$', fs.constants.O_RDWR | fs.constants.O_EXCL, 0o666)) @@ -109,15 +109,17 @@ module.exports = function start(filename, source) { statusBar.hide() autocomplete.hide() + process.stdout.on('resize', () => { + screen.destroy() + program.destroy() + start(filename, source, {json, expanded}) + }) + screen.key(['escape', 'q', 'C-c'], function () { program.disableMouse() // If exit program immediately, stdin may still receive setTimeout(() => process.exit(0), 10) // mouse events which will be printed in stdout. }) - screen.on('resize', function () { - render() - }) - input.on('submit', function () { if (autocomplete.hidden) { const code = input.getValue()