Skip to content

Commit

Permalink
Fix bug with synchronous reopening of tty on unix
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jan 30, 2019
1 parent 7501e5a commit 44d95c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _* Function eXecution_
[![Build Status](https://travis-ci.org/antonmedv/fx.svg?branch=master)](https://travis-ci.org/antonmedv/fx)
[![Npm Version](https://img.shields.io/npm/v/fx.svg)](https://www.npmjs.com/package/fx)
[![Brew Version](https://img.shields.io/homebrew/v/fx.svg)](https://formulae.brew.sh/formula/fx)
[![Snap Version](https://img.shields.io/badge/snap-11.0.0-blue.svg)](https://snapcraft.io/fx)
[![Snap Version](https://img.shields.io/badge/snap-12.0.0-blue.svg)](https://snapcraft.io/fx)

Command-line JSON processing tool

Expand Down
31 changes: 13 additions & 18 deletions fx.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'
const fs = require('fs')
const tty = require('tty')
const blessed = require('@medv/blessed')
const stringWidth = require('string-width')
const reopenTTY = require('reopen-tty')
const reduce = require('./reduce')
const print = require('./print')
const find = require('./find')
Expand All @@ -25,30 +26,24 @@ module.exports = function start(filename, source) {
let findGen = null
let currentPath = null

// Reopen tty
let ttyReadStream
let ttyWriteStream
reopenTTY.stdin(function (err, readStream) {
if (err) {
throw err
} else {
ttyReadStream = readStream
}
})

reopenTTY.stdout(function (err, writeStream) {
if (err) {
throw err
} else {
ttyWriteStream = writeStream
}
})
if (process.platform === 'win32') {
const cfs = process.binding('fs')
ttyReadStream = tty.ReadStream(cfs.open('conin$', fs.constants.O_RDWR | fs.constants.O_EXCL, 0o666))
ttyWriteStream = tty.WriteStream(cfs.open('conout$', fs.constants.O_RDWR | fs.constants.O_EXCL, 0o666))
} else {
const ttyFd = fs.openSync('/dev/tty', 'r+')
ttyReadStream = tty.ReadStream(ttyFd)
ttyWriteStream = tty.WriteStream(ttyFd)
}

const program = blessed.program({
input: ttyReadStream,
output: ttyWriteStream
output: ttyWriteStream,
})


const screen = blessed.screen({
program: program,
smartCSR: true,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "ava",
"build": "pkg . --out-path dist -t node8-linux-x64,node8-macos-x64,node8-win-x64",
"zip": "cd dist && find . -name 'fx-*' -exec zip '{}.zip' '{}' \\;",
"release": "npm run build && npm run zip && release-it --github.release --github.assets=dist/*.zip"
"release": "rm -rf ./dist && npm run build && npm run zip && release-it --github.release --github.assets=dist/*.zip"
},
"keywords": [
"json",
Expand All @@ -40,7 +40,6 @@
"@medv/blessed": "^2.0.0",
"chalk": "^2.4.2",
"indent-string": "^3.2.0",
"reopen-tty": "^1.1.2",
"string-width": "^3.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 44d95c6

Please sign in to comment.