-1

I'm writing a simple application to use ptys and run commands such as vi. When they run, regardless of my terminal emulator's size, the pty runs on a very small window; here's a screenshot: https://imgur.com/a/DdRG2Ib the cursor is just outside the pty (and the screen is blank, nothing is written outside it).

Keeping the terminal emulator at a maximum size, I aim to "extend" the pty's size and use the full screen.

My approach was to get the size for stdout and set it on the master size of the terminal, following what I read here: Can't change terminal size on pty/N (works on ttyN)

#define err(x) { if((x)==-1) exit(1); }
int set(int masterfd) {
    float k = 0;
    struct winsize w;
    err(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w));
    printf("wsz: r:%d c:%d\n", w.ws_row, w.ws_col);
    w.ws_row *= k; w.ws_col *= k;
    err(ioctl(masterfd, TIOCSWINSZ, &w));
    return 1;
}

When k is non-zero, the whole screen is messed up. Only when both rows and columns are zero, the terminal is tiny but works.

After opening the master, I was expecting a call to set() with the master fd to adjust the size of the terminal. The call to printf() shows that on STDOUT_FILENO the rows and columns are my display size, on the master fd they are 0.

How can I make the pty use my full screen?

bicup
  • 195
  • 8

1 Answers1

-1

Your problem is almost surely not in the code you've shown but in the code you haven't. Also, your question isn't clear, but I suspect it's working fine not just for k=0 but for all nonnegative k with k<=1.

Presumably you're passing the output from the program running on the pty through to the terminal your process has as its stdout, either as-is or modified in some way. In general this can't work. Rather, you'd have to actually emulate a (some particular type of) terminal, maintaining your own logical terminal contents in memory, then render that to the real terminal, clipping it to the region you want to show. This is rather nontrivial. Note that screen can already do at least a limited form of this though, without you having to write any new code.

R.. GitHub STOP HELPING ICE
  • 195,354
  • 31
  • 331
  • 669
  • "for all nonnegative k<=1" no; I used `float` to try 0.1, 0.5, 1, 2, 4 - they don't make all nonnegatives, but good samples. Can you explain some more why it can't work? When you say "clipping it to the region you want to show", I'm trying to "extend/expand" the view, not clip it. Side note: I tried using `screen`, but the same issue appears – bicup Sep 03 '19 at 20:20
  • @bicup: I don't understand what you mean by "extend/expand"; my best guess is that you mean you want to have a virtual size larger than the actual terminal (in which case displaying it would require clipping). But maybe I'm misunderstanding what you want. – R.. GitHub STOP HELPING ICE Sep 03 '19 at 22:39
  • In the screenshot, see the mouse pointer, outside of the region of vim. I am trying to get vim use the full available screen. From what I understand, you might be thinking about the opposite way – bicup Sep 04 '19 at 07:43