Fix some of terminal resize issues (#116)

js-version
Anton Medvedev 5 years ago committed by GitHub
parent a39e80b5b0
commit 6b4e7254c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

20
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()

Loading…
Cancel
Save