Properly cache terminal width and dirty on SIGWINCH
Summary:
See PHI110. Currently, the cache here is bad: if tput fails, we'll keep running tput over and over again, since null is not cached.
Instead:
- Cache null.
- Dirty the cache when we receivew SIGWINCH, which indicates the window/terminal metadata has changed.
Test Plan:
- Ran scripts/test/progress_bar.php in wide and narrow windows, saw it fit to the window.
- Resized the window while it was running, saw it (mostly) figure it out (it can leave some artifacts behind, but we can't do much about that).
- Added some debugging "print" statements to make sure the cache was working, saw it only recalculate once and then after a resize.
Reviewers: amckinley, chad
Reviewed By: amckinley
Differential Revision: https://secure.phabricator.com/D18669