1
0
Fork 0
forked from len0rd/rockbox

lua Add scrollable stack traceback WIP

lua currently splashes a stack traceback on error
for deep tracebacks and especially on devices with smaller screens
this leaves out a lot of vital information

in the past I have resorted to splitting the traceback string or
even saving the return to a file

This patch provides a scrollable buffer with rudimentary text reflow
to allow you to read the whole traceback string

Upon traceback if you press nothing the screen will display for 5 seconds
If you press OK or CANCEL it will quit immediately
PREV/NEXT scrolls the list on button press timeout is disabled

lua now provides rb.splash_scroller(timeout, str)

example script provided too

Change-Id: Idbc8ce0c514196f0fae48c43aeaea8b60d6da1a5
This commit is contained in:
William Wilgus 2020-10-02 14:30:41 -04:00 committed by William Wilgus
parent 1916aca7f3
commit 80c3b84e08
5 changed files with 141 additions and 3 deletions

View file

@ -41,6 +41,122 @@ char *strerror(int errnum)
return NULL;
}
/* splash string and allow user to scroll around
* provides rudimentary text reflow
* timeout is disabled on user interaction
* returns the action that caused quit
* [ACTION_NONE, ACTION_STD_CANCEL, ACTION_STD_OK]
* !ACTION_NONE (only on initial timeout)!
* TIMEOUT can be TIMEOUT_BLOCK or time in ticks
*/
int splash_scroller(int timeout, const char* str)
{
int w, ch_w, ch_h;
rb->lcd_getstringsize("W", &ch_w, &ch_h);
const int max_w = LCD_WIDTH - (ch_w * 2);
const int max_lines = LCD_HEIGHT / ch_h - 1;
const int wrap_thresh = (LCD_WIDTH / 3);
const char *ch;
char *brk;
const int max_ch = (LCD_WIDTH / ch_w - 1) * 2;
char line[max_ch + 2]; /* display buffer */
const char break_chars[] = "@#$%^&*+-{}[]()/\\|<>:;.,? _\n\r\t";
int linepos, curline, linesdisp, realline, chars_next_break;
int action = ACTION_NONE;
int firstline = 0;
int cycles = 2; /* get action timeout returns immediately on first call */
while (cycles > 0)
{
/* walk whole buffer every refresh, only display relevant portion */
rb->lcd_clear_display();
curline = 0;
linepos = 0;
linesdisp = 0;
ch = str;
for (; *ch && linepos < max_ch; ch++)
{
if (ch[0] == '\t')
{
line[linepos++] = ' ';
line[linepos] = ' ';
}
else if (ch[0] == '\b' && timeout > 0)
{
line[linepos] = ' ';
rb->beep_play(1000, HZ, 1000);
}
else if (ch[0] < ' ') /* Dont copy control characters */
line[linepos] = (linepos == 0) ? '\0' : ' ';
else
line[linepos] = ch[0];
line[linepos + 1] = '\0'; /* terminate to check text extent */
rb->lcd_getstringsize(line, &w, NULL);
/* try to not split in middle of words */
if (w + wrap_thresh >= max_w && strpbrk (&line[linepos], break_chars))
{
brk = strpbrk(ch+1, break_chars);
chars_next_break = (brk - ch);
if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w)
{
if (!isprint(line[linepos]))
{
line[linepos] = '\0';
ch--; /* back-up we want it on the next line */
}
w += max_w;
}
}
if (w > max_w ||
(ch[0] >= '\n' && iscntrl(ch[0])) ||
ch[1] == '\0')
{
realline = curline - firstline;
if (realline >= 0 && realline < max_lines)
{
rb->lcd_putsxy(0, realline * ch_h, line);
linesdisp++;
}
linepos = 0;
curline++;
continue;
}
linepos++;
}
rb->lcd_update();
action = rb->get_action(CONTEXT_STD, timeout);
switch(action)
{
case ACTION_STD_OK:
case ACTION_STD_CANCEL:
cycles--;
/* Fall Through */
case ACTION_NONE:
cycles--;
break;
case ACTION_STD_PREV:
timeout = TIMEOUT_BLOCK; /* disable timeout */
if(firstline > 0)
firstline--;
break;
case ACTION_STD_NEXT:
timeout = TIMEOUT_BLOCK; /* disable timeout */
if (linesdisp == max_lines)
firstline++;
break;
}
}
return action;
}
long rb_pow(long x, long n)
{
long pow = 1;