diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2017-01-27 03:55:22 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2017-01-27 03:55:22 +0100 |
commit | 250cc7003788a51437e298f5ef416da44169b8a3 (patch) | |
tree | 4ad7fddc0a081df40d837182b1118e0260998e01 | |
parent | 416b52083d2357b950b3428364bf8e5548d0a23a (diff) | |
download | hex-250cc7003788a51437e298f5ef416da44169b8a3.tar.gz hex-250cc7003788a51437e298f5ef416da44169b8a3.tar.xz hex-250cc7003788a51437e298f5ef416da44169b8a3.zip |
Pull a progress bar out of our assprogressbar
-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 (); |