Skip to content

Commit

Permalink
Fix some of terminal resize issues (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Dec 7, 2019
1 parent a39e80b commit 6b4e725
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ 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]'}
let index = new Map()

// 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.
Expand All @@ -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))
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6b4e725

Please sign in to comment.