-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
libterm: synchronize with public "term" crate v0.4.0 #31205
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
I mainly want this so I can update syntex to use the latest term crate :) Keep a close eye on the Windows code. I wasn't able to test it out on my Mac. |
FYI, in
|
Otherwise, LGTM. |
@Stebalien: Good point. I made both of your suggested changes in the latest patch. |
☔ The latest upstream changes (presumably #31120) made this pull request unmergeable. Please resolve the merge conflicts. |
Hm, I'm marked as reviewer but know nothing about this crate. @alexcrichton, do you know of a good person to r? here? |
Yes I can take a look |
fn from(err: term::Error) -> Self { | ||
Error::Term(err) | ||
} | ||
} |
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.
This seems pretty unfortunate, shouldn't a term::Error
be convertible into a io::Error
?
This same duplication seems to happen in libtest which is what makes me wary
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.
Yeah, I thought about that. I initially started by just adding:
impl From<term::Error> for io::Error {
fn from(err: term::Error) -> io::Error {
match err {
term::Io(err) => err,
err => io::Error::new(io::ErrorKind::Other, err),
}
}
}
But I decided against that because it seems a shame that we're giving up the flexibility to do sensible things with the term
errors, and making it slightly harder to add in custom emitter and libtest errors in the future. There's a side of me that just wants us to not get into the habit of stuffing things into error types like io::Error
. It probably doesn't really matter much in this case since these uses are internal to the compiler, but I'm trying to be a good role model :)
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.
In terms of integration with libsyntax/libtest, however, it seems pretty onerous to always require a shim like this (or to merge any two libraries together)
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.
Yep, it does get a bit obnoxious to setup the first time, and if we never take advantage of it, it does get a bit silly. I'm fine either way, assuming if we add this impl to term
it's fine with @Stebalien.
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.
Personally, I'd prefer the following so we don't loose any information:
impl From<term::Error> for io::Error {
fn from(err: term::Error) -> io::Error {
let kind = match &err {
&term::Error::Io(ref e) => e.kind(),
_ => ErrorKind::Other,
};
io::Error::new(kind, err)
}
}
This way, we keep the fact that this IO error was caused by a term error.
Thoughts?
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.
Sounds good to me!
☔ The latest upstream changes (presumably #30411) made this pull request unmergeable. Please resolve the merge conflicts. |
If we get a conversion of |
@alexcrichton done in term 0.4.1. |
Note that @pnkfelix found a bug in what appears to be Along those lines we may want to be hesitant about aggressively updating to new code? @Stebalien could you speak to some of the bigger changes made between term 0.2 and 0.4? |
@alexcrichton term used to return |
After Stebalien/term#56 is merged, the fix here would be to check if color is supported in |
I apologize for not catching this when initially reviewing this patch, I completely forgot about this change. Thanks @pnkfelix for noticing this. |
Ok, thanks for the summary @Stebalien! @erickt it looks like there's going to need to be some changes in that case? e.g. if we call methods like |
I'm sort of surprised that I was seeing the behavior that I was observing given that the API change described was something where unsupported operations now lead to This is what I mean (from rust-lang/cargo#2338 (comment) ):
this is the scenario where |
@pnkfelix it's probably just ignoring the errors as unimportant (printing to the screen is not critical) For example, the following would say nothing: fn say_something(&self) -> Result {
try!(self.term.reset());
write!(term, "something");
}
fn do_something_important() {
let _ = sayer.say_something();
} |
@Stebalien / @alexcrichton: I've updated my patch to sync with term v0.4.4, and got rid of the custom |
See #31205 (comment). You need to check if the terminal supports color.Steven Allen |
Looks good to me modulo what @Stebalien mentioned |
The only point of divergence from the public crate is that this patch uses `std::sys::windows` instead of the `winapi` and `kernel32` crate to access the Windows Console APIs.
@Stebalien: This PR should now be synced with term, modulo the clippy work you did in the repo. Does that address your comment about checking the terminal if it supports color? |
Not quite. You need to actually check for color support in |
@Stebalien: I added a patch that I think implements the check you were looking for. How does it look? |
Raw(Box::new(io::stderr())) | ||
} | ||
} | ||
None => Raw(Box::new(io::stderr())), |
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.
LGTM.
⌛ Testing commit 388cf4e with merge c8c296a... |
💔 Test failed - auto-win-gnu-32-nopt-t |
use std::io::prelude::*; | ||
use std::io; | ||
use std::ptr; | ||
use std::sys::windows::c as kernel32; |
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.
looks like this stuff casued the build failure
../src/libterm\win.rs:18:5: 18:37 error: unresolved import `std::sys::windows::c`. Could not find `windows` in `std::sys` [E0432]
☔ The latest upstream changes (presumably #32390) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing due to inactivity, but seems good to merge with a rebase and test fixes! |
The largest impact is that the public "term" crate now has it's own
term::Error
type. Most of the changes are propagating this type through the other crates.I also had a minor extraction of a subset of the "winapi" and "kernel32" crates.
cc @cmr, who made the original change to term.