don't automatically add new lines at each message

add ll_pause function
This commit is contained in:
milang 2019-09-21 12:48:06 +02:00
parent bb6407e6c5
commit 1f04e55306
No known key found for this signature in database
GPG Key ID: D287C9D6C33D9035
2 changed files with 69 additions and 31 deletions

View File

@ -2,18 +2,20 @@
#include <gint/keyboard.h>
#include <gint/display.h>
#include <gint/std/stdlib.h>
#include <gint/std/stdio.h>
#include <gint/defs/attributes.h>
#include <liblog.h>
#include <stdint.h>
#ifdef FX9860G
#define MAX_LENGHT 21
#define MAX_LENGHT 22
#define WIDTH 8
#endif
#ifdef FXCG50
#define MAX_LENGHT 150
#define MAX_LENGHT 132
#define WIDTH 17
#endif
@ -29,13 +31,15 @@ typedef struct log_line
char text[MAX_LENGHT];
#endif
void* next;
int cursor;
} log_line;
static log_line first_line=
{
0,
"<Log beginning>",
"",
0,
0
};
@ -48,10 +52,13 @@ static log_line* add_line()
current_line = current_line->next;
current_line->previous=previous;
current_line->next=0;
current_line->text[0]=' ';
current_line->cursor=0;
for (int i=0; i<MAX_LENGHT; i++)
current_line->text[i]='\0';
return current_line;
}
static void clear_log()
void ll_clear()
{
while (current_line->previous)
{
@ -59,6 +66,10 @@ static void clear_log()
free(current_line);
current_line=next;
}
current_line->next=0;
current_line->cursor=0;
for (int i=0; i<MAX_LENGHT; i++)
current_line->text[i]='\0';
}
static void show_line(const log_line* l, int y)
@ -66,52 +77,47 @@ static void show_line(const log_line* l, int y)
dtext(1, y, &l->text[0], C_BLACK, C_NONE);
}
static void set_character(char c, int x)
static void append_character(char c)
{
if (c=='\0' || c=='\n')
if (c=='\n')
{
current_line->text[x]= '\0';
current_line->text[current_line->cursor]= '\0';
add_line();
}
else
{
current_line->text[x] = c;
current_line->text[current_line->cursor] = c;
current_line->cursor ++;
if (current_line->cursor == MAX_LENGHT-1)
add_line();
current_line->text[current_line->cursor] = '\0';
#ifdef FXCG50
if (dsize(&current_line->text[0])>396-7)
{
add_line();
}
#endif
}
}
// log something
void ll_send(const char * txt)
{
add_line();
char c=1;
int i=0;
int p=0;
while (c)
{
c=txt[i];
set_character(c,p);
p++;
if (c=='\0' || c=='\n')
p=0;
if (p==MAX_LENGHT-1)
{
set_character('\0', p);
p=0;
}
#ifdef FXCG50
if (dsize(&current_line->text[0])>396-3)
{
set_character('\0', p);
p=0;
}
#endif
append_character(c);
i++;
}
}
void ll_display_custom(log_line* line)
{
dfont(NULL);
dclear(C_WHITE);
for (int i=0; i<8; i++)
{
@ -134,10 +140,35 @@ void ll_display()
ll_display_custom(current_line);
}
GNORETURN void ll_panic()
void ll_pause()
{
log_line* line=current_line;
while (1)
{
ll_display_custom(line);
int key = getkey().key;
if (key==KEY_UP)
{
log_line* linet=line->previous;
if (linet)
line=linet;
}
if (key==KEY_DOWN)
{
log_line* linet=line->next;
if (linet)
line=linet;
}
if (key==KEY_EXIT)
break;
}
}
GNORETURN void ll_panic(uint32_t code)
{
char str[10];
sprintf(str, "\nException occured : %d", code);
ll_send(str);
log_line* line=current_line;
while (1)
{

View File

@ -2,12 +2,19 @@
#define LLOG
// Display a message in the log stream
// you can add \n to start an new line ^^
void ll_send(const char * txt);
// Puts the 8 last lines of the stream
// Put the 8 last lines of the stream
void ll_display();
// Enable log displaying on panic
void ll_set_panic();
// Display log, enable scrolling, and waits the user to press Exit
void ll_pause();
// Clear log
void ll_clear();
#endif