All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH 04/14] client: update station to use display_table_row
Date: Wed,  6 Jul 2022 14:28:41 -0700	[thread overview]
Message-ID: <20220706212851.92685-4-prestwoj@gmail.com> (raw)
In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com>

This includes updating diagnostics too, otherwise the output becomes
really nasty.
---
 client/diagnostic.c | 32 +++++++++++++-------------------
 client/station.c    | 42 +++++++++++++++++++-----------------------
 2 files changed, 32 insertions(+), 42 deletions(-)

diff --git a/client/diagnostic.c b/client/diagnostic.c
index 9e255918..6360b7e2 100644
--- a/client/diagnostic.c
+++ b/client/diagnostic.c
@@ -69,12 +69,13 @@ static bool display_bitrate_100kbps(struct l_dbus_message_iter *variant,
 				int name_column_width, int value_column_width)
 {
 	uint32_t rate;
+	char str[50];
 
 	if (!l_dbus_message_iter_get_variant(variant, "u", &rate))
 		return false;
 
-	display("%s%-*s%-*u Kbit/s\n", margin, name_column_width, key,
-			value_column_width, rate * 100);
+	sprintf(str, "%u Kbit/s", rate * 100);
+	display_table_row(margin, 3, 8, "", name_column_width, key, value_column_width, str);
 
 	return true;
 }
@@ -110,6 +111,7 @@ void diagnostic_display(struct l_dbus_message_iter *dict,
 		uint32_t u_value;
 		int16_t n_value;
 		uint8_t y_value;
+		int bytes;
 
 		map = find_mapping(key, diagnostic_mapping);
 		if (!map)
@@ -132,9 +134,7 @@ void diagnostic_display(struct l_dbus_message_iter *dict,
 							&s_value))
 				goto parse_error;
 
-			sprintf(display_text, "%s%-*s%-*s", margin,
-					name_column_width, key,
-					value_column_width, s_value);
+			bytes = sprintf(display_text, "%s", s_value);
 			break;
 
 		case 'u':
@@ -142,9 +142,7 @@ void diagnostic_display(struct l_dbus_message_iter *dict,
 							&u_value))
 				goto parse_error;
 
-			sprintf(display_text, "%s%-*s%-*u", margin,
-						name_column_width, key,
-						value_column_width, u_value);
+			bytes = sprintf(display_text, "%u", u_value);
 			break;
 
 		case 'n':
@@ -152,9 +150,7 @@ void diagnostic_display(struct l_dbus_message_iter *dict,
 							&n_value))
 				goto parse_error;
 
-			sprintf(display_text, "%s%-*s%-*i", margin,
-						name_column_width, key,
-						value_column_width, n_value);
+			bytes = sprintf(display_text, "%i", n_value);
 			break;
 
 		case 'y':
@@ -162,21 +158,19 @@ void diagnostic_display(struct l_dbus_message_iter *dict,
 							&y_value))
 				goto parse_error;
 
-			sprintf(display_text, "%s%-*s%-*u", margin,
-						name_column_width, key,
-						value_column_width, y_value);
+			bytes = sprintf(display_text, "%u", y_value);
 			break;
 
 		default:
-			display("type %c not handled", map->type);
+			display("type %c not handled\n", map->type);
 			continue;
 		}
 
 		if (map->units)
-			display("%s %s\n", display_text,
-					(const char *)map->units);
-		else
-			display("%s\n", display_text);
+			sprintf(display_text + bytes, " %s", map->units);
+
+		display_table_row(margin, 3, 8, "", name_column_width,
+					key, value_column_width, display_text);
 	}
 
 	return;
diff --git a/client/station.c b/client/station.c
index 68d7ee8c..1a573674 100644
--- a/client/station.c
+++ b/client/station.c
@@ -186,8 +186,7 @@ static void display_addresses(const char *device_name)
 				continue;
 
 			have_address = true;
-			display("%s%*s  %-*s%-*s\n", MARGIN, 8, "", 20,
-				"IPv4 address", 47, addrstr);
+			display_table_row(MARGIN, 3, 8, "", 20, "IPv4 address", 47, addrstr);
 		}
 	}
 
@@ -200,8 +199,7 @@ static void display_addresses(const char *device_name)
 	if (r < 0 || r == 1)
 		return;
 
-	display("%s%*s  %-*s%-*s\n", MARGIN, 8, "", 20,
-			"No IP addresses", 47, "Is DHCP client configured?");
+	display_table_row(MARGIN, 3, 8, "", 20, "No IP addresses", 47, "Is DHCP client configured?");
 }
 
 
