diff options
Diffstat (limited to 'hex.c')
-rw-r--r-- | hex.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -149,6 +149,8 @@ static struct app_context lua_State *L; ///< Lua state int ref_format; ///< Reference to "string.format" struct str_map coders; ///< Map of coders by name + + int progress; ///< Decoding progressbar #endif // HAVE_LUA // Data: @@ -1000,8 +1002,25 @@ app_lua_chunk_newindex (lua_State *L) } static void +app_update_progress (int64_t real_offset) +{ + // Updating too often causes unnecessary slowdowns + int progress = real_offset * 20 / g_ctx.data_len; + if (progress <= g_ctx.progress) + return; + + g_ctx.progress = progress; + printf ("\rDecoding... %3d%%", progress * 5); + fflush (stdout); +} + +static void app_lua_mark (int64_t offset, int64_t len, const char *desc) { + // XXX: not all decoders go sequentially over the file + if (!g_ctx.polling && g_ctx.data_len) + app_update_progress (offset - g_ctx.data_offset); + // That would cause stupid entries, making trouble in marks_by_offset if (len <= 0) return; @@ -2015,6 +2034,9 @@ main (int argc, char *argv[]) exit_fatal ("Lua: decoding failed: %s", lua_tostring (g_ctx.L, -1)); lua_pop (g_ctx.L, 1); + + if (g_ctx.progress) + fputc ('\n', stdout); #endif // HAVE_LUA app_flatten_marks (); |