bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

Sometimes the width calculation fail #32

Closed FJLendinez closed 5 years ago

FJLendinez commented 5 years ago

When bullet calculate the width of terminal could fail throwing this stacktrace:


    _, n = os.popen('stty size', 'r').read().split()
ValueError: not enough values to unpack (expected 2, got 0)```

Using it we asume the standard console width when it fails
rcfox commented 5 years ago

Why not use shutil.get_terminal_size()?

FJLendinez commented 5 years ago

Is better to use it https://gist.github.com/jtriley/1108174 than shutil

PS: shutil.get_terminal_sized == os.terminal_size

rcfox commented 5 years ago

That code looks like it was meant for Python 2. shutil.get_terminal_size() was added in Python 3.3. I haven't looked into how it's implemented, but I get the sense that it's meant to work across platforms.

FJLendinez commented 5 years ago

Yes, i saw it, shutil is better. I will commit it

rcfox commented 5 years ago

shutil.get_terminal_size() returns (columns, lines) but you're taking the lines result now. It also probably isn't necessary it call int() on the result anymore.

FJLendinez commented 5 years ago

Right, i didn't see that.

rcfox commented 5 years ago

You're still taking the wrong value. Should be COLUMNS, _ = ...

FJLendinez commented 5 years ago

Right thanks i was clueless 😥

rcfox commented 5 years ago

No worries, it happens to me all the time.