@@ -215,9 +213,9 @@ static void display_station(const char *device_name,
 	l_free(caption);
 
 	if (station->connected_network) {
-		display("%s%*s  %-*s%-*s\n", MARGIN, 8, "", 20,
-				"Connected network", 47,
-				network_get_name(station->connected_network));
+		display_table_row(MARGIN, 3, 8, "", 20, "Connected network",
+			47, network_get_name(station->connected_network));
+
 		display_addresses(device_name);
 
 		/*
@@ -246,10 +244,8 @@ static void display_station_inline(const char *margin, const void *data)
 	if (!identity)
 		return;
 
-	display("%s%-*s%-*s%-*s\n", margin,
-			20, identity,
-			15, station->state ? : "",
-			8, station->scanning ? "scanning" : "");
+	display_table_row(margin, 3, 20, identity, 15, station->state ? : "",
+				8, station->scanning ? "scanning" : "");
 }
 
 static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
@@ -258,7 +254,8 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
 	struct l_queue *match =
 		proxy_interface_find_all(IWD_STATION_INTERFACE, NULL, NULL);
 
-	display_table_header("Devices in Station Mode", MARGIN "%-*s%-*s%-*s",
+	display_table_header("Devices in Station Mode",
+				MARGIN "%-*s  %-*s  %-*s",
 				20, "Name", 15, "State", 8, "Scanning");
 
 	if (!match) {
@@ -416,7 +413,7 @@ static void ordered_networks_display(struct l_queue *ordered_networks)
 	char *dbms = NULL;
 	const struct l_queue_entry *entry;
 
-	display_table_header("Available networks", "%s%-*s%-*s%-*s%*s",
+	display_table_header("Available networks", "%s%-*s  %-*s  %-*s  %*s",
 					MARGIN, 2, "", 32, "Network name",
 					18, "Security", 6, "Signal");
 
@@ -441,11 +438,11 @@ static void ordered_networks_display(struct l_queue *ordered_networks)
 		if (display_signal_as_dbms)
 			dbms = l_strdup_printf("%d", network->signal_strength);
 
-		display("%s%-*s%-*s%-*s%-*s\n", MARGIN, 2,
-			network_is_connected(network_i) ?
-				COLOR_BOLDGRAY "> " COLOR_OFF : "",
-			32, network_name, 18, network_type,
-			6, display_signal_as_dbms ? dbms :
+		display_table_row(MARGIN, 4, 2,
+				network_is_connected(network_i) ?
+				COLOR_BOLDGRAY "> " COLOR_OFF: "",
+				32, network_name, 18, network_type, 6,
+				display_signal_as_dbms ? dbms :
 				dbms_tostars(network->signal_strength));
 
 		if (display_signal_as_dbms) {
@@ -556,7 +553,7 @@ static void hidden_access_points_display(struct l_queue *access_points)
 {
 	const struct l_queue_entry *entry;
 
-	display_table_header("Available hidden APs", MARGIN "%-*s%-*s%*s",
+	display_table_header("Available hidden APs", MARGIN "%-*s  %-*s  %*s",
 				20, "Address", 10, "Security", 6, "Signal");
 
 	if (l_queue_isempty(access_points)) {
@@ -574,9 +571,8 @@ static void hidden_access_points_display(struct l_queue *access_points)
 		if (display_signal_as_dbms)
 			dbms = l_strdup_printf("%d", ap->signal_strength);
 
-		display(MARGIN "%-*s%-*s%-*s\n",
-			20, ap->address, 10, ap->type,
-			6, dbms ? : dbms_tostars(ap->signal_strength));
+		display_table_row(MARGIN, 3, 20, ap->address, 10, ap->type, 6,
+				dbms ? : dbms_tostars(ap->signal_strength));
 	}
 
 	display_table_footer();
@@ -676,7 +672,7 @@ static void get_diagnostics_callback(struct l_dbus_message *message,
 		goto done;
 	}
 
-	diagnostic_display(&iter, "            ", 20, 20);
+	diagnostic_display(&iter, MARGIN, 20, 47);
 
 done:
 	/* Finish the table started by cmd_show */
-- 
2.34.1


  parent reply	other threads:[~2022-07-06 21:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 21:28 [PATCH 01/14] client: add generic display function for table rows James Prestwood
2022-07-06 21:28 ` [PATCH 02/14] client: remove newline/tab encoding from help description James Prestwood
2022-07-06 21:28 ` [PATCH 03/14] client: update dbus-proxy to use display_table_row James Prestwood
2022-07-06 21:28 ` James Prestwood [this message]
2022-07-06 21:28 ` [PATCH 05/14] client: dpp: display table footer and set to auto update James Prestwood
2022-07-06 21:28 ` [PATCH 06/14] client: check NULL return for DPP cmd_show James Prestwood
2022-07-06 21:28 ` [PATCH 07/14] client: update CLEAR_SCREEN to be consistent with others James Prestwood
2022-07-06 21:28 ` [PATCH 08/14] client: make COLOR_* macros take a string input James Prestwood
2022-07-06 21:28 ` [PATCH 09/14] client: update ap to use display_table_row James Prestwood
2022-07-06 21:28 ` [PATCH 10/14] client: update known-networks " James Prestwood
2022-07-06 21:28 ` [PATCH 11/14] client: update command table header James Prestwood
2022-07-06 21:28 ` [PATCH 12/14] client: update device to use display_table_row James Prestwood
2022-07-06 21:28 ` [PATCH 13/14] client: update adapter table header James Prestwood
2022-07-06 21:28 ` [PATCH 14/14] client: update ad-hoc " James Prestwood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220706212851.92685-4-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.