Skip to content

WIP: print prompt to /dev/tty instead of stderr. #139

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

devank4000
Copy link
Contributor

Currently does not respect posixly_correct and is_interactive options, feedback is appreciated!
See #138 for issue tracker

Currently does not respect posixly_correct and is_interactive options,
feedback is appreciated!
Copy link
Owner

@magicant magicant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a nice try as a first step, but it seems there is still a lot of work to be done to support the new behavior. In particular, we will need to review all code fragments that assume the output is stderr. I'm inclined to doubt it's worth the effort.

Thanks anyway, your code helped me see the current situation.

fwrite(lebuf.buf.contents, 1, lebuf.buf.length, stderr);
fflush(stderr);
write(ttyfd, lebuf.buf.contents, lebuf.buf.length);
fsync(ttyfd);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The write function is not buffered. There is no need to flush the data after writing.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unbuffered-ness of write also means that write may only write part of the contents. You need to examine the return value of write and keep calling it until the whole contents are written.
If you don't want to do it manually, you should keep using fwrite.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you should not assume ttyfd is always open.

@@ -193,7 +193,7 @@ int main(int argc, char **argv)
input.fd = STDIN_FILENO;
inputname = NULL;
if (!options.is_interactive_set && argc == xoptind
&& isatty(STDIN_FILENO) && isatty(STDERR_FILENO))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this condition would break POSIX-conformance.

Comment on lines +219 to 224
open_ttyfd();
is_interactive_now = is_interactive;
if (!options.do_job_control_set)
do_job_control = is_interactive;
if (do_job_control) {
open_ttyfd();
if (do_job_control)
ensure_foreground();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ttyfd should be opened only when the shell starts job control. Especially, when the shell is non-interactive, opening the ttyfd would be useless.

@@ -1505,7 +1506,7 @@ size_t select_list_item(size_t index, int offset, size_t listsize)
* terminal and returns true. */
bool le_try_print_prompt(const wchar_t *s)
{
if (isatty(STDERR_FILENO) && le_setupterm(true)) {
if (le_setupterm(true)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this condition would break things when stderr is redirected to a non-terminal file.

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

Successfully merging this pull request may close these issues.

2 participants