Closed (fixed)
Project:
Drush
Component:
Base system (internal API)
Priority:
Minor
Category:
Bug report
Assigned:
Reporter:
Created:
12 Mar 2010 at 08:32 UTC
Updated:
6 Dec 2010 at 20:10 UTC
Jump to comment: Most recent file
You get "tput: No value for $TERM and no -T specified" - we don't care about nicely wrapping columns in any case where a terminal is not available (such as crontab), and the additional output causes cron to report each run (unless you direct errors to /dev/null), so the simplest fix is simply to skip the tput COLUMNS export if TERM is zero length.
Please check out the attached patch - I will probably go ahead and commit it unless anyone has any objections.
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | drush-export-columns.patch | 2.25 KB | greg.1.anderson |
| #27 | 740448.drush_.patch | 422 bytes | kotnik |
| #20 | drush-cvs.diff | 968 bytes | patrick2000 |
| #19 | tput-stderr.patch | 833 bytes | greg.1.anderson |
| #17 | drush-cvs.diff | 1.56 KB | patrick2000 |
Comments
Comment #1
moshe weitzman commentedAgree that this is annoying. My one thought is that we once had some code that suppressed this error but we had to back it out because it broke something somewhere. I searched but couldn't find the issue. Maybe one of the Aegir guys remembers (anarcat?). Anyway, seems like a good patch to me.
Comment #2
moshe weitzman commentedthat prior rollback was unrelated.
Comment #3
moshe weitzman commentedCommitted. thanks owen.
Comment #5
jm.federico commentedI was still getting the notice so I did one modification to the logic:
changed
to
For some reason $TERM is set to dumb in some cases. I'm using ubuntu 8.04 (not in my hands to upgrade).
Comment #6
starbow commentedI am having the same issue as jm.federico, but on CentOS 5.4. During the crontab run $TERM is set to 'dumb'.
Comment #7
patrick2000 commentedI also have the same issue like jm.federico
my 5cts to find out why:
and a quick-fix:
Comment #8
greg.1.anderson commented#784342: Drush should't use colors if there is no terminal attached should also fix this; re-open if it does not.
Comment #9
patrick2000 commentedNo, sorry, #784342 doesn't fix this issue here.
Also, I think the test weather stdout is "not a terminal" ([ ! -t 1 ]) is not the best thing to base the "--nocolor" decision on. What if somebody does $ drush | less -R (-R for "Raw control chars" - makes color codes work in the less pager). In that case the colors will be suppressed because stdout will be a pipe while the user actually intended to have colors enabled. And besides that i don't like the "set -- ..." line, that changes the effective command line arguments, at all. That sort of manipulations can make debugging really hard.
Checking the TERM variable for being "not present" OR "'dumb'" is better, I think. It has already been done this way. It was just not "done right", because TERM was only tested for being "not present" and checking for "dumb" was neglected. As bash sets "TERM" to "dumb" on startup if it is not present, this is necessary. Switching to [ -t 1 ] type testing now would be inconsistent with existing code.
See the attached proposed patch, which implements my suggested changes.
Comment #10
patrick2000 commentedthe same patch in diff -u format
Comment #11
owen barton commentedI think checking for "dumb" in addition is a good approach (I can confirm that this is what you get with cron on some systems, whilst others leave $TERM unset), but the logic doesn't look quite right to me:
Shouldn't this check be something like: if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ "$TERM" != "dumb" ]?
Same logic issue here.
I think it makes more sense to keep the "terminal environment logic" all together in the drush script wrapper. This means that users of other platforms/shells (e.g. Windows, other *nix, tcsh etc etc) can write their own native wrappers without bumping into terminal environment logic in the main php code. Hence, I would suggest that we drop the whole getenv here, and alter the existing color disabling logic to also detect a $TERM = "dumb".
Comment #12
owen barton commentedComment #13
greg.1.anderson commentedOkay, I've just skimmed this and the other issue, but I think I'm convinced. Will return to this later.
Comment #14
greg.1.anderson commentedEdit: I was insane when I wrote the comments here, so I've deleted them. :p
Comment #15
bibo commentedSubscribing.
I just noticed that my new drush crontab (which is run every minute), fills the mailbox with errors. I actually tried to fix it in crontab, like this guy:
http://www.practicalweb.co.uk/blog/10/02/18/drush-tput-no-value-term-and...
It didnt work for me though. It's definitely not critical, but annoying. 'm just waiting until this is fixed in drush.
Thanks for the awesomeness of drush btw! Makes my life so much easier :)
Comment #16
patrick2000 commentedIn reply to comment #11 by owen barton:
Yes, you ar right of course! Fixed that.
(And forget what I originally said in this comment, please. Must have been infected with insanity. Sorry.)
Comment #17
patrick2000 commentedComment #18
fl3a commentedDetected the same behaviour in Drush v.3.3.
Comment #19
greg.1.anderson commentedFirst, sorry for #8 -- these two issues are unrelated, except for both relating to the tput command. I re-opened #784342: Drush should't use colors if there is no terminal attached to discuss the -t vs --nocolor issue there.
Regarding this issue, it seems that the only thing that we want to fix here is to suppress the message that tput prints to stderr when there is no terminal. I don't like testing for "dumb"; I don't know that $TERM might be "mudo" or "物の言えない" or something else. I know that drush does not need to support every language and every distro, but if there's an alternative that is distro-agnostic, then we should use it.
The enclosed patch simply suppresses everything that tput writes to stderr. This should not interfere with any correct value of TERM, and calling tput should not cause any adverse affects (other than the msg to stderr) when it is called with a "missing" value for TERM. In short, tput is better than drush at detecting whether or not the value of TERM is meaningful.
The TERM tests in environment.inc are not necessary, as stderr is already redirected to stdout there, and the is_numeric test prevents undesirable outcomes when the stderr message is interpreted as a column count.
This seems to clear everything up for me; does anyone know of other cases I missed, where calling tput still causes problems with a missing TERM?
Comment #20
patrick2000 commentedI am fine with greg's patch. It's simple and fixes the issue.
The fact that COLUMNS could be exported while containing just an empty string (in case "tput columns" fails because TERM=dumb) could maybe be ironed out... ?
Comment #21
moshe weitzman commentedGreg should commit this when he is satisfied.
Comment #22
greg.1.anderson commentedCommitted.
Comment #23
greg.1.anderson commentedComment #24
kotnik commentedSorry, but this is not fixed. Both Ubuntu and Debian (dash and bash) default to 80. For example:
I'll check later what's going on.
Comment #25
kotnik commentedOk, got it now.
Since both stderr (2>/dev/null) and stdout (implicitly via $()) are redirected, tput gets confused and doesn't know for what terminal do we want info for, and returns it's default, hence 80. And currently it will always return 80, regardless of the terminal size.
So, the best approach would be to check for $TERM: if there is no $TERM, then COLUMNS get to be 80. Otherwise, let tput figure out what to do (ie. read termcap file and give us result).
Will provide a patch.
Comment #26
greg.1.anderson commentedSee #7 & c.; sometimes $TERM is "dumb". Sorry that I tested on an 80-column terminal and didn't notice that it was still broken.
Comment #27
kotnik commentedTerm being dumb, doesn't confuse tput
Dumb is defined (/lib/terminfo/d/dumb) and tput can handle it. Here's the patch that fixes this.
Comment #28
greg.1.anderson commentedPer #7, your test is not adequate for the situation where TERM is not set.
Try this:
On Debian (Ubuntu), this prints:
Other distros might print different values, but the fact remains that there are some instances where $TERM is non-empty, and tput cols prints an error to stderr. I'm a bit at a loss on how to deal with this; if we redirect stderr to /dev/null or to stdout, then tput cols returns the wrong value when $TERM is set. If we don't redirect stderr, then we get an undesirable message.
I can think of only two solutions, neither of which make me terribly happy.
#1 is subject to failure if 'dumb' is ever localized (and frankly I don't know if it is or isn't)
#2 is a little inelegant, as it involves multiple calls to tput
Pick your ugly. I think I prefer #2, but I'm ready to settle on either one and just move on.
Comment #29
kotnik commentedI guess you're right with this approach. I'll provide a patch.
Comment #30
owen barton commentedI have done some Googling and I am pretty sure TERM=dumb is a standard terminal type (like xterm), not a language or (very) distro specific convention. Between this and checking for an unset TERM, I think we should be covered. Hence, I would lean towards #1, unless we have an actual example of a "width-less" terminal other than NULL or "dumb".
Comment #31
greg.1.anderson commentedI can go with that. Sorry for #19.
Looks like we can basically go with #17, although this does bring up the question of whether
exec('tput colors 2>&1');returns the correct value, or the default value for colors per #25. Might want to avoid setting COLUMNS unless necessary per #20.Since this issue has turned out to be so convoluted, a goodly amount of commenting would be nice too.
Comment #32
markus_petrux commentedsubscribe
Comment #33
greg.1.anderson commentedI just tried to make my terminal wider to see more info, and got annoyed by my bug in #19. Here's a patch that fixes it, as we discussed above.
Comment #34
daniels____ commentedPatch tested and seems that works fine.
Comment #35
moshe weitzman commentedCommitted. Thanks.
Comment #36
moshe weitzman commentedComment #37
patrick2000 commentedThank you everybody for fixing this! Perfect.
Cheers