-
Notifications
You must be signed in to change notification settings - Fork 37
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
#include <wchar.h> | ||
#include <wctype.h> | ||
#include <sys/stat.h> | ||
#include "../redir.h" | ||
#include "../history.h" | ||
#include "../job.h" | ||
#include "../option.h" | ||
|
@@ -516,13 +517,13 @@ void finish(void) | |
display_active = false; | ||
} | ||
|
||
/* Flushes the contents of the print buffer to the standard error and destroys | ||
/* Flushes the contents of the print buffer to the tty and destroys | ||
* the buffer. */ | ||
void le_display_flush(void) | ||
{ | ||
current_position = lebuf.pos; | ||
fwrite(lebuf.buf.contents, 1, lebuf.buf.length, stderr); | ||
fflush(stderr); | ||
write(ttyfd, lebuf.buf.contents, lebuf.buf.length); | ||
fsync(ttyfd); | ||
sb_destroy(&lebuf.buf); | ||
} | ||
|
||
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
lebuf_init((le_pos_T) { 0, 0 }); | ||
lebuf_print_prompt(s); | ||
le_display_flush(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this condition would break POSIX-conformance. |
||
&& isatty(STDIN_FILENO)) | ||
is_interactive = true; | ||
unset_nonblocking(STDIN_FILENO); | ||
} else { | ||
|
@@ -212,16 +212,15 @@ int main(int argc, char **argv) | |
#if YASH_ENABLE_LINEEDIT | ||
/* enable line editing if interactive and connected to a terminal */ | ||
if (!options.lineedit_set && shopt_lineedit == SHOPT_NOLINEEDIT) | ||
if (is_interactive && isatty(STDIN_FILENO) && isatty(STDERR_FILENO)) | ||
if (is_interactive && isatty(STDIN_FILENO)) | ||
set_lineedit_option(SHOPT_VI); | ||
#endif | ||
|
||
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(); | ||
Comment on lines
+219
to
224
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
set_signals(); | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 thatwrite
may only write part of the contents. You need to examine the return value ofwrite
and keep calling it until the whole contents are written.If you don't want to do it manually, you should keep using
fwrite
.There was a problem hiding this comment.
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.