billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=9f58d6837115a03db64cd862638edc9f8eaa94a7

commit 9f58d6837115a03db64cd862638edc9f8eaa94a7
Author: Boris Faure <[email protected]>
Date:   Sun Nov 24 18:06:21 2019 +0100

    options_behavior: display current memory usage of the backlog
---
 src/bin/backlog.c          | 10 ++++++++--
 src/bin/backlog.h          |  3 +++
 src/bin/options_behavior.c | 27 ++++++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/bin/backlog.c b/src/bin/backlog.c
index aac4db8..17a2b83 100644
--- a/src/bin/backlog.c
+++ b/src/bin/backlog.c
@@ -9,12 +9,18 @@ static int ts_uncomp = 0;
 static int ts_freeops = 0;
 static Eina_List *ptys = NULL;
 
-static int64_t mem_used = 0;
+static int64_t _mem_used = 0;
 
 static void
 _accounting_change(int64_t diff)
 {
-   mem_used += diff;
+   _mem_used += diff;
+}
+
+int64_t
+termpty_backlog_memory_get(void)
+{
+   return _mem_used;
 }
 
 
diff --git a/src/bin/backlog.h b/src/bin/backlog.h
index 0c3e5ce..dfe0fd7 100644
--- a/src/bin/backlog.h
+++ b/src/bin/backlog.h
@@ -21,6 +21,9 @@ termpty_backlog_size_set(Termpty *ty, size_t size);
 ssize_t
 termpty_backlog_length(Termpty *ty);
 
+int64_t
+termpty_backlog_memory_get(void);
+
 #define BACKLOG_ROW_GET(Ty, Y) \
    (&Ty->back[(Ty->backsize + ty->backpos - ((Y) - 1 )) % Ty->backsize])
 
diff --git a/src/bin/options_behavior.c b/src/bin/options_behavior.c
index 1fc4e4a..c945d5d 100644
--- a/src/bin/options_behavior.c
+++ b/src/bin/options_behavior.c
@@ -4,6 +4,8 @@
 #include <math.h>
 #include <Elementary.h>
 #include <assert.h>
+#include "termpty.h"
+#include "backlog.h"
 #include "config.h"
 #include "termio.h"
 #include "options.h"
@@ -17,6 +19,8 @@ typedef struct _Behavior_Ctx {
      Evas_Object *op_wh_current;
      Evas_Object *term;
      Evas_Object *sld_hide_cursor;
+     Evas_Object *backlock_label;
+     char *backlog_msg;
      Config *config;
 } Behavior_Ctx;
 
@@ -85,6 +89,24 @@ sback_units_format(double d)
     return (char*)eina_stringshare_printf(_("%'d lines"), 
sback_double_to_expo_int(d));
 }
 
+static void
+_update_backlog_title(Behavior_Ctx *ctx)
+{
+   char *factor = " KMG";
+   double amount = termpty_backlog_memory_get();
+
+   while (amount > 1024.0 && factor[1] != '\0')
+     {
+        amount /= 1024;
+        factor++;
+     }
+   eina_stringshare_del(ctx->backlog_msg);
+   ctx->backlog_msg = (char*) eina_stringshare_printf(
+      _("Scrollback (current memory usage: %'.2f%cB):"),
+      amount, factor[0]);
+   elm_object_text_set(ctx->backlock_label, ctx->backlog_msg);
+}
+
 static void
 _cb_op_behavior_sback_chg(void *data,
                           Evas_Object *obj,
@@ -95,6 +117,7 @@ _cb_op_behavior_sback_chg(void *data,
 
    config->scrollback = (double) 
sback_double_to_expo_int(elm_slider_value_get(obj));
    termio_config_update(ctx->term);
+   _update_backlog_title(ctx);
    config_save(config);
 }
 
@@ -187,6 +210,7 @@ _parent_del_cb(void *data,
 {
    Behavior_Ctx *ctx = data;
 
+   eina_stringshare_del(ctx->backlog_msg);
    free(ctx);
 }
 
@@ -563,7 +587,8 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
    o = elm_label_add(bx);
    evas_object_size_hint_weight_set(o, 0.0, 0.0);
    evas_object_size_hint_align_set(o, 0.0, 0.5);
-   elm_object_text_set(o, _("Scrollback:"));
+   ctx->backlock_label = o;
+   _update_backlog_title(ctx);
    elm_box_pack_end(bx, o);
    evas_object_show(o);
 

-- 


Reply via email to