Page MenuHomePhabricator

Properly cache terminal width and dirty on SIGWINCH
ClosedPublic

Authored by epriestley on Oct 2 2017, 7:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Feb 2, 4:45 PM
Unknown Object (File)
Mon, Jan 27, 12:01 PM
Unknown Object (File)
Sun, Jan 26, 7:45 PM
Unknown Object (File)
Fri, Jan 24, 10:39 PM
Unknown Object (File)
Fri, Jan 24, 10:39 PM
Unknown Object (File)
Fri, Jan 24, 10:39 PM
Unknown Object (File)
Fri, Jan 24, 10:39 PM
Unknown Object (File)
Wed, Jan 22, 9:10 PM
Subscribers
None

Details

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.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

amckinley added inline comments.
src/console/format.php
217–218

Maybe keep this comment? I was briefly confused by this too.

This revision is now accepted and ready to land.Oct 2 2017, 7:51 PM
src/console/format.php
217–218

Oh, sure -- I originally thought I could write this in a slightly less dumb way and make what was going on a little more obvious, but PhutilExecPassthru doesn't currently have a mode to pass some kind of normal pipe for stdout/stderr.

This revision was automatically updated to reflect the committed changes.