aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-11-22 17:49:27 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-11-22 17:49:27 +0100
commitf69edd6606dc7ed720a2328cc434e3f28a09e951 (patch)
tree8bdb536ee99b1b9bf11e6ec5842a375a46ef10b7
parent385de6f4fe796fc480bf983decd742c338daa8d8 (diff)
downloadxK-f69edd6606dc7ed720a2328cc434e3f28a09e951.tar.gz
xK-f69edd6606dc7ed720a2328cc434e3f28a09e951.tar.xz
xK-f69edd6606dc7ed720a2328cc434e3f28a09e951.zip
degesch: optimize prompt changes
We used to do lots of unnecessary redisplays.
-rw-r--r--degesch.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/degesch.c b/degesch.c
index 436e9eb..f4deab3 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5056,6 +5056,16 @@ make_prompt (struct app_context *ctx, struct str *output)
}
static void
+input_maybe_set_prompt (struct input *self, char *new_prompt)
+{
+ // Redisplay can be an expensive operation
+ if (self->prompt && !strcmp (new_prompt, self->prompt))
+ free (new_prompt);
+ else
+ input_set_prompt (self, new_prompt);
+}
+
+static void
refresh_prompt (struct app_context *ctx)
{
bool have_attributes = !!get_attribute_printer (stdout);
@@ -5070,7 +5080,7 @@ refresh_prompt (struct app_context *ctx)
if (have_attributes)
{
// XXX: to be completely correct, we should use tputs, but we cannot
- input_set_prompt (&ctx->input, xstrdup_printf ("%c%s%c%s%c%s%c",
+ input_maybe_set_prompt (&ctx->input, xstrdup_printf ("%c%s%c%s%c%s%c",
INPUT_START_IGNORE, ctx->attrs[ATTR_PROMPT],
INPUT_END_IGNORE,
localized,
@@ -5079,7 +5089,7 @@ refresh_prompt (struct app_context *ctx)
free (localized);
}
else
- input_set_prompt (&ctx->input, localized);
+ input_maybe_set_prompt (&ctx->input, localized);
}
// --- Helpers -----------------------------------------------------------------