medium sized dollop
[vg.git] / src / vg / vg_console.h
index 8f9020cfcf0a4d60c94933f4f664aec870483d1f..6ef2d7837774fc01f29331915e0a148e46fbd6a2 100644 (file)
@@ -3,6 +3,10 @@
 #ifndef VG_CONSOLE_H
 #define VG_CONSOLE_H
 
+#include "vg/vg_ui.h"
+#include "vg/vg_log.h"
+
+
 struct vg_console
 {
        struct vg_convar
@@ -46,13 +50,10 @@ struct vg_console
        }
        *functions;
        
-       char lines[16][512];
-       u32 current, len;
-       
-       char input[512];
+       char input[96];
        int cursor_user, cursor_pos, string_length;
        
-       char history[32][512];
+       char history[32][96];
        int history_last, history_pos, history_count;
        
        int enabled;
@@ -111,14 +112,15 @@ static void vg_console_draw( void )
        if( !vg_console.enabled )
                return;
 
-       int ptr = vg_console.current-1;
+   vg_mutex_lock( &log_print_mutex );
 
+       int ptr = vg_log.buffer_line_current;
    int const fh = 14;
+   int console_lines = VG_MIN( 16, vg_log.buffer_line_count );
        
        ui_global_ctx.cursor[0] = 0;
        ui_global_ctx.cursor[1] = 0;
-       ui_global_ctx.cursor[3] = 
-      vg_list_size( vg_console.lines )*fh*vg_console.scale;
+       ui_global_ctx.cursor[3] = 16*fh*vg_console.scale;
        ui_fill_x( &ui_global_ctx );
        
        ui_new_node( &ui_global_ctx );
@@ -127,18 +129,19 @@ static void vg_console_draw( void )
        
                ui_global_ctx.cursor[3] = fh*vg_console.scale;
                ui_align_bottom( &ui_global_ctx ); 
-               
-               for( int i = 0; i < vg_console.len; i ++ )
+
+               for( int i=0; i<console_lines; i ++ )
                {
+                       ptr --;
+
                        if( ptr < 0 )
-                               ptr = vg_list_size( vg_console.lines )-1;
+                               ptr = vg_list_size( vg_log.buffer )-1;
          
                        ui_text( &ui_global_ctx, ui_global_ctx.cursor, 
-               vg_console.lines[ptr], vg_console.scale, 0 );
+               vg_log.buffer[ptr], vg_console.scale, 0 );
                        ui_global_ctx.cursor[1] -= fh*vg_console.scale;
-               
-                       ptr --;
                }
+
        }
        ui_end_down( &ui_global_ctx );
        
@@ -162,17 +165,7 @@ static void vg_console_draw( void )
                ui_fill_rect( &ui_global_ctx, ui_global_ctx.cursor, 0x66ffffff );
        }
        ui_end_down( &ui_global_ctx );
-}
-
-void vg_console_println( const char *str )
-{
-       if( vg_console.len < vg_list_size( vg_console.lines ) )
-               vg_console.len ++;
-       
-       strcpy( vg_console.lines[ vg_console.current ++ ], str );
-       
-       if( vg_console.current >= vg_list_size( vg_console.lines ) )
-               vg_console.current = 0;
+   vg_mutex_unlock( &log_print_mutex );
 }
 
 static int vg_console_list( int argc, char const *argv[] )
@@ -196,6 +189,14 @@ static int vg_console_list( int argc, char const *argv[] )
 
 static int vg_console_chartest( int argc, char const *argv[] )
 {
+vg_info(" Copyright  .        . .       -----, ,----- ,---.   .---.  " );
+vg_info(" 2021-2022  |\\      /| |           /  |      |    | |    /| " );
+vg_info("            | \\    / | +--        /   +----- +---'  |   / | " );
+vg_info("            |  \\  /  | |         /    |      |   \\  |  /  | " );
+vg_info("            |   \\/   | |        /     |      |    \\ | /   | " );
+vg_info("            '        ' '--' [] '----- '----- '     ' '---'  " 
+        "SOFTWARE" );
+
    vg_info( "\"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG\"\n" );
    vg_info( "'the quick brown fox jumps over the lazy dog'\n" );
    vg_info( ":;!@#$%^& 0123456789 +-*/=~ ()[]{}<>\n" );
@@ -204,25 +205,29 @@ static int vg_console_chartest( int argc, char const *argv[] )
 
 static void vg_console_init(void)
 {
-       vg_log_callback = vg_console_println;
-       
        vg_convar_push( (struct vg_convar)
-       { .name = "console_scale", .data = &vg_console.scale, 
+       { 
+      .name = "console_scale", .data = &vg_console.scale, 
       .data_type = k_convar_dtype_i32, 
                .opt_i32 = { .clamp = 1, .min = 1, .max = 7 },
       .update = NULL
    });
        
-       vg_function_push( (struct vg_cmd){
+       vg_function_push( (struct vg_cmd)
+   {
                .name = "list",
                .function = vg_console_list
        });
 
-   vg_function_push( (struct vg_cmd){
+   vg_function_push( (struct vg_cmd)
+   {
       .name = "chartest",
       .function = vg_console_chartest
    });
+}
 
+static void vg_console_load_autos(void)
+{
        /* Read and exec persistent commands */
        FILE *fp = fopen( "cfg/auto.conf", "r" );
        if( fp )