about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorSimon Effenberg <savar@schuldeigen.de>2015-01-12 11:32:32 +0100
committerSimon Effenberg <savar@schuldeigen.de>2015-01-12 11:32:32 +0100
commit34148e21012289b8ebf4ba5a3e2aa8b65051fd55 (patch)
treee87d91c61d711d5d5f9652a9e60aa01a8e905bc8 /src/command
parentc7ff3255b8bd4bed2f825255a4fe28940db533b2 (diff)
downloadprofani-tty-34148e21012289b8ebf4ba5a3e2aa8b65051fd55.tar.gz
adding preference option for dynamic input blocking
/inpblock is now having subcommands 'timeout' and 'dynamic'
with:

/inpblock timeout <milliseconds>

and

/inpblock dynamic <on|off>

Defaults are:

/inpblock timeout 500
/inpblock dynamic on

To get the old behavior specify:

/inpblock timeout 20
/inpblock dynamic off

The dynamic mode will block incrementally after something
should be written to the window or after a key was pressed. So pressing
a key would set the timeout to 0ms and after 10 timeouts to the next
bigger one.

Example (with dynamic mode on):

"/inpblock timeout 50"

timeout series:

10x 0ms
10x 10ms (0ms + 10 times since last keypress)
10x 30ms (10ms + 20 times since last keypress)
*x50ms until next key was pressed or
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c20
-rw-r--r--src/command/commands.c37
2 files changed, 45 insertions, 12 deletions
diff --git a/src/command/command.c b/src/command/command.c
index f2ceaa82..bfc05f7e 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -623,14 +623,20 @@ static struct cmd_t command_defs[] =
           NULL } } },
 
     { "/inpblock",
-        cmd_inpblock, parse_args, 1, 1, &cons_inpblock_setting,
-        { "/inpblock millis", "Input blocking delay.",
-        { "/inpblock millis",
+        cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting,
+        { "/inpblock [timeout|dynamic] [millis|on|off]", "Input blocking delay (dynamic or static).",
+        { "/inpblock [timeout|dynamic] [millis|on|off]",
           "----------------",
-          "Time to wait in milliseconds before reading input from the terminal buffer, defaults to 20.",
-          "Valid values are 1-1000.",
-          "A higher value will result in less CPU usage, but a noticable delay for response to input.",
-          "A lower value will result in higher CPU usage, but faster response to input.",
+          "Setting for how long to wait for input before checking for new messages or checking for state",
+          "changes like 'idle'.",
+          "timeout : Time to wait in milliseconds before reading input from the terminal buffer, defaults to 500.",
+          "        : Valid values are 1-1000.",
+          "dynamic : Either use the timeout statically or use a dynamic variant which is responsive after an input",
+          "        : and blocks longer (up to the specified 'timeout').",
+          "        : on|off",
+          "A higher value will result in less CPU usage (irrespective if dynamic is on or off), but a noticable",
+          "delay for response to input if dynamic is off.",
+          "A lower value will result in higher CPU usage, but faster response to input if dynamic is off.",
           NULL } } },
 
     { "/notify",
diff --git a/src/command/commands.c b/src/command/commands.c
index 5aae8fe5..2126800d 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -3450,13 +3450,40 @@ cmd_notify(gchar **args, struct cmd_help_t help)
 gboolean
 cmd_inpblock(gchar **args, struct cmd_help_t help)
 {
-    char *value = args[0];
+    char *subcmd = args[0];
+    char *value = args[1];
     int intval;
-    if (_strtoi(value, &intval, 1, 1000) == 0) {
-        cons_show("Input blocking set to %d milliseconds.", intval);
-        prefs_set_inpblock(intval);
-        ui_input_nonblocking(FALSE);
+    if (strcmp(subcmd, "timeout") == 0) {
+        if (value == NULL) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
+
+        if (_strtoi(value, &intval, 1, 1000) == 0) {
+            cons_show("Input blocking set to %d milliseconds.", intval);
+            prefs_set_inpblock(intval);
+            ui_input_nonblocking(FALSE);
+        }
+
+        return TRUE;
+    }
+
+    if (strcmp(subcmd, "dynamic") == 0) {
+        if (value == NULL) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
+
+        if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
+            cons_show("Dynamic must be one of 'on' or 'off'");
+            return TRUE;
+        }
+
+        return _cmd_set_boolean_preference(value, help, "Dynamic input blocking", PREF_INPBLOCK_DYNAMIC);
     }
+
+    cons_show("Usage: %s", help.usage);
+
     return TRUE;
 }