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

How to fall back on std::io::stderr() if term::stderr() fails? #57

Open
matthiasbeyer opened this issue Feb 23, 2016 · 8 comments
Open

Comments

@matthiasbeyer
Copy link

Is there a way to fall back to plain std::io::stderr() when term::stderr() fails building the terminal object?

If not, then this is a feature request.

@Stebalien
Copy link
Owner

Not currently but I'd like to provide this functionality eventually. However, I don't want to just "not color". Instead, I'd like to provide a tiered API where the user can construct a low level terminal directly if they need fine control or a higher level "colored output" object if they just want "smart coloring".

@matthiasbeyer
Copy link
Author

This is a blocker for some of my things. I would really like to have the option "Either term::stderr() or std::io::stderr() if the former fails" - even if this means without color - no problem for me!

@Stebalien
Copy link
Owner

You can do what rust and cargo do for now.

On February 24, 2016 8:34:54 AM EST, Matthias Beyer notifications@github.com wrote:

This is a blocker for some of my things. I would really like to have
the option "Either term::stderr() or std::io::stderr() if the former
fails" - even if this means without color - no problem for me!


Reply to this email directly or view it on GitHub:
#57 (comment)

Steven Allen

@matthiasbeyer
Copy link
Author

What do they do?

@Stebalien
Copy link
Owner

They have enums that abstract over Stdout and a Terminal. That is, something like:

enum Output {
    Terminal(StdoutTerminal),
    Stdout(Stdout),
}
impl Output {
    fn new() -> Output {
        if let Ok(term) = term::stdout() {
            if term.supports_color() {
                return Output::Terminal(term);
            }
        }
        return Output::Stdout(std::io::stdout());
    }
    fn print_error(&mut self, msg: &str) -> io::Result<()> {
        match *self {
            Terminal(ref term) => { /* ... */ },
            Stdout(ref out) => { /* ... */ },
        }
    }
}

This is obviously not a very good solution (which is why I'm leaving this issue open).

@matthiasbeyer
Copy link
Author

matthiasbeyer commented May 7, 2016

Any progress here?


Edit: I ask because I need support for this in https://github.com/matthiasbeyer/imag/pull/212 and https://github.com/matthiasbeyer/imag/pull/213

@Stebalien
Copy link
Owner

Stebalien commented May 7, 2016

Sorry, I'm kind of swamped with school work at the moment (trying to finish a masters thesis) and doing this right is non-trivial. Basically, I've been re-writing term to,

  1. Have a global interface (configured globally) like std::io's stdout. No more passing around a Terminal object. IMO, this is almost always what users want.
  2. Never color the wrong text. This is currently a big problem on Windows and a lesser problem on unix.
  3. Reduce the number of places where things can go wrong. Currently, we can know that something won't work up-front but don't report this to the user till they try to use the feature.
  4. Proper, reliable buffering. Line, full (print on flush), and no buffering.
  5. Pluggable and configurable. Users need to be able to drop in their own terminal endpoints. This is especially useful for testing.
  6. Just do the right thing. (this is the feature you're looking for).

Unfortunately, it took me a while to realize that a global interface was the right one so I still have quite a bit of work to do.

@matthiasbeyer
Copy link
Author

Sorry, I'm kind of swamped with school work at the moment (trying to finish a masters thesis)

Hey, no problem! 😄 I can fully understand that, I'm working on my bachelors thesis at the moment.

Have a global interface [...] IMO, this is almost always what users want.

Sounds good, yes. The other points sound good as well.


I just wanted to ping you whether you are still working on this or whether this is abandoned. Awesome to hear/read that you want progress as well! Thank you a lot! I didn't want to annoy or push you, just a simple "anyone alive here"-ping 👍

MoSal added a commit to rust-alt/term that referenced this issue Aug 20, 2018
 Parallel API to terminfo terminals is also added:
  * WinConsoleInfo::from_env()
  * WinConsole::new_with_consoleinfo()

 Just like terminfo, this allows to check if we are going to get
 errors before moving `out`.

 Related: Stebalien#57

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
MoSal added a commit to rust-alt/term that referenced this issue Aug 20, 2018
 Parallel API to terminfo terminals is also added:
  * WinConsoleInfo::from_env()
  * WinConsole::new_with_consoleinfo()

 Just like terminfo, this allows to check if we are going to get
 errors before moving `out`.

 Related: Stebalien#57

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
MoSal added a commit to rust-alt/term that referenced this issue Aug 20, 2018
 Parallel API to terminfo terminals is also added:
  * WinConsoleInfo::from_env()
  * WinConsole::new_with_consoleinfo()

 Just like terminfo, this allows to check if we are going to get
 errors before moving `out`.

 Related: Stebalien#57

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
MoSal added a commit to rust-alt/term that referenced this issue Aug 20, 2018
 Parallel API to terminfo terminals is also added:
  * WinConsoleInfo::from_env()
  * WinConsole::new_with_consoleinfo()

 Just like terminfo, this allows to check if we are going to get
 errors before moving `out`.

 Related: Stebalien#57

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
MoSal added a commit to rust-alt/term that referenced this issue Aug 20, 2018
 Parallel API to terminfo terminals is also added:
  * WinConsoleInfo::from_env()
  * WinConsole::new_with_consoleinfo()

 Just like terminfo, this allows to check if we are going to get
 errors before moving `out`.

 Related: Stebalien#57

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
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