term-size.c 690 B

123456789101112131415161718192021
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2013 K. Lange
  5. *
  6. * term-size - Print the size of the tty
  7. *
  8. * This is mostly redundant with ttysize, and should probably
  9. * be replaced with setting COLUMNS and LINES in the shell,
  10. * like bash does, but it's left here for historical reasons
  11. */
  12. #include <stdio.h>
  13. #include <sys/ioctl.h>
  14. #include <termios.h>
  15. int main(int argc, char * argv[]) {
  16. struct winsize w;
  17. ioctl(0, TIOCGWINSZ, &w);
  18. printf("Terminal is %dx%d (%d px x %d px)\n", w.ws_col, w.ws_row, w.ws_xpixel, w.ws_ypixel);
  19. return 0;
  20. }