Skip to content
← Back to Community
Console size
Profile icon
h
has Hacker Plan
realTronsi

I'm grabbing the console dimensions using ioctl, but the dimensions are inconsistent with the actual size.

Executing the same code (as provided below) works perfectly in the shell however, suggesting it's probably due to an underlying factor from how the console is implemented, which I do not know about.

struct winsize ws; if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0){ // fall back if ioctl fails if (write(STDOUT_FILENO, "\x1b[999C\x1b[999B", 12) != 12) return -1; return get_cursor_pos(width, height); } else { *width = ws.ws_col; *height = ws.ws_row; return 0; } }

Notice I do have a fallback, but it isn't being executed in this case as ioctl is not failing, but simply returning incorrect dimension.

I'm mainly focused on the rows as of now. ioctl returns a value of 24 for the rows in the console, while correctly displaying 30 when executed in the shell.

I just want to make sure this is a quirk unique to repl and not some technological error I've made.

Voters
Profile icon
AsharCada
Profile icon
hyungyulove
Profile icon
realTronsi
Comments
hotnewtop
Profile icon
19wintersp

As in, the output window in the Replit IDE is different to the result? That's expected, the IDE doesn't communicate the output window size back to the Docker container.

Profile icon
realTronsi

@19wintersp and the shell does?

Profile icon
realTronsi

@19wintersp and also side note: it has worked before, correctly displaying 30 while run in the console, but don't remember changing anything about the window detection

Profile icon
19wintersp

@realTronsi From what I know, the shell works differently to the Console, though I don't know exactly how, sorry. I'll have a look at some WS packets and tell you if I see anything.

Profile icon
19wintersp

@realTronsi Apparently, it does, after some very rudimentary tests. Resizing the Console sends no WebSocket messages, resizing the Shell does.

Profile icon
realTronsi

@19wintersp I see, are you just reading the outgoing packets or are you decoding the binary? Just curious

Profile icon
19wintersp

@realTronsi Just checking from DevTools, no decoding. Not very scientific, but ¯\_(ツ)_/¯

Profile icon
realTronsi

@19wintersp hmm so is the console disconnected from the container completely? Meaning fallbacks such as escape sequences will be effectively useless as well

Profile icon
19wintersp

@realTronsi I think so, I think it's just an input/output thing.

Profile icon
realTronsi

@SixBeeps @Coder100 you guys make console stuff, perhaps you know something about this?