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

The LinePipedInputStream breaks the terminal character buffer #15

Open
gnodet opened this issue Apr 4, 2017 · 3 comments
Open

The LinePipedInputStream breaks the terminal character buffer #15

gnodet opened this issue Apr 4, 2017 · 3 comments

Comments

@gnodet
Copy link
Contributor

gnodet commented Apr 4, 2017

As expained in the LineDisciplineTerminal,

 * In order to correctly handle line discipline, the console
 * needs to read the input in advance in order to raise the
 * signals as fast as possible.
 * For example, when the user hits Ctrl+C, we can't wait until
 * the application consumes all the read events.
 * The same applies to echoing, when enabled, as the echoing
 * has to happen as soon as the user hit the keyboard, and not
 * only when the application running in the terminal processes
 * the input.
@stalep
Copy link
Member

stalep commented Apr 4, 2017

LineDisciplineTerminal is not used directly except for tests. If used directly it is extended by ExternalTerminal which creates a reader thread that will process the input bytes (echo for instance and signals).
ExternalTerminal is used when the java process is started as part of a series of commands eg. if the input is redirected in etc.
Is that sufficient?

@gnodet
Copy link
Contributor Author

gnodet commented Apr 4, 2017

ExternalTerminal is supposed to be used for all terminals but the system one, i.e. the terminal which is used by the end user to launch the application. So all incoming connections should use the ExternalTerminal.
The original design was to work as close as possible as real Unix terminals, i.e. read the input, process the signals, and push the data into an internal buffer. This allows signals and echoing to work in advance, i.e. before the receiving application actually processes the input.

A simple example is how the sleep command works in a unix shell. If you run sleep 100, the terminal is in canonical mode when the sleep command is executed. Until the timeout is over, or until ^C is hit, you can type characters on your keyboard. Given the terminal is in canonical mode, it will have the echo flag set, so chars will be immediately echoed, even if they are not yet consumed by the sleep method.
The problem with the LinePipedInputStream is that it will only read until the first <enter> key, so if you hit <enter>, then <ctrl+c>, the interrupt signal won't be processed.

The terminal implementations did support those use cases, and I'd like to understand what use case is being solved by the introduction of the LinePipedInputStream class.

@stalep
Copy link
Member

stalep commented May 17, 2017

The reason we created LinePipedInputStream is when æsh-readline is started locally when part of a pipeline or redirection. The inputstream is then returned as a stream that could be read in its full length in one go. With LinePipedInputStream it will still read the entire buffer, but it will only return in chunks separated by the line.separator sign.
It will still receive signals, but again, this is only used for pipelines/redirections.

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

No branches or pull requests

2 participants