Fix terminal size detection logic