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

Disable input handling in a non-tty environment #40

Closed
thetoxicavenger opened this issue Aug 25, 2017 · 9 comments
Closed

Disable input handling in a non-tty environment #40

thetoxicavenger opened this issue Aug 25, 2017 · 9 comments
Labels

Comments

@thetoxicavenger
Copy link

/node_modules/ink/index.js:61

Never seen this one before and googling didn't help much - what's going on here? It's preventing me from running this example from your docs:

`const {h, render, Component} = require('ink');

class Counter extends Component {
constructor() {
super();

	this.state = {
		i: 0
	};
}

render(props, state) {
	return `Iteration #${state.i}`;
}

componentDidMount() {
	this.timer = setInterval(() => {
		this.setState({
			i: this.state.i + 1
		});
	}, 100);
}

componentWillUnmount() {
	clearInterval(this.timer);
}

}

const unmount = render();

setTimeout(() => {
// Enough counting
unmount();
}, 1000);`

@vadimdemedes
Copy link
Owner

What Node.js version are you on?

@thetoxicavenger
Copy link
Author

thetoxicavenger commented Aug 27, 2017 via email

@zachary95
Copy link
Contributor

zachary95 commented Sep 30, 2017

This happened when I tried to launch my Ink app on WebStorm IDE, even more while using node inspect index.js

I think this error happen when you're trying to run a ink app in a non-tty env such debuggers or some IDE terminal.

(I'm on Node v8.6.0, latest)

@vadimdemedes
Copy link
Owner

Yes, I think it happens only in non-tty env, which I guess there's no way to enable interactive input. Possible solution for this would be to just disable the input altogether.

@zachary95
Copy link
Contributor

zachary95 commented Sep 30, 2017

I've just been looking at it and making a conditional to see if current env is TTY.

readline.emitKeypressEvents(stdin);

if (stdin.isTTY) { // < this
  stdin.setRawMode(true);
}

And it worked, it's now working on both debugger, WebStorm IDE and regular terminal (iTerm). Should I make a PR for this fix?

I'm looking futher to see if I can make a better fix.

@vadimdemedes
Copy link
Owner

Sure, a PR would be great, thanks! I'd completely disable all handling of stdin, not just setRawMode(), but also in render() and exit() in index.js.

@vadimdemedes vadimdemedes changed the title stdin.setRawMode is not a function Disable input handling in a non-tty env Sep 30, 2017
@vadimdemedes vadimdemedes changed the title Disable input handling in a non-tty env Disable input handling in a non-tty environment Sep 30, 2017
@vadimdemedes
Copy link
Owner

Fixed via #42. Will close the issue when a release is out.

@sonaye
Copy link

sonaye commented Dec 31, 2017

Can we have this released please?

@vadimdemedes
Copy link
Owner

Released 0.4.0, sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants