NCurses_Test (Hybris), posted by 'evilsocket' on Sat Jun 12 17:20:02 2010
Link - Raw - Download - Embed
  1. /*
  2.  * This file is part of the Hybris programming language interpreter.
  3.  *
  4.  * Copyleft of Simone Margaritelli aka evilsocket <evilsocket@gmail.com>
  5.  *
  6.  * Hybris is free software: you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation, either version 3 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * Hybris is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with Hybris. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. import std.*;
  20. include std.os.Dll;
  21.  
  22. function screen_init(){
  23. mainwnd = nc.initscr();
  24. nc.noecho();
  25. nc.cbreak();
  26. nc.nodelay( mainwnd, 1 );
  27. nc.refresh();
  28. nc.wrefresh(mainwnd);
  29. screen = nc.newwin(13, 27, 1, 1);
  30. nc.box( screen, '|', '-' );
  31. }
  32.  
  33. function update_display() {
  34. t = time();
  35.  
  36. nc.curs_set(0);
  37. nc.mvwprintw( screen, 1, 1, "-------- HEADER --------");
  38. nc.mvwprintw( screen, 3, 6, "TIME: %d:%d:%d", t.hour, t.min, t.sec);
  39. nc.mvwprintw( screen, 5, 6, "DATE: %d-%d-%d", t.mday, t.month, t.year);
  40. nc.mvwprintw( screen, 7, 6, "PRESS q TO END");
  41. nc.mvwprintw( screen, 10, 1, "-------- FOOTER --------");
  42. nc.wrefresh(screen);
  43. nc.refresh();
  44. }
  45.  
  46. try{
  47. nc = new Dll( "libncurses.so" );
  48. screen = null;
  49.  
  50. screen_init();
  51.  
  52. while( nc.getch() != 113 ) {
  53. update_display();
  54. sleep(1);
  55. }
  56.  
  57. nc.endwin();
  58. }
  59. catch( e ){
  60. e.print();
  61. }