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

Implement escape sequence to query terminal size in pixels ('\e[14t'). #581

Closed
dylanaraps opened this issue May 28, 2018 · 8 comments
Closed

Comments

@dylanaraps
Copy link

This escape sequence outputs the current terminal's window size in pixels.
The output appears as user input in the prompt and requires a read
command to store it’s output.

This is supported in all VTE based terminals, XTerm, URxvt, iTerm2 and
many others so it makes sense for Kitty to support it as well.

Neofetch uses this escape sequence to correctly size and place the image
inside of the terminal window (Neofetch has fallbacks for when this
sequence isn’t supported but they depend on an X server
).

Neofetch recently added support for kitty icat and this works when an X
server is running (thanks to the fallbacks above). However it fails on
macOS as the escape sequence is not supported.

There is a way of using osascript on macOS to query the window size but
this requires the user to accept a dialog that appears on first run. Kitty
supporting the sequence directly would make this feature transparent for
users.

Cheers 👍

@kovidgoyal
Copy link
Owner

There is no need for this. kitty has a far superior mechanism to query window size, that is synchronous and much more efficient. See https://github.com/kovidgoyal/kitty/blob/master/graphics-protocol.asciidoc
And this sis upported in other terminals as well, such as xterm. it should be a two line patch to neofetch to use this method of detecting screen size.

@kovidgoyal
Copy link
Owner

Oh and just for completeness, if you dont want to implement the method, you can also use:

kitty +runpy "from kitty.utils import *; s = screen_size_function()(); print('x'.join(map(str, s[2:4])))"

@kovidgoyal
Copy link
Owner

And to make it even easier:
20611c7

Note that this will actually work in any terminal that implements TIOCGWINSZ correctly, not just kitty.

@dylanaraps
Copy link
Author

dylanaraps commented May 28, 2018 via email

@kovidgoyal
Copy link
Owner

Note I renamed the option to --print-window-size

@dylanaraps
Copy link
Author

--print-window-size and the +runpy commands don't work from a bash sub-shell. The error is the same for both commands.

Example code:

IFS=x read -r term_width term_height < <(kitty icat --print-window-size)

Error output:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/bin/../lib/kitty/__main__.py", line 76, in <module>
    main()
  File "/usr/bin/../lib/kitty/__main__.py", line 72, in main
    func(sys.argv[1:])
  File "/usr/bin/../lib/kitty/__main__.py", line 10, in icat
    main(args)
  File "/usr/bin/../lib/kitty/kittens/icat/main.py", line 256, in main
    print('{}x{}'.format(screen_size().width, screen_size().height))
  File "/usr/bin/../lib/kitty/kitty/utils.py", line 94, in screen_size
    fcntl.ioctl(fd, termios.TIOCGWINSZ, buf)
OSError: [Errno 25] Inappropriate ioctl for device

@kovidgoyal
Copy link
Owner

8809b8d

@dylanaraps
Copy link
Author

Thanks 👍

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