robustified getTerminalWidth