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 command to get terminal size #13

Open
noelwelsh opened this issue Jan 21, 2025 · 4 comments
Open

Add command to get terminal size #13

noelwelsh opened this issue Jan 21, 2025 · 4 comments

Comments

@noelwelsh
Copy link
Contributor

Add command (effect, program, documentation) to get the current terminal size.

It looks like the size can be obtained with the command CSI18t, but it's not clear this is widely supported. If it's not widely supported, the next step is to use the ioctl C API.

See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html and search for XTWINOPS for the escape code to get the terminal size (we're interested in getting it in characters; pixels doesn't seem as useful).

For example of C code using ioctl see https://rosettacode.org/wiki/Terminal_control/Dimensions#Library:_BSD_libc

Crossterm code, which is a bit more complicated, is at https://github.com/crossterm-rs/crossterm/blob/e104a7cb400910609cdde36f322e3905c4baa805/src/terminal/sys/unix.rs#L59

@kapunga
Copy link
Contributor

kapunga commented Jan 26, 2025

It looks like the TIOCGWINSZ constant needed for use with ioctl is missing from the Scala native implementation, but JLine appears to have it: https://github.com/search?q=repo%3Ajline%2Fjline3%20TIOCGWINSZ&type=code

@noelwelsh
Copy link
Contributor Author

The Scala Native people might be open to a PR, but it's probably easiest to start with the CSI code and see how widely supported that is.

@noelwelsh
Copy link
Contributor Author

At the OSS Hack Night we discovered:

  • Not all terminals respond to ESC[18t. The terminal inside IntelliJ did not but Ghostty did.
  • JLine provides a method to get the size of the terminal, so that provides an implementation pathway on the JVM

As a step forward we can define a GetSize effect and implement it for the JVM.

@kapunga
Copy link
Contributor

kapunga commented Feb 2, 2025

JLine provides a method to get the size of the terminal, so that provides an implementation pathway on the JVM
For a lot of things JLine is doing, it appears that eventually there is an endpoint in JNI we might be able to mimic when we worry about support for Scala Native.

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

No branches or pull requests

2 participants