Ask coding questions

← Back to all posts
ncurses window sizes
h
Pankak (49)

ncurses getmaxyx(stdscr, screeny, screenx); is unable to get correct window dimensions, instead it always displays 24 by 80, the y to x respectively.

I am not sure why this is, perhaps the repl console is a fixed dimension at its root or ncurses is just not very compatible with repl.

#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <unistd.h>

int DIMCHECK(int screeny, int screenx){
  getmaxyx(stdscr, screeny, screenx);
  mvprintw(2, 0, "%d, %d", screeny, screenx);
  if(screenx >= 50 || screeny >= 25){
    return 1;
  }
  return 0;
}

int main() {
  int screeny, screenx = 0;

  initscr();
  noecho();
  curs_set(FALSE);

  while(1){
    refresh();
    if(DIMCHECK(screeny, screenx)==0){
      
    } else {
      mvprintw(0, 0, "Please enlarge your window");
    }
  }
  refresh();

  endwin();
  return 0;
}

Result:

Please enlarge your window

24, 80

Calling all ncurses experts here