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.

61 lines
1.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectCURSESLoggingService.h"
  2. objectCURSESLoggingService::objectCURSESLoggingService() : WindowCLI(NULL){
  3. m_bLogging = true;
  4. #ifndef NEWT_CLI
  5. create( 0, 49, 121, 20 );
  6. #endif
  7. m_iLinesCount = 20;
  8. m_ppLines = (char **) malloc( m_iLinesCount * sizeof( char* ) );
  9. };
  10. objectCURSESLoggingService::objectCURSESLoggingService( int x, int y, int w, int h ): WindowCLI(NULL){
  11. m_bLogging = true;
  12. #ifndef NEWT_CLI
  13. create( x, y, w, h );
  14. #endif
  15. m_iLinesCount = h;
  16. m_ppLines = (char **) malloc( m_iLinesCount * sizeof( char* ) );
  17. for( int index = 0; index < m_iLinesCount; index++){
  18. m_ppLines[index] = NULL;
  19. };
  20. };
  21. objectCURSESLoggingService::~objectCURSESLoggingService(){
  22. for(int index = 0; index < m_iLinesCount; index++ ) {
  23. if( m_ppLines[index]!= NULL ) free( m_ppLines[index] );
  24. };
  25. free( m_ppLines );
  26. };
  27. void objectCURSESLoggingService::paint( void ){
  28. #ifndef NEWT_CLI
  29. createBox( true );
  30. for( int index = 0; index < (m_iLinesCount-1); index++) {
  31. if( m_ppLines[index]!= NULL ) mvwprintw( m_pWND, index+1 , 1, m_ppLines[index] );
  32. };
  33. wrefresh( m_pWND );
  34. #endif
  35. };
  36. void objectCURSESLoggingService::logMessage( CSTR Msg ){
  37. logMessage( (const char *)Msg );
  38. };
  39. void objectCURSESLoggingService::logMessage( const char *Msg ){
  40. if ( m_bLogging ){
  41. if( m_ppLines[m_iLinesCount-1]!= NULL ) free( m_ppLines[m_iLinesCount-1]);
  42. for(int index = m_iLinesCount-1; index > 0; index--) {
  43. m_ppLines[index] = m_ppLines[index-1];
  44. };
  45. m_ppLines[0] = (char *) malloc(512);
  46. if( m_ppLines[0] != NULL ){
  47. time_t LocalTime;
  48. tm *gmt_time;
  49. time( &LocalTime );
  50. gmt_time = gmtime( &LocalTime );
  51. sprintf( m_ppLines[0], "%04d-%02d-%02d %02d:%02d:%02d %s\n", 1900+gmt_time->tm_year, 1+gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Msg );
  52. };
  53. paint();
  54. };
  55. };