term.c 608 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "util.h"
  2. void get_term_dimensions(struct winsize *ws)
  3. {
  4. char *s = getenv("LINES");
  5. if (s != NULL) {
  6. ws->ws_row = atoi(s);
  7. s = getenv("COLUMNS");
  8. if (s != NULL) {
  9. ws->ws_col = atoi(s);
  10. if (ws->ws_row && ws->ws_col)
  11. return;
  12. }
  13. }
  14. #ifdef TIOCGWINSZ
  15. if (ioctl(1, TIOCGWINSZ, ws) == 0 &&
  16. ws->ws_row && ws->ws_col)
  17. return;
  18. #endif
  19. ws->ws_row = 25;
  20. ws->ws_col = 80;
  21. }
  22. void set_term_quiet_input(struct termios *old)
  23. {
  24. struct termios tc;
  25. tcgetattr(0, old);
  26. tc = *old;
  27. tc.c_lflag &= ~(ICANON | ECHO);
  28. tc.c_cc[VMIN] = 0;
  29. tc.c_cc[VTIME] = 0;
  30. tcsetattr(0, TCSANOW, &tc);
  31. }