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

ui: refactor prompt to write to stdout or stderr #4536

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

torquestomp
Copy link
Collaborator

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

buf = trimmed.to_owned();
} else if buf.is_empty() {
return Err(io::Error::new(
let buf = buf.strip_suffix('\n').map(|s| s.to_owned()).unwrap_or(buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: buf.truncate(trimmed.len()) could also be used.

btw, if buf == "\n", an empty string should be returned. It's not an EOF.

@@ -566,15 +566,15 @@ impl Ui {
.unwrap_or(false)
}

pub fn prompt(&self, prompt: &str) -> io::Result<String> {
pub fn prompt(&self, writer: &mut dyn Write, prompt: &str) -> io::Result<String> {
if !Self::can_prompt() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate the intent? It's weird that can_prompt() tests stdout, but we use an arbitrary write stream.

If the goal was to handle the case where stdout is redirected, it might be okay to always use stderr. Maybe we can also use some library that can obtain tty even if stdout/err was redirected. I assume rpassword does something like that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume its for testing Google's custom binary. But I agree that its missing the intent in the commit message.

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.

3 participants