Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some of terminal resize issues #116

Merged
merged 2 commits into from
Dec 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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