fixed instance loading forget to append basepath.. other path fixes (windows)
[csRadar.git] / csrLog.h
1 // Copyright (C) 2021 Harry Godden (hgn)
2
3 // Logging with colour
4 // ======================================================================================
5
6 void log_success( const char *fmt, ... );
7 void log_info( const char *fmt, ... );
8 void log_warn( const char *fmt, ... );
9 void log_error( const char *fmt, ... );
10
11 #ifdef CSR_EXECUTABLE
12
13 #define KNRM "\x1B[0m"
14 #define KRED "\x1B[31m"
15 #define KGRN "\x1B[32m"
16 #define KYEL "\x1B[33m"
17 #define KBLU "\x1B[34m"
18 #define KMAG "\x1B[35m"
19 #define KCYN "\x1B[36m"
20 #define KWHT "\x1B[37m"
21
22 #define CSR_LOG_WRITE( FILE, PREFIX ) \
23 fprintf( FILE, PREFIX ); \
24 va_list args; \
25 va_start( args, fmt ); \
26 vfprintf( FILE, fmt, args ); \
27 va_end( args ); \
28 fprintf( FILE, KNRM );
29
30 void log_success( const char *fmt, ... ) { CSR_LOG_WRITE( stdout, (KGRN "success" KWHT "| " KGRN) ); }
31 void log_info( const char *fmt, ... ) { CSR_LOG_WRITE( stdout, (KNRM " info" KWHT "| " KNRM) ); }
32 void log_warn( const char *fmt, ... ) { CSR_LOG_WRITE( stdout, (KYEL " warn" KWHT "| " KYEL) ); }
33 void log_error( const char *fmt, ... ) { CSR_LOG_WRITE( stderr, (KRED " error" KWHT "| " KRED) ); }
34
35 // TODO: Remove this?
36 const char *csr_prog_msg;
37 void csr_prog_begin( const char *msg )
38 {
39 csr_prog_msg = msg;
40 }
41
42 void csr_prog_update( float const percent )
43 {
44 int const k_track_length = 40;
45
46 printf( "\r %s %d%% |", csr_prog_msg, (int)(percent*100.f) );
47
48 // Calculate how many steps travelled
49 int cur_pos = ((float)k_track_length * (1.f-percent));
50
51 for( int i = 0; i < cur_pos; i ++ )
52 printf( " " );
53
54 printf( "🚂🚃🚃🚃🚃" );
55
56 for( int i = 0; i < k_track_length-cur_pos; i ++ )
57 printf( " " );
58
59 printf( "|" );
60
61 fflush( stdout );
62 }
63
64 void csr_prog_end(void)
65 {
66 csr_prog_update( 1.f );
67 printf( "\n" );
68 }
69
70 #endif