Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ecran.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/utsname.h>
  5. #include <getopt.h>
  6. #include <ncurses.h>
  7. #include "ecran.h"
  8. extern int verbosity;
  9. /* ---------------------------------------------------------------- */
  10. void bordure(WINDOW * w, char *texte, int type)
  11. {
  12. if (type)
  13. box(w, 0, 0);
  14. else
  15. wborder(w, '|', '|', '-', '-', '+', '+', '+', '+');
  16. wstandout(w); mvwaddstr(w, 0, 3, texte); wstandend(w);
  17. wrefresh(w);
  18. }
  19. /* ---------------------------------------------------------------- */
  20. int kbhit(void)
  21. {
  22. int r, ch;
  23. nodelay(stdscr, TRUE);
  24. noecho();
  25. // check for input
  26. ch = getch();
  27. if( ch == ERR) { // no input
  28. r = FALSE;
  29. }
  30. else { // input
  31. r = TRUE;
  32. ungetch(ch);
  33. }
  34. // restore block and echo
  35. echo();
  36. nodelay(stdscr, FALSE);
  37. return r;
  38. }
  39. /* ---------------------------------------------------------------- */
  40. int aff_message(char *txt)
  41. {
  42. static int pass = 0;
  43. #if TRACE
  44. fprintf(stderr, "%s [%s]\n", __func__, txt);
  45. #endif
  46. standout();
  47. mvhline(LINES-1, 0, ' ', COLS);
  48. mvaddch(LINES-1, 0, "\\|/-"[(pass++)%4]);
  49. mvaddstr(LINES-1, 2, txt);
  50. standend();
  51. refresh();
  52. return 0;
  53. }
  54. /* ---------------------------------------------------------------- */
  55. void barre_inverse(char c, int ligne)
  56. {
  57. int foo;
  58. standout();
  59. for (foo=0; foo<COLS; foo++)
  60. mvaddch(ligne, foo, c);
  61. standend();
  62. /* refresh(); */
  63. }
  64. /* ---------------------------------------------------------------- */
  65. /* make display on the standard screen (stdscr) */
  66. int fond_ecran(char *title)
  67. {
  68. char *tp;
  69. struct utsname utsn;
  70. int foo;
  71. char buffer[200];
  72. tp = " DD2 Monitoring by tTh 2019 ";
  73. if (NULL != title) tp = title;
  74. barre_inverse(' ', 0);
  75. standout();
  76. mvaddstr(0, 2, tp);
  77. if (verbosity) {
  78. sprintf(buffer, " ecr: %dx%d ", COLS, LINES);
  79. fprintf(stderr, "%s ==> %s\n", __func__, buffer);
  80. foo = strlen(buffer);
  81. mvaddstr(0, COLS-2-foo, buffer);
  82. }
  83. /* get and display hostname */
  84. foo = uname(&utsn);
  85. if ( !foo ) {
  86. mvaddstr(0, 2+strlen(tp), "on");
  87. mvaddstr(0, 5+strlen(tp), utsn.nodename);
  88. }
  89. standend();
  90. refresh();
  91. return 0;
  92. }
  93. /* ---------------------------------------------------------------- */