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

feature: Deno.ttySize() #3790

Closed
wants to merge 6 commits into from
Closed

feature: Deno.ttySize() #3790

wants to merge 6 commits into from

Conversation

sinclairzx81
Copy link
Contributor

This PR implements the Deno.ttySize() API for obtaining the current terminal dimensions columns/rows. This update takes a dependency on the crossterm crate which should facilitate cross platform queries for current terminal dimensions.

PR is submitted for review and feedback with reference to issue #3456

@claassistantio
Copy link

claassistantio commented Jan 25, 2020

CLA assistant check
All committers have signed the CLA.

@sinclairzx81 sinclairzx81 requested a review from ry January 25, 2020 15:49
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I'm glad to see you were able to figure out how to add ops.

I'm not keen to take on new dependencies but crossterm looks good and will certainly be useful in the future. I'm going to now try to remove our termcolor = "1.0.5" and ansi_term = "0.11.0" and atty = "0.2.13".

Generally we prefer unit tests to integration tests because they run faster. I've edited your PR to do that. I've also marked it as unstable, since it's new.

@bartlomieju
Copy link
Member

I wonder if enable_raw_mode will work with Tokio's stdio just like that 🤔 that would save us a lot of headache

@ry
Copy link
Member

ry commented Jan 25, 2020

Actually I'm having second thoughts about crossterm because we have a lot of TTY crates and I would either like to reduce them to a single dependency or not add more. It doesn't seem like crossterm would allow reducing deps.

Here is a list of our current TTY crates:

So I wonder if there is a smaller crate which can provide the functionality? Or can we just rip out the implementation from crossterm? We can certainly issue the ioctl ourselves without much difficulty https://stackoverflow.com/questions/1022957/getting-terminal-width-in-c

@sinclairzx81
Copy link
Contributor Author

@ry Hi, thanks, yes, sorry, missed the unit test code in there, thanks for moving that.

Happy to keep an eye on this and help out on any enhancements down the road. I am guessing this is all fairly preliminary at this point, so happy to follow along with all design considerations on the tty api as things progress.

Many thanks

@ry
Copy link
Member

ry commented Jan 25, 2020

Wow I totally forgot that we've already got term width/height in our code:

if libc::ioctl(libc::STDERR_FILENO, libc::TIOCGWINSZ, &mut winsize) < 0 {

I'm not sure what to do yet, but I'm more convinced that we need to clean up the TTY crate situation rather than adding a new dep.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs more investigation

@ry
Copy link
Member

ry commented Feb 24, 2020

Thanks for the patch @sinclairzx81 but I'm going to close without merge. I don't want to add this crossterm dep. This ttySize op is definitely desirable, but I think we can achieve it (at least on unix) with a single line as I gave above.

@ry ry closed this Feb 24, 2020
@apatrida
Copy link

apatrida commented Jun 14, 2020

@ry it seems like you'll need something like CrossTerm (or similar code) for node tty support #5392. Resize event can be had via signals already, but we are missing columns, rows that this patch was focusing on, and clearLine, clearScreenDown, cursorTo, moveCursor, getColorDepth, hasColors (covered by noColor?), ... Some are just ANSI sequences, but not all.

@Yamboy1
Copy link

Yamboy1 commented Jun 24, 2020

Any update on this? My current deno readline-esque implementation for my shell is broken when you hit the edge of the terminal, not sure if I can go any further without checking the size of the terminal as well as resize events

https://github.com/Yamboy1/denosh

sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 27, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 27, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 27, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 27, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 28, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 28, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 28, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 28, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 28, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jun 28, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jul 6, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jul 7, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jul 7, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jul 7, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
sebastienfilion added a commit to sebastienfilion/deno that referenced this pull request Jul 9, 2020
…ns and rows property on STDOUT

To be able to build rich CLI tools, it is very useful to be able to calculate the terminal's number of columns and rows.
Although we could use tput through `Deno.run`, this approach is a bit slow and convoluted.

Resolves: denoland#3456
References: denoland#3790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants