Supply default terminal width to fix #795

It compiles. I didn't try to reproduce the bug with dump terminal.
Resending this pull request because I forgot the branch the other one.
Also it uses `math`. /cc @xuwei-k.