diff options
author | William Wilgus <wilgus.william@gmail.com> | 2020-10-02 14:30:41 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2020-10-03 22:09:52 +0000 |
commit | 80c3b84e08a1debc0e5af8567f9eeb0b1716303a (patch) | |
tree | 13763bcdf8c0a4e1bddab713a84145621ccc7213 /apps/plugins | |
parent | 1916aca7f3e76dd5440a9fa22ef4ea623bda8512 (diff) | |
download | rockbox-80c3b84e08a1debc0e5af8567f9eeb0b1716303a.tar.gz rockbox-80c3b84e08a1debc0e5af8567f9eeb0b1716303a.zip |
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
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/lua/rockaux.c | 116 | ||||
-rw-r--r-- | apps/plugins/lua/rockconf.h | 1 | ||||
-rw-r--r-- | apps/plugins/lua/rocklib.c | 9 | ||||
-rw-r--r-- | apps/plugins/lua/rocklua.c | 17 | ||||
-rw-r--r-- | apps/plugins/lua_scripts/splashscroller.lua | 1 |
5 files changed, 141 insertions, 3 deletions
diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c index 734b6a8324..7ed82f616d 100644 --- a/apps/plugins/lua/rockaux.c +++ b/apps/plugins/lua/rockaux.c | |||
@@ -41,6 +41,122 @@ char *strerror(int errnum) | |||
41 | return NULL; | 41 | return NULL; |
42 | } | 42 | } |
43 | 43 | ||
44 | /* splash string and allow user to scroll around | ||
45 | * provides rudimentary text reflow | ||
46 | * timeout is disabled on user interaction | ||
47 | * returns the action that caused quit | ||
48 | * [ACTION_NONE, ACTION_STD_CANCEL, ACTION_STD_OK] | ||
49 | * !ACTION_NONE (only on initial timeout)! | ||
50 | * TIMEOUT can be TIMEOUT_BLOCK or time in ticks | ||
51 | */ | ||
52 | int splash_scroller(int timeout, const char* str) | ||
53 | { | ||
54 | int w, ch_w, ch_h; | ||
55 | rb->lcd_getstringsize("W", &ch_w, &ch_h); | ||
56 | |||
57 | const int max_w = LCD_WIDTH - (ch_w * 2); | ||
58 | const int max_lines = LCD_HEIGHT / ch_h - 1; | ||
59 | const int wrap_thresh = (LCD_WIDTH / 3); | ||
60 | const char *ch; | ||
61 | char *brk; | ||
62 | |||
63 | const int max_ch = (LCD_WIDTH / ch_w - 1) * 2; | ||
64 | char line[max_ch + 2]; /* display buffer */ | ||
65 | const char break_chars[] = "@#$%^&*+-{}[]()/\\|<>:;.,? _\n\r\t"; | ||
66 | |||
67 | int linepos, curline, linesdisp, realline, chars_next_break; | ||
68 | int action = ACTION_NONE; | ||
69 | int firstline = 0; | ||
70 | int cycles = 2; /* get action timeout returns immediately on first call */ | ||
71 | |||
72 | while (cycles > 0) | ||
73 | { | ||
74 | /* walk whole buffer every refresh, only display relevant portion */ | ||
75 | rb->lcd_clear_display(); | ||
76 | curline = 0; | ||
77 | linepos = 0; | ||
78 | linesdisp = 0; | ||
79 | ch = str; | ||
80 | for (; *ch && linepos < max_ch; ch++) | ||
81 | { | ||
82 | if (ch[0] == '\t') | ||
83 | { | ||
84 | line[linepos++] = ' '; | ||
85 | line[linepos] = ' '; | ||
86 | } | ||
87 | else if (ch[0] == '\b' && timeout > 0) | ||
88 | { | ||
89 | line[linepos] = ' '; | ||
90 | rb->beep_play(1000, HZ, 1000); | ||
91 | } | ||
92 | else if (ch[0] < ' ') /* Dont copy control characters */ | ||
93 | line[linepos] = (linepos == 0) ? '\0' : ' '; | ||
94 | else | ||
95 | line[linepos] = ch[0]; | ||
96 | |||
97 | line[linepos + 1] = '\0'; /* terminate to check text extent */ | ||
98 | rb->lcd_getstringsize(line, &w, NULL); | ||
99 | |||
100 | /* try to not split in middle of words */ | ||
101 | if (w + wrap_thresh >= max_w && strpbrk (&line[linepos], break_chars)) | ||
102 | { | ||
103 | brk = strpbrk(ch+1, break_chars); | ||
104 | chars_next_break = (brk - ch); | ||
105 | if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w) | ||
106 | { | ||
107 | if (!isprint(line[linepos])) | ||
108 | { | ||
109 | line[linepos] = '\0'; | ||
110 | ch--; /* back-up we want it on the next line */ | ||
111 | } | ||
112 | w += max_w; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | if (w > max_w || | ||
117 | (ch[0] >= '\n' && iscntrl(ch[0])) || | ||
118 | ch[1] == '\0') | ||
119 | { | ||
120 | realline = curline - firstline; | ||
121 | if (realline >= 0 && realline < max_lines) | ||
122 | { | ||
123 | rb->lcd_putsxy(0, realline * ch_h, line); | ||
124 | linesdisp++; | ||
125 | } | ||
126 | linepos = 0; | ||
127 | curline++; | ||
128 | continue; | ||
129 | } | ||
130 | linepos++; | ||
131 | } | ||
132 | |||
133 | rb->lcd_update(); | ||
134 | |||
135 | action = rb->get_action(CONTEXT_STD, timeout); | ||
136 | switch(action) | ||
137 | { | ||
138 | case ACTION_STD_OK: | ||
139 | case ACTION_STD_CANCEL: | ||
140 | cycles--; | ||
141 | /* Fall Through */ | ||
142 | case ACTION_NONE: | ||
143 | cycles--; | ||
144 | break; | ||
145 | case ACTION_STD_PREV: | ||
146 | timeout = TIMEOUT_BLOCK; /* disable timeout */ | ||
147 | if(firstline > 0) | ||
148 | firstline--; | ||
149 | break; | ||
150 | case ACTION_STD_NEXT: | ||
151 | timeout = TIMEOUT_BLOCK; /* disable timeout */ | ||
152 | if (linesdisp == max_lines) | ||
153 | firstline++; | ||
154 | break; | ||
155 | } | ||
156 | } | ||
157 | return action; | ||
158 | } | ||
159 | |||
44 | long rb_pow(long x, long n) | 160 | long rb_pow(long x, long n) |
45 | { | 161 | { |
46 | long pow = 1; | 162 | long pow = 1; |
diff --git a/apps/plugins/lua/rockconf.h b/apps/plugins/lua/rockconf.h index 6a1141f86a..503c2c7dec 100644 --- a/apps/plugins/lua/rockconf.h +++ b/apps/plugins/lua/rockconf.h | |||
@@ -48,6 +48,7 @@ unsigned long strtoul(const char *str, char **endptr, int base); | |||
48 | size_t strftime(char* dst, size_t max, const char* format, const struct tm* tm); | 48 | size_t strftime(char* dst, size_t max, const char* format, const struct tm* tm); |
49 | long lfloor(long x); | 49 | long lfloor(long x); |
50 | long lpow(long x, long y); | 50 | long lpow(long x, long y); |
51 | int splash_scroller(int timeout, const char* str); | ||
51 | 52 | ||
52 | #define floor lfloor | 53 | #define floor lfloor |
53 | #define pow lpow | 54 | #define pow lpow |
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 8eab08f987..5f0143efbb 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -287,6 +287,14 @@ RB_WRAP(do_menu) | |||
287 | return 1; | 287 | return 1; |
288 | } | 288 | } |
289 | 289 | ||
290 | RB_WRAP(splash_scroller) | ||
291 | { | ||
292 | int timeout = luaL_checkint(L, 1); | ||
293 | const char *str = luaL_checkstring(L, 2); | ||
294 | int action = splash_scroller(timeout, str); /*rockaux.c*/ | ||
295 | lua_pushinteger(L, action); | ||
296 | return 1; | ||
297 | } | ||
290 | 298 | ||
291 | /* DEVICE AUDIO / PLAYLIST CONTROL */ | 299 | /* DEVICE AUDIO / PLAYLIST CONTROL */ |
292 | 300 | ||
@@ -948,6 +956,7 @@ static const luaL_Reg rocklib[] = | |||
948 | RB_FUNC(kbd_input), | 956 | RB_FUNC(kbd_input), |
949 | RB_FUNC(gui_syncyesno_run), | 957 | RB_FUNC(gui_syncyesno_run), |
950 | RB_FUNC(do_menu), | 958 | RB_FUNC(do_menu), |
959 | RB_FUNC(splash_scroller), | ||
951 | 960 | ||
952 | /* DEVICE AUDIO / SOUND / PLAYLIST CONTROL */ | 961 | /* DEVICE AUDIO / SOUND / PLAYLIST CONTROL */ |
953 | RB_FUNC(audio), | 962 | RB_FUNC(audio), |
diff --git a/apps/plugins/lua/rocklua.c b/apps/plugins/lua/rocklua.c index 79f6bae953..3909f3008f 100644 --- a/apps/plugins/lua/rocklua.c +++ b/apps/plugins/lua/rocklua.c | |||
@@ -86,7 +86,7 @@ static int db_errorfb (lua_State *L) { | |||
86 | if (lua_gettop(L) == arg) | 86 | if (lua_gettop(L) == arg) |
87 | lua_pushliteral(L, ""); | 87 | lua_pushliteral(L, ""); |
88 | else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ | 88 | else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ |
89 | else lua_pushliteral(L, "\n"); | 89 | else lua_pushliteral(L, "\n\n"); |
90 | lua_pushliteral(L, "stack traceback: "); | 90 | lua_pushliteral(L, "stack traceback: "); |
91 | while (lua_getstack(L1, level++, &ar)) { | 91 | while (lua_getstack(L1, level++, &ar)) { |
92 | if (level > LEVELS1 && firstpart) { | 92 | if (level > LEVELS1 && firstpart) { |
@@ -101,7 +101,7 @@ static int db_errorfb (lua_State *L) { | |||
101 | firstpart = 0; | 101 | firstpart = 0; |
102 | continue; | 102 | continue; |
103 | } | 103 | } |
104 | lua_pushliteral(L, "\n\t"); | 104 | lua_pushliteral(L, "\n\n\t"); |
105 | lua_getinfo(L1, "Snl", &ar); | 105 | lua_getinfo(L1, "Snl", &ar); |
106 | char* filename = rb->strrchr(ar.short_src, '/'); /* remove path */ | 106 | char* filename = rb->strrchr(ar.short_src, '/'); /* remove path */ |
107 | lua_pushfstring(L, "%s:", filename ? filename : ar.short_src); | 107 | lua_pushfstring(L, "%s:", filename ? filename : ar.short_src); |
@@ -118,8 +118,10 @@ static int db_errorfb (lua_State *L) { | |||
118 | lua_pushfstring(L, " in function <%s:%d>", | 118 | lua_pushfstring(L, " in function <%s:%d>", |
119 | ar.short_src, ar.linedefined); | 119 | ar.short_src, ar.linedefined); |
120 | } | 120 | } |
121 | |||
121 | lua_concat(L, lua_gettop(L) - arg); | 122 | lua_concat(L, lua_gettop(L) - arg); |
122 | } | 123 | } |
124 | lua_pushfstring(L, "\n\nRam Used: %d Kb", lua_gc (L, LUA_GCCOUNT, 0)); | ||
123 | lua_concat(L, lua_gettop(L) - arg); | 125 | lua_concat(L, lua_gettop(L) - arg); |
124 | return 1; | 126 | return 1; |
125 | } | 127 | } |
@@ -225,6 +227,14 @@ static int lua_split_arguments(lua_State *L, const char *filename) | |||
225 | return 2; | 227 | return 2; |
226 | } | 228 | } |
227 | 229 | ||
230 | static void display_traceback(const char *errstr) | ||
231 | { | ||
232 | #if 1 | ||
233 | splash_scroller(HZ * 5, errstr); /*rockaux.c*/ | ||
234 | #else | ||
235 | rb->splash(10 * HZ, errstr); | ||
236 | #endif | ||
237 | } | ||
228 | /***************** Plugin Entry Point *****************/ | 238 | /***************** Plugin Entry Point *****************/ |
229 | enum plugin_status plugin_start(const void* parameter) | 239 | enum plugin_status plugin_start(const void* parameter) |
230 | { | 240 | { |
@@ -251,7 +261,8 @@ enum plugin_status plugin_start(const void* parameter) | |||
251 | 261 | ||
252 | if (lu_status) { | 262 | if (lu_status) { |
253 | DEBUGF("%s\n", lua_tostring(Ls, -1)); | 263 | DEBUGF("%s\n", lua_tostring(Ls, -1)); |
254 | rb->splash(10 * HZ, lua_tostring(Ls, -1)); | 264 | display_traceback(lua_tostring(Ls, -1)); |
265 | //rb->splash(10 * HZ, lua_tostring(Ls, -1)); | ||
255 | /*lua_pop(Ls, 1);*/ | 266 | /*lua_pop(Ls, 1);*/ |
256 | } | 267 | } |
257 | lua_close(Ls); | 268 | lua_close(Ls); |
diff --git a/apps/plugins/lua_scripts/splashscroller.lua b/apps/plugins/lua_scripts/splashscroller.lua new file mode 100644 index 0000000000..78a7266de8 --- /dev/null +++ b/apps/plugins/lua_scripts/splashscroller.lua | |||
@@ -0,0 +1 @@ | |||
rb.splash_scroller(rb.HZ * 5, "This is a rb.splash_scroller test, it is meant to reflow text into a format easily digestable on small screen devices.\n\n it is not particularly adept at this as we strive for the bare minimum in order to leave room for YOUR code. :) \n\nHowever, it does recognize \t\\t \r\\r\n\\n\n\\b (bell)\b") | |||