Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TTY::Screen.visible_height #20

Closed
aaronmallen opened this issue Jan 16, 2025 · 1 comment
Closed

Add TTY::Screen.visible_height #20

aaronmallen opened this issue Jan 16, 2025 · 1 comment

Comments

@aaronmallen
Copy link

aaronmallen commented Jan 16, 2025

Describe the problem

I would like to get the screen height accounting for the prompt so that I can assure my screens are completely visible on render. For example given a terminal height of 10 and a prompt height of 2 I would expect the method to return a height of 8.

How would the new feature work?

Ideally the feature would find and calculate the height of the prompt in use and subtract it from the screen height.

visible_height = TTY::Screen.visible_height

Alternatively you could provide a method that just produces the prompt height and let the end user do the math:

visible_height = TTY::Screen.height - (TTY::Screen.prompt_height * 2)

Drawbacks

It might take some magic, I've been having a hard time detecting my own prompt height (p10k) but I'm also not a terminal wizard like you are and my hope is you'd know some tricks that I definitely do not.

@piotrmurach
Copy link
Owner

Hi Aaron 👋

Thank you for your interest in the TTY Toolkit and particularly this gem.

From the start, my aim for each tty-* gem is to keep it focused on a single task. Hence this gem measures the terminal screen and doesn't aim to do anything outside of that.

As for the API addition of the visible_height. The name is confusing. Why? Whether the terminal prompt is there or not, or how tall it is is irrelevant to the visibility of the screen. You can move the cursor anywhere in the terminal screen size, which means you can print over the prompt.

More importantly, as you found out determining prompt height is rather a difficult task. Reading terminal info won't be of much help here. Equally trying to read from the environment variable such as PS1, which may or may not be set, you would still need to expand the string to find out how many rows it takes up.

Unfortunately, I won't be adding any such functionality to this gem and I'm afraid I don't have any good suggestions either. However, if you find some robust solution to your problem please let me know as I'd be curious how you resolved this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants