All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] client: Rename window change signal for clarity
@ 2020-04-09 22:51 Tim Kourt
  2020-04-09 22:51 ` [PATCH 2/2] client: Automate display refresh enablement Tim Kourt
  2020-04-10 14:45 ` [PATCH 1/2] client: Rename window change signal for clarity Denis Kenzior
  0 siblings, 2 replies; 3+ messages in thread
From: Tim Kourt @ 2020-04-09 22:51 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1416 bytes --]

---
 client/display.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/client/display.c b/client/display.c
index 4a9f7be0..c285d1bc 100644
--- a/client/display.c
+++ b/client/display.c
@@ -40,7 +40,7 @@
 #define IWD_PROMPT COLOR_GREEN "[iwd]" COLOR_OFF "# "
 #define LINE_LEN 81
 
-static struct l_signal *resize_signal;
+static struct l_signal *window_change_signal;
 static struct l_io *io;
 static char dashed_line[LINE_LEN] = { [0 ... LINE_LEN - 2] = '-' };
 static char empty_line[LINE_LEN] = { [0 ... LINE_LEN - 2] = ' ' };
@@ -634,7 +634,7 @@ void display_quit(void)
 	rl_crlf();
 }
 
-static void signal_handler(void *user_data)
+static void window_change_signal_handler(void *user_data)
 {
 	if (display_refresh.cmd)
 		display_refresh_reset();
@@ -678,7 +678,9 @@ void display_init(void)
 
 	setlinebuf(stdout);
 
-	resize_signal = l_signal_create(SIGWINCH, signal_handler, NULL, NULL);
+	window_change_signal =
+		l_signal_create(SIGWINCH, window_change_signal_handler, NULL,
+									NULL);
 
 	rl_attempted_completion_function = command_completion;
 	rl_completion_display_matches_hook = display_completion_matches;
@@ -708,7 +710,7 @@ void display_exit(void)
 
 	l_io_destroy(io);
 
-	l_signal_remove(resize_signal);
+	l_signal_remove(window_change_signal);
 
 	if (history_path)
 		write_history(history_path);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] client: Automate display refresh enablement
  2020-04-09 22:51 [PATCH 1/2] client: Rename window change signal for clarity Tim Kourt
@ 2020-04-09 22:51 ` Tim Kourt
  2020-04-10 14:45 ` [PATCH 1/2] client: Rename window change signal for clarity Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Tim Kourt @ 2020-04-09 22:51 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 3400 bytes --]

The display refresh is automatically enabled or disabled depending on
the width of the window. This allows to avoid the incorrect display on
refresh for the small windows.
---
 client/display.c | 48 ++++++++++++++++++++++++++++++++++++++++++------
 client/display.h |  1 +
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/client/display.c b/client/display.c
index c285d1bc..b19759ea 100644
--- a/client/display.c
+++ b/client/display.c
@@ -28,6 +28,8 @@
 #include <stdio.h>
 #include <signal.h>
 #include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
 
 #include <readline/history.h>
 #include <readline/readline.h>
@@ -48,6 +50,7 @@ static struct l_timeout *refresh_timeout;
 static struct saved_input *agent_saved_input;
 
 static struct display_refresh {
+	bool enabled;
 	char *family;
 	char *entity;
 	const struct command *cmd;
@@ -56,7 +59,7 @@ static struct display_refresh {
 	size_t undo_lines;
 	struct l_queue *redo_entries;
 	bool recording;
-} display_refresh;
+} display_refresh = { .enabled = true };
 
 struct saved_input {
 	char *line;
@@ -221,12 +224,45 @@ void display_refresh_set_cmd(const char *family, const char *entity,
 	}
 }
 
+static void display_refresh_check_feasibility(void)
+{
+	const struct winsize ws;
+
+	ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+
+	if (ws.ws_col < LINE_LEN - 1) {
+		if (display_refresh.enabled) {
+			display_refresh.recording = false;
+			display(COLOR_YELLOW "Auto-refresh is disabled. "
+				"Enlarge window width to@least %u to enable."
+				"\n" COLOR_OFF, LINE_LEN - 1);
+			display_refresh.recording = true;
+		}
+
+		display_refresh.enabled = false;
+	} else {
+		display_refresh.enabled = true;
+	}
+}
+
+static void display_refresh_check_applicability(void)
+{
+	if (display_refresh.enabled && display_refresh.cmd)
+		display_refresh_redo_lines();
+	else if (display_refresh.cmd)
+		display_refresh_timeout_set();
+}
+
 static void timeout_callback(struct l_timeout *timeout, void *user_data)
 {
 	struct saved_input *input;
 
-	if (!display_refresh.cmd)
+	if (!display_refresh.enabled || !display_refresh.cmd) {
+		if (display_refresh.cmd)
+			display_refresh_timeout_set();
+
 		return;
+	}
 
 	input = save_input();
 	display_refresh_undo_lines();
@@ -336,8 +372,7 @@ void display_table_footer(void)
 {
 	display_text("\n");
 
-	if (display_refresh.cmd)
-		display_refresh_redo_lines();
+	display_refresh_check_applicability();
 }
 
 void display_command_line(const char *command_family,
@@ -636,8 +671,7 @@ void display_quit(void)
 
 static void window_change_signal_handler(void *user_data)
 {
-	if (display_refresh.cmd)
-		display_refresh_reset();
+	display_refresh_check_feasibility();
 }
 
 static char *history_path;
@@ -691,6 +725,8 @@ void display_init(void)
 							readline_callback);
 
 	rl_redisplay();
+
+	display_refresh_check_feasibility();
 }
 
 void display_exit(void)
diff --git a/client/display.h b/client/display.h
index fbae0c67..b5df944a 100644
--- a/client/display.h
+++ b/client/display.h
@@ -28,6 +28,7 @@ struct command_family;
 #define COLOR_GREEN	"\x1b[32m"
 #define COLOR_RED	"\x1B[0;91m"
 #define COLOR_BLUE	"\x1B[94m"
+#define COLOR_YELLOW	"\x1b[33m"
 #define COLOR_OFF	"\x1B[0m"
 #define CLEAR_SCREEN	"\033[2J"
 #define MARGIN		"  "
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] client: Rename window change signal for clarity
  2020-04-09 22:51 [PATCH 1/2] client: Rename window change signal for clarity Tim Kourt
  2020-04-09 22:51 ` [PATCH 2/2] client: Automate display refresh enablement Tim Kourt
@ 2020-04-10 14:45 ` Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2020-04-10 14:45 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

Hi Tim,

On 4/9/20 5:51 PM, Tim Kourt wrote:
> ---
>   client/display.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 

Both applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-10 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 22:51 [PATCH 1/2] client: Rename window change signal for clarity Tim Kourt
2020-04-09 22:51 ` [PATCH 2/2] client: Automate display refresh enablement Tim Kourt
2020-04-10 14:45 ` [PATCH 1/2] client: Rename window change signal for clarity Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.