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

Wrong value for TIOCGWINSZ? #3

Closed
simonschoelly opened this issue Aug 8, 2020 · 6 comments
Closed

Wrong value for TIOCGWINSZ? #3

simonschoelly opened this issue Aug 8, 2020 · 6 comments

Comments

@simonschoelly
Copy link

I use Linux here and I tried to use your library to get the size of my terminal in pixels. Maybe a bit overkill but I don't know a better way yet. When I try to get that size, I get the following error:

julia> TerminalUserInterfaces.terminal_size()
ERROR: ioctl failed: Inappropriate ioctl for device
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] ioctl(::RawFD, ::Int64) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:123
 [3] ioctl at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:126 [inlined]
 [4] terminal_size(::Base.TTY) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:9
 [5] terminal_size() at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:13
 [6] top-level scope at REPL[71]:1

I then tried out

julia> TerminalUserInterfaces.IOCTL.ioctl(stdout,  TerminalUserInterfaces.IOCTL.TIOCGWINSZ)
ERROR: ioctl failed: Inappropriate ioctl for device
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] ioctl(::RawFD, ::Int64) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:123
 [3] ioctl(::Base.TTY, ::Int64) at /home/simon/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:126
 [4] top-level scope at REPL[73]:1

and got the same error. Finally I looked at the code and saw that TerminalUserInterfaces.IOCTL.TIOCGWINSZ is set to 25 for linux systems. I looked up ioctl.h on the internet and saw that there TIOCGWINSZ is set to 21523. So I tried that out and it worked:

julia> TerminalUserInterfaces.IOCTL.ioctl(stdout,  21523)
TerminalUserInterfaces.IOCTL.winsize(0xdeb8, 0x1b66, 0x7ffe, 0x0000)

So is it possible that the value for TIOCGWINSZ is incorrectly defined?

@kdheepak
Copy link
Owner

kdheepak commented Aug 9, 2020

If you are just interested in getting the size of the terminal you can run the built in Base.displaysize(stdout) or just Base.displaysize().

You might be right about the IOCTL.TIOCGWINSZ values, I only tested them on a macos. I'll look into it and submit a PR for linux compatible changes.

@yakir12
Copy link

yakir12 commented Aug 27, 2020

I'm on Debian and have the exact same issue (the weird alignment is part of the problem, I assume):

ERROR: ioctl failed: Inappropriate ioctl for device
                                                   Stacktrace:
                                                               [1] error(::String) at ./error.jl:33
                                                                                                    [2] ioctl(::RawFD, ::Int64) at /home/yakir/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:123
                                                                 [3] ioctl at /home/yakir/.julia/packages/TerminalUserInterfaces/ha2Cg/src/ioctl.jl:126 [inlined]
                      [4] terminal_size(::Base.TTY) at /home/yakir/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:9
                                                                                                                               [5] terminal_size() at /home/yakir/.julia/packages/TerminalUserInterfaces/ha2Cg/src/utils.jl:13
                                                                                   [6] Terminal(::Base.TTY, ::Base.TTY) at /home/yakir/.julia/packages/TerminalUserInterfaces/ha2Cg/src/terminal.jl:18 (repeats 2 times)
                                                                             [7] main() at ./REPL[5]:6
                                                                                                       [8] top-level scope at REPL[6]:1

I'm on TerminalUserInterfaces v0.2.0.

@kdheepak
Copy link
Owner

This has been on my list of things to do and I haven't gotten to it yet. But I'll commit to setting up a Linux VM and debugging this this weekend!

@kdheepak
Copy link
Owner

kdheepak commented Aug 31, 2020

I made some changes in this commit that might resolve this issue: 4236b4c.

I was able to set up a Ubuntu machine as well, so I will be able to do further testing shortly.

@kdheepak
Copy link
Owner

Are you able to test with the latest version master of the package? I was able to run the examples using Julia 1.5.1 and TerminalUserInterfaces.jl#master.

@kdheepak
Copy link
Owner

kdheepak commented Jul 25, 2023

I've dropped the dependency on Termios, so this issue should now be resolved in this release: https://github.com/kdheepak/TerminalUserInterfaces.jl/releases/tag/v0.3.0

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

3 participants