From patchwork Wed Jul 6 22:18:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908727 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 432052F21 for ; Wed, 6 Jul 2022 22:21:28 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id 145so15134101pga.12 for ; Wed, 06 Jul 2022 15:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fubeP8Gpomxz1l4RpRKR7xeHEl2tknsqcnZNF0g+uDU=; b=lKXKzJNvKZ9qgkKYlZ5Jf3iXgLWWl/gXb3UAtf9gIdo/X3VPLShQQSgaUAwl5k2wNd A2fCsQ2xzA8BPmLI//r7vfig4lIv4zlwMjEPGaJlXuw2svVjNvCvMRmyEPc4eNRuo4U0 WMA1oYMII0SjVMqFxf4CNAjUxcO9vvFrw+TCmOnTR/XaY2i/IOcOBtfjhJtOE8WurhVA w7FAoo2jm43gyI9Mx3tstwWCl6NWsQi5oicmfhvMJ5Xa8e+X4PmhqqI1R0ACj6EnyUab m844WNYr7ADdSF/MCOYoDYDxg8DcOa//bGMGrt/ACnV94vzgNLjRz/LSypgA0nso4myd XoXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fubeP8Gpomxz1l4RpRKR7xeHEl2tknsqcnZNF0g+uDU=; b=TN3BLeCJ29FiSaqeAnt8B6RFwm3pnUj7uuz2OE5VO9QRAds1zbn5c71DwZeGdm8X0k sqdjmQAK/0u0ji/s95KTaiMcWX9cP0awf82ZzzTrTjerqV12UKkgUyw/cyve9sz+hFVE 4Yn+sYixF7qu/wiNTz52udWKYVbs1ygyDQty7HnvbyrNt7zBJKbNHb9jUuwCRFsVn/u5 n9k9bzU3/anOLLO1ZB9n1RHkgFXgVTocsLYbAUB6XFy5jh/e3kQp3cdoGuTMcgjKTZ+E 0hON28h3iwYyaZmvsguMEqg87vEt0dxU7mgsAy1/g4CXenkS3xPqELh/AEVPO7NHnEBv /nZQ== X-Gm-Message-State: AJIora8y8N+JkvKGlpvTJ57xxKClUSbXTW9xOQa5Vy42KKkErgpeCDy+ TQFyLT3DDL/Ye+jTCaRwAmI03MfNhcE= X-Google-Smtp-Source: AGRyM1u/PNI/pairR0e+NdkgQX39jvw+2i/mpW4YmyyT9uJPD0e51pWNZG7B4HqpCji3tI4XJYDY/A== X-Received: by 2002:a63:2b84:0:b0:412:5277:99dc with SMTP id r126-20020a632b84000000b00412527799dcmr14025642pgr.208.1657146087294; Wed, 06 Jul 2022 15:21:27 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:26 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 01/14] client: add generic display function for table rows Date: Wed, 6 Jul 2022 15:18:54 -0700 Message-Id: <20220706221907.126408-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There was no easy to use API for printing the contents of a table, and was left up to the caller to handle manually. This adds display_table_row which makes displaying tables much easier, including automatic support for line truncation and continuation on the next line. Lines which are too long will be truncated and displayed on the next line while also taking into account any colored output. This works with any number of columns. This removes the need for the module to play games with encoding newlines and tabs to make the output look nice. As a start, this functionality was added to the command display. --- client/display.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++- client/display.h | 1 + 2 files changed, 172 insertions(+), 3 deletions(-) diff --git a/client/display.c b/client/display.c index 07cb7bda..7ca3a767 100644 --- a/client/display.c +++ b/client/display.c @@ -376,8 +376,176 @@ void display_table_footer(void) display_refresh_check_applicability(); } -void display_command_line(const char *command_family, - const struct command *cmd) +#define COLOR_END(_str) \ +({ \ + char *_s = (_str); \ + while (*_s != 'm' && *_s != '\0') \ + _s++; \ + _s - (_str) + 1; \ +}) + +/* + * Finds last space in 's' before 'max' characters, terminates at that index, + * and returns a new string to be printed on the next line. + * + * 'max' should be set to the column width, but is also an out parameter since + * this width can be updated if colored escapes are detected. + * + * Any colored escapes found are set to 'color_out' so they can be re-enabled + * on the next line. + */ +static char* next_line(char *s, unsigned int *max, char **color_out) +{ + unsigned int i; + int last_space = -1; + int last_color = -1; + + /* Find the last space before 'max', as well as any color */ + for (i = 0; i <= *max && s[i] != '\0'; i++) { + if (s[i] == ' ') + last_space = i; + else if (s[i] == 0x1b) { + /* color escape won't count for column width */ + *max += COLOR_END(s + i); + last_color = i; + } + } + + /* Reached the end of the string within the column bounds */ + if (i <= *max) + return NULL; + + /* Not anywhere nice to split the line */ + if (last_space == -1) + last_space = *max - 1; + + /* + * Only set the color if it occurred prior to the last space. If after, + * it will get picked up on the next line. + */ + if (last_color != -1 && last_space >= last_color) + *color_out = l_strndup(s + last_color, + COLOR_END(s + last_color)); + else + *color_out = NULL; + + s[last_space] = '\0'; + + return l_strdup(s + last_space + 1); +} + +struct table_entry { + unsigned int width; + char *next; + char *color; +}; + +/* + * Appends the next line from 'e' to 'line_buf'. 'done' is only set false when + * there are more lines needed for the current entry. + */ +static int entry_append(struct table_entry *e, char *line_buf, bool *done) +{ + char *value = e->next; + unsigned int ret = 0; + unsigned int width = e->width; + + /* Empty line */ + if (!value) + return sprintf(line_buf, "%-*s ", e->width, ""); + + /* Color from previous line */ + if (e->color) { + ret = sprintf(line_buf, "%s", e->color); + l_free(e->color); + e->color = NULL; + } + + /* Advance entry to next line, and terminate current */ + e->next = next_line(value, &width, &e->color); + + if (e->next) + *done = false; + + /* Append current line */ + ret += sprintf(line_buf + ret, "%-*s ", width, value); + + l_free(value); + + /* Un-color output for next column */ + if (e->color) + ret += sprintf(line_buf + ret, "%s", COLOR_OFF); + + return ret; +} + +/* + * Expects an initial margin, number of columns in table, then row data: + * + * , , ... + * + * The data string can be of any length, and will be split into new lines of + * length . + */ +void display_table_row(const char *margin, unsigned int ncolumns, ...) +{ + char buf[512]; + char *str = buf; + unsigned int i; + struct table_entry entries[ncolumns]; + va_list va; + bool done = true; + + memset(&entries[0], 0, sizeof(entries)); + + va_start(va, ncolumns); + + str += sprintf(str, "%s", margin); + + for (i = 0; i < ncolumns; i++) { + struct table_entry *e = &entries[i]; + + e->width = va_arg(va, unsigned int); + e->next = l_strdup(va_arg(va, char*)); + + str += entry_append(e, str, &done); + } + + va_end(va); + + display("%s\n", buf); + str = buf; + + /* + * The first column should now be indented, which effects the entry + * width. Subtract this indentation only from the first column. + */ + entries[0].width -= strlen(margin) * 2; + + while (!done) { + done = true; + + for (i = 0; i < ncolumns; i++) { + struct table_entry *e = &entries[i]; + + if (i == 0) + str += sprintf(str, "%s%s%s", margin, + margin, margin); + + str += entry_append(e, str, &done); + } + + display("%s\n", buf); + str = buf; + } + + for (i = 0; i < ncolumns; i++) { + if (entries[i].color) + l_free(entries[i].color); + } +} + +void display_command_line(const char *command_family, const struct command *cmd) { char *cmd_line = l_strdup_printf("%s%s%s%s%s%s%s", command_family ? : "", @@ -388,7 +556,7 @@ void display_command_line(const char *command_family, cmd->arg ? " " : "", cmd->arg ? : ""); - display(MARGIN "%-*s%s\n", 50, cmd_line, cmd->desc ? : ""); + display_table_row(MARGIN, 2, 50, cmd_line, 30, cmd->desc); l_free(cmd_line); } diff --git a/client/display.h b/client/display.h index 7747c6a0..c34cab9c 100644 --- a/client/display.h +++ b/client/display.h @@ -37,6 +37,7 @@ void display(const char *format, ...) __attribute__((format(printf, 1, 2))); void display_table_header(const char *caption, const char *fmt, ...) __attribute__((format(printf, 2, 3))); +void display_table_row(const char *margin, unsigned int ncolumns, ...); void display_table_footer(void); void display_error(const char *error); void display_command_line(const char *command_family, From patchwork Wed Jul 6 22:18:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908728 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16703664F for ; Wed, 6 Jul 2022 22:21:29 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id t3so2486247pfq.10 for ; Wed, 06 Jul 2022 15:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DM19MrL0XT/0sC94EUTCmp8xPndF6ZhaP67EriDgwgI=; b=DOnGdPO1j9dx1UQZKn9AEpkVrv7bbGxGKoQOYg6iYL0TuKCPV1F6AATbO7k3XXnZw7 zAO6epIjmPfavKOnyy0GzyBcm/ZzlkGSEfzcCWA+oKykd9QfDsCuHvhQBXsnGSUn/Wr/ 8awUoFXvCILwqxaIzMBpLH8U6rA+SHRMSiC7VyPUuhWsOU1MtFmn3K7nnBDtOvKG8WIv cy8uaWgQmHh5z/IOpmwPaQu5cgewTeRmy2CG5AyMD1yqMEal9Ka5SwjCzZEyUyOjDrHu i/ADLSN+cwOG0Ydqyr/5yyQw+/lRBq1QUuh7e8gN6/YgGDVex4ibPDmg9puDuILMt/nk j/Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DM19MrL0XT/0sC94EUTCmp8xPndF6ZhaP67EriDgwgI=; b=C0yv3fCehU+aGw5ebAc08TXuVEOoZsFT27RXqN5zyMQvu597Wpv5ITcwvOEMU0kMxY DKxqbvh+fJm+quers/P6CY7cCgQw8obPjJEP5Xi1xbdzlUSGz6DwNZ1LMSEIqvvrRX0I MUG/qYJyRNL474cQFKnalTI7QJMuFNqtB5qP7TDiOL9r72CguGVLLrcsgEN4UtAWasWz VW6/pLvsyOTqIw/Lv9O6XV/S336pe7Low62PiBGqQBIpnMBjFKv/R4WvVuUgj2V8xx60 6Jr/4diB3tT/q716Pn2GdEJSiY8Qxzn06q4XGCf4m7XdLS0INk1PwHxi4YAvdL5k1pK+ Koiw== X-Gm-Message-State: AJIora/of2msx5Wolcll86KTZFpfE2F74yGYyobw7GoER0NRHb0VAbRZ 5a2PwlfPdymiVMEOKos4tYTqB3ODPUI= X-Google-Smtp-Source: AGRyM1uF3Tb0NsMYmcpGZD6yvMupkT2fXFn3pMK4wYVt2BOpPPD38t3u77n46mBcfZ+bv/3742qjSw== X-Received: by 2002:a17:90a:7c05:b0:1ee:e40c:589b with SMTP id v5-20020a17090a7c0500b001eee40c589bmr1122909pjf.78.1657146088221; Wed, 06 Jul 2022 15:21:28 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:27 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 02/14] client: remove newline/tab encoding from help description Date: Wed, 6 Jul 2022 15:18:55 -0700 Message-Id: <20220706221907.126408-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ad-hoc, ap, and wsc all had descriptions longer than the max width but this is now taken care of automatically. Remove the tab and newline's from the description. The WSC pin command description was also changed to be more accurate since the pin does not need to be 8 digits. --- client/ad-hoc.c | 11 ++++------- client/ap.c | 7 +++---- client/wsc.c | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/client/ad-hoc.c b/client/ad-hoc.c index c90f9dd6..33bff9ca 100644 --- a/client/ad-hoc.c +++ b/client/ad-hoc.c @@ -215,14 +215,11 @@ static enum cmd_status cmd_stop(const char *device_name, char **argv, int argc) static const struct command ad_hoc_commands[] = { { NULL, "list", NULL, cmd_list, "List devices in Ad-hoc mode", true }, { "", "start", "<\"network name\"> ", cmd_start, - "Start or join an existing\n" - "\t\t\t\t\t\t Ad-Hoc network called\n" - "\t\t\t\t\t\t \"network name\" with a\n" - "\t\t\t\t\t\t passphrase" }, + "Start or join an existing Ad-Hoc network called " + "\"network name\" with a passphrase" }, { "", "start_open", "<\"network name\">", cmd_start_open, - "Start or join an existing\n" - "\t\t\t\t\t\t open Ad-Hoc network called\n" - "\t\t\t\t\t\t \"network name\"" }, + "Start or join an existing open Ad-Hoc network called" + " \"network name\"" }, { "", "stop", NULL, cmd_stop, "Leave an Ad-Hoc network" }, { } }; diff --git a/client/ap.c b/client/ap.c index bb583397..b992c792 100644 --- a/client/ap.c +++ b/client/ap.c @@ -416,12 +416,11 @@ static enum cmd_status cmd_get_networks(const char *device_name, char **argv, static const struct command ap_commands[] = { { NULL, "list", NULL, cmd_list, "List devices in AP mode", true }, { "", "start", "<\"network name\"> ", cmd_start, - "Start an access point\n\t\t\t\t\t\t called \"network " - "name\" with\n\t\t\t\t\t\t a passphrase" }, + "Start an access point called \"network " + "name\" with a passphrase" }, { "", "start-profile", "<\"network name\">", cmd_start_profile, "Start an access point based on a disk profile" }, - { "", "stop", NULL, cmd_stop, "Stop a started access\n" - "\t\t\t\t\t\t point" }, + { "", "stop", NULL, cmd_stop, "Stop a started access point" }, { "", "show", NULL, cmd_show, "Show AP info", false }, { "", "scan", NULL, cmd_scan, "Start an AP scan", false }, { "", "get-networks", NULL, cmd_get_networks, diff --git a/client/wsc.c b/client/wsc.c index 39950453..1e5912ce 100644 --- a/client/wsc.c +++ b/client/wsc.c @@ -182,10 +182,10 @@ static enum cmd_status cmd_cancel(const char *device_name, static const struct command wsc_commands[] = { { NULL, "list", NULL, cmd_list, "List WSC-capable devices", true }, { "", "push-button", NULL, cmd_push_button, "PushButton mode" }, - { "", "start-user-pin", "<8 digit PIN>", cmd_start_user_pin, + { "", "start-user-pin", "", cmd_start_user_pin, "PIN mode" }, { "", "start-pin", NULL, cmd_start_pin, - "PIN mode with generated\n\t\t\t\t\t\t 8 digit PIN" }, + "PIN mode with generated 8 digit PIN" }, { "", "cancel", NULL, cmd_cancel, "Aborts WSC operations" }, { } }; From patchwork Wed Jul 6 22:18:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908729 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 023912F21 for ; Wed, 6 Jul 2022 22:21:29 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id l124so5266489pfl.8 for ; Wed, 06 Jul 2022 15:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e9ieV3CILIiKWCqTQ7cPR9lgx3GxdbKLHByre30dKcA=; b=Ej6CxrLlgHKjjU1jhZfC+zBxK03K9hLpQ9Tp3O0wqCfBD40D046/VUIUcphSNP6G9w YlHRO4jDeOcJfPXs6Ek+Csv0a8sdlCMiSuZkBQbxt0/j276TipxNzq3r42CY5Yqod9u/ Z6XAQdvOfi5rrim95hwCtYFCemWKlfukhy7CKEIUm0eskWhONKRzS+Js9pCIExc18cey xh3so/Hd5DBL6ofByuAYVdDYZHD6r23eLeHJgqP1x9HmbtDflMUXzOeIZ2Cq99ZL06lx Bp8+YV8jMGtv2dV94mOQrjTuljawfgYJZujuND5OfW2bxMyLLUhIIqHhyVbkeNOH5JLt I5iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e9ieV3CILIiKWCqTQ7cPR9lgx3GxdbKLHByre30dKcA=; b=mDROz2tBZdvVUTaKnRKb/l5dJKs57HWz7RRGAMDNBkl3b1RV+pWRDixAny8NK+T/gT KmZo/RfCExRXvEYK8jvfZ6ZtfuK60IlvXzsgCWgVR+azAyYeErOrz3gkXpvJ4wihe7wH DJsGHJyWwZErM5Im2ZDbgCy82lBXzefDIauiFCJPivmEVEOOD2JDH9PXsqmaXObTbTBn u13Hm5nP81BojYgoOQS/lcWYLWWoymHiORhwe/SQuA6MqkYEunuACdv15avlxGW3n3NI Tyu8R1y5dNyIL72PzoLuCJ+Tlzc86pTr3rqBJ+WEv18NujJ7Mu++4CsQ9sWIOfHPOGzL rUHg== X-Gm-Message-State: AJIora8ae1ru9wccfIEGLqHHcYNVD+IwEL4OnIPOHBR7oATd25w43/x8 LGQt8jCdxImC/mqxWMee5jiodKGDs8k= X-Google-Smtp-Source: AGRyM1tmdSfnS4O62FBDhF8wXJgdo54CM7c/ZN2GhaQNZ3vTKzmr4CQDugkKH++bB3x4eeN/xXhERg== X-Received: by 2002:a17:902:a502:b0:16b:fbd9:7fc5 with SMTP id s2-20020a170902a50200b0016bfbd97fc5mr8292070plq.112.1657146089213; Wed, 06 Jul 2022 15:21:29 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:28 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 03/14] client: update dbus-proxy to use display_table_row Date: Wed, 6 Jul 2022 15:18:56 -0700 Message-Id: <20220706221907.126408-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- client/dbus-proxy.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c index 9f05c0e7..bbb97eb5 100644 --- a/client/dbus-proxy.c +++ b/client/dbus-proxy.c @@ -59,7 +59,7 @@ void proxy_properties_display(const struct proxy_interface *proxy, if (!proxy->type->properties) return; - display_table_header(caption, "%s%-*s %-*s%-*s", margin, + display_table_header(caption, "%s%-*s %-*s %-*s", margin, 8, "Settable", name_column_width, "Property", value_column_width, "Value"); @@ -69,29 +69,16 @@ void proxy_properties_display(const struct proxy_interface *proxy, for (i = 0; properties[i].name; i++) { const char *str; - size_t len; - size_t j; if (!properties[i].tostr) continue; str = properties[i].tostr(data); - len = str ? strlen(str) : 0; - display("%s%*s %-*s%-.*s\n", margin, - 8, properties[i].is_read_write ? + display_table_row(MARGIN, 3, 8, properties[i].is_read_write ? COLOR_BOLDGRAY " *" COLOR_OFF : "", - name_column_width, properties[i].name, - value_column_width, str ? : ""); - - if (len <= value_column_width) - continue; - - /* Display remaining data */ - for (j = value_column_width; j < len; j += value_column_width) - display("%s%*s %-*s%-.*s\n", margin, 8, "", - name_column_width, "", value_column_width, - str + j); + name_column_width, properties[i].name, + value_column_width, str ? : ""); } } From patchwork Wed Jul 6 22:18:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908730 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 099C26657 for ; Wed, 6 Jul 2022 22:21:30 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id s206so15174191pgs.3 for ; Wed, 06 Jul 2022 15:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gKdUJO5ZwHb4qiMXCCu0nn9rfz7x5XKmG9AsGRamOfY=; b=PORViAtRNz56qF5IGwlgp4QaoJRc92TItNW7i0HCo7VCiJlvFcJ9i+4cPw6zYGXaFg d/qEUs/1/SbPKR/EplM3yVgAdrvCH0lIJTu97664pDdfA8il5OFQHcgYOige9m0NybDZ E3Lo0CHt0fC5gqqWcR7C6naak1Uarmydl5b3T1uNstWrXZiB9EgJK+zAFz3EN+Jf1cdG S1vwpsekVrO/X9ePO49wcLOpyFHF+azXylS1NmQcPuZH15FmQ3UmYLjKlwNBRm/e9v6I yNeqxrxBaxBfGDMz1pXbeEKo9Y7f1H+YrNrVG1Yk7n7C7D48T2+X5XI2cwKCxAW1YkSG j30Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gKdUJO5ZwHb4qiMXCCu0nn9rfz7x5XKmG9AsGRamOfY=; b=R+x3ozaGGwcfepC8Zv0t3siPCJ5dhwg/RhBLwa3GOQrCgbw18AiPH94qtuumM/Lw4v HqHz0Oe4NqqbZclX1/iOFD2okziyn/16qDGaiB3XOxodq+pipDHfvhpeItpIXDWGW3/Z P+T7+QLE9BPo04q6D1FzI9BO9mkWfXUNOfOWy13kxMiT96Dc9CpiHJkoTNwHdTmmRIVZ tqkHY0GTe+6m91PGDffSRadSt3Z6T8uc/fycBxlfZbQO6AOa5TetjCketqZAwUyCM+Is QFe363mYdZYKYB6agX6+Os/f46JdFP6Xqu2NDUs1Z1d6kn5pc8mV/EZ8D0BnyXN6dETr 25Pw== X-Gm-Message-State: AJIora9wps6Wp/mW0I8LCsuBHsylx41+Ip4JxYEfluH6UlGDlTgujcYB T4yj4S9cDujKnoNvm0SZdkBGqO/nMxo= X-Google-Smtp-Source: AGRyM1ufIKYvwGRLrxj/U65x9U30DBhOYAyscFgKQpyH1jKniXZ1owzzTV+msHPPuU+SJERyhOHvXw== X-Received: by 2002:a17:903:2410:b0:16a:81d2:f5e8 with SMTP id e16-20020a170903241000b0016a81d2f5e8mr49234385plo.81.1657146090205; Wed, 06 Jul 2022 15:21:30 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:29 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 04/14] client: update station to use display_table_row Date: Wed, 6 Jul 2022 15:18:57 -0700 Message-Id: <20220706221907.126408-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 */ From patchwork Wed Jul 6 22:18:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908731 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF21A53BA for ; Wed, 6 Jul 2022 22:21:31 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id e16so2874868pfm.11 for ; Wed, 06 Jul 2022 15:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ld4GeYr+7Z4DNiCGJbPvu22aYTQs3MaFU1OF+dq/0TM=; b=gw5coCmQeN/0kIDomkn/LQ+2VnkyOt9kMkM3auFOS0U2Vg0IYpVVDgbFAJe6gZ/EYS 19EPJS/xz1a2/jxGn113ZCpjI17kUutCF7wUK/NE3EYwNDnRPLn/c0aJYFJ27OCMXyti mgoVai6ILdmEgi3ysXsJLZxV3n/MQ0MPf0NOMzOTWMMfschIEN30ixH4YoLwzgN/SBO7 wF2CmNud9FU8VMaXb/Paq5DFedriImf+EkxyJL3WTScewm+RbHUc++8A7CVt/49+YsdC I5goWRuBFcurO0kwqTsG/bnnaTCmnyqnjAiok82A5/nW53YMvLm4KwquO1E79/0Ssbr5 gnWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ld4GeYr+7Z4DNiCGJbPvu22aYTQs3MaFU1OF+dq/0TM=; b=xOFdJKeaMsCwcIrXuFYeZDWY8FQWUPXOA0ZD0xFEMIG+UiGvzqRcyEZdIYt4an1gcI OFR/ujZKBDpfp6Za1gnO7UGSIXY1Yw5nA7WRJcujkBajHARDEQQJm2sqcbiyNnBsn0d3 55+jB2p/mvW7WU8L1ZzW53XvJSMGrlYNI7lDv6uwLMdMDaJXjCORvDH+qXFI/m3Xe1r6 2pS52zA+4d5uLYnTX+aWRWvDPk29aJePtzr1nsGsnFesALyT28u+lUF00S0PnrzZ/vmu q4DVzJwd6EdVqvwaQAiSzQUJswK3xLVvY7X/zF241dtRnz51UDgUsdf1CcW1h4EYtZNb 6xyg== X-Gm-Message-State: AJIora9LMTMVy8cDJMuiv7QogjNgBLLylw+A9rvfjC+dPdVcyzBY/sUi yI3urYsPiS8hGv40lS03JbCpyGxEAWU= X-Google-Smtp-Source: AGRyM1uX/kyAbJrAsVtoda47jCBWU4RyJogq+VWhj6EWsgO7ymXnKru2AGNPz1oMLh7vO05ovwQzvw== X-Received: by 2002:a17:902:934c:b0:167:80c6:aedd with SMTP id g12-20020a170902934c00b0016780c6aeddmr50912259plp.97.1657146091024; Wed, 06 Jul 2022 15:21:31 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:30 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 05/14] client: dpp: display table footer and set to auto update Date: Wed, 6 Jul 2022 15:18:58 -0700 Message-Id: <20220706221907.126408-5-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The table footer never got added when the properties did. In addition set the 'show' command to update since these properties could change. --- client/dpp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/dpp.c b/client/dpp.c index af69d2c0..cd05a33b 100644 --- a/client/dpp.c +++ b/client/dpp.c @@ -287,6 +287,8 @@ static enum cmd_status cmd_show(const char *device_name, proxy_properties_display(proxy, caption, MARGIN, 20, 47); l_free(caption); + display_table_footer(); + return CMD_STATUS_DONE; } @@ -297,7 +299,7 @@ static const struct command dpp_commands[] = { { "", "start-configurator", NULL, cmd_start_configurator, "Starts a DPP Configurator" }, { "", "stop", NULL, cmd_stop, "Aborts DPP operations" }, - { "", "show", NULL, cmd_show, "Shows the DPP state" }, + { "", "show", NULL, cmd_show, "Shows the DPP state", true }, { } }; From patchwork Wed Jul 6 22:18:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908732 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB3732F21 for ; Wed, 6 Jul 2022 22:21:32 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id g4so15183544pgc.1 for ; Wed, 06 Jul 2022 15:21:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mYEunOFTFC/n9/8Um0rXVxJFt1Z1Q3f5kP2ThqZP93U=; b=hFSmBbai6lDfofr+YHMBOvpbWBcUZdgUgQ8cJecTAqQY6QmHfv8CAnRLfiZUg0ZOmv nKEVVUTLDhnZXBuBl7xebni4gll3KVM/dAC3Mgch8S9iV8FQPqLXKa+EVwwejQCZErIB Q3lMXeZLRfrxFHlkpO6cOKXFAfiYC9v3jz3ncwkWlfobhbt014Q2wnfRkB6GgwAwVd/q 1+/Dz8SbOVtF87HGmi9UCfky5x3TBql10eRay60w8tq20rtx42oAyxw9eh8AMByhIuuu ikNUXy1GWWswVyBgXJr0wEsEOwufK9I+3FHHJQqlY6kjN5CVuwSNWb8usxcbAzkOmxSj oThw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mYEunOFTFC/n9/8Um0rXVxJFt1Z1Q3f5kP2ThqZP93U=; b=yhnplOM5FdXQ+v5YkdEAawn6n4KANWOmQTrYsLTDXt6fLdfY5JwDWNSkIsng6zwsEI LyMifHRtUXGYl6F8RLocPhp58YB3NZYPZmSyfFOaZEsYGV+xA+R33X+XHM016SBCZkuk L3kbxtIJSDS6Jleg2xjFQAhzXWo+RA0W6KIWsKN/RGTz1g+M3IYNUUe8GOWNdr5gQLoI Pm61ut4vWi2+3hMPhey2+40h7wE94CjEdYGHfMhnk9BOZbjmeFJdok2fpnkkJp4KXCd8 S7yveO5uD3Ob4X86qPcTiHIVpknYCNPxrh2S/H64izqLnMTDGz0UFa1zzFm4AFSk0d5s rexw== X-Gm-Message-State: AJIora8Nhn5UoC7Dn9f6EOe1z+1Aacpb9+uCFu1f1AY1JBJIus8P5S5o VJaUdmAeAzyJaphXLKLKvzqEy6xkjkE= X-Google-Smtp-Source: AGRyM1sp6vWcLMlzjE8rG0rHdaPaWtB0cVUCQ3e0qSWnpfQ8k5sZf0ssBceNaK+/fFom7GC2tARaRg== X-Received: by 2002:a17:90a:4e05:b0:1ec:8de4:1dd5 with SMTP id n5-20020a17090a4e0500b001ec8de41dd5mr1071738pjh.242.1657146091909; Wed, 06 Jul 2022 15:21:31 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:31 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 06/14] client: check NULL return for DPP cmd_show Date: Wed, 6 Jul 2022 15:18:59 -0700 Message-Id: <20220706221907.126408-6-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the DPP interface goes away this could return NULL which was unchecked. Caught by static analysis. --- client/dpp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/dpp.c b/client/dpp.c index cd05a33b..a659f545 100644 --- a/client/dpp.c +++ b/client/dpp.c @@ -284,6 +284,11 @@ static enum cmd_status cmd_show(const char *device_name, device_proxy_find(device_name, IWD_DPP_INTERFACE); char *caption = l_strdup_printf("%s: %s", "DPP", device_name); + if (!proxy) { + display("No DPP interface on device: '%s'\n", device_name); + return CMD_STATUS_INVALID_VALUE; + } + proxy_properties_display(proxy, caption, MARGIN, 20, 47); l_free(caption); From patchwork Wed Jul 6 22:19:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908733 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8713A665F for ; Wed, 6 Jul 2022 22:21:33 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id j3so3001234pfb.6 for ; Wed, 06 Jul 2022 15:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BmMZpc14Ab1wbx04tHduSMqXwFCtXithIXdMgoNEut8=; b=BMhSzMPTTi2F/Jko40C1oWojoi5HjPqygRZyoRT0w7bI35o+AP3vEeZjLV8Xf/3Td/ y6CAY2QGtoiaXsoGypAR1oYiC9wMA8UxSjgYAX6KZHNVEuBmmyB+iq73VpeaWr1imnRm xY5psgpzpzP/PyFG2RlidMaKwdqYv6BRpQDE14DzVt0b0rY26NAa5LAkkIiZQi5tRlWR oSHFYoNbfiSrWKs61t4cIKZmkYcRWhQkVxNSF6OT087YVAq0fgvfTkRZuIqP8Ywgn+jw r1n8Y4hf+sTG5FGKclq/EC6VXkgQUmt7LfQiSujn1zhrxFcl+fYQRkGGrSJu+Qy9y+2u pOTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BmMZpc14Ab1wbx04tHduSMqXwFCtXithIXdMgoNEut8=; b=obtf1Tmla6+68yfXZGgvIQ19yKcLK2yHCcEYXtbVro3bn7hwhbdjuPH1F2noG83FcE /s/R4vAmj9AlOMewrQyk59iUUNNmUBdC8B/kL/Gca0Y27h7bgC+QgPb24smSx7UAgp6e N6o66Bw8b80kidDbvO3y8Kjasz5zGQnbUXNFTYeq+iOUJxPJ43h3knwY1DbLlsWcFSgT iEpSjYS33GZdoyqFVXIEUW7VNQJEnx6Zs2sl5Nq0LrUBG5dl4vypvzLqYkO1ODL7kRyI ysNoZn1kYHMDUtUA9/feuN2jQy9IID+34SL3jLlmyXnK5hJZddM/RvsNNQoy4FXgroFr 5qqQ== X-Gm-Message-State: AJIora9qABoUJXDMRV2sZWIfZIB+WbzrQWqHXuCRmbOk1a83SctV+gdE Uo9cI2DmsUN8/ztMz+C75U6yWv8ZX9w= X-Google-Smtp-Source: AGRyM1uXBFlFCDzVh1FoOYdSFoSzISeX6UxPImFsLSYqELobYxHXGQhK4r2NZbn58/HcHOFOh1j1fQ== X-Received: by 2002:a17:902:c205:b0:16b:f021:4299 with SMTP id 5-20020a170902c20500b0016bf0214299mr12633929pll.70.1657146092740; Wed, 06 Jul 2022 15:21:32 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:32 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 07/14] client: update CLEAR_SCREEN to be consistent with others Date: Wed, 6 Jul 2022 15:19:00 -0700 Message-Id: <20220706221907.126408-7-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Clear screen used a \033 escape sequence while others used a \x --- client/display.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/display.h b/client/display.h index c34cab9c..8e597bb5 100644 --- a/client/display.h +++ b/client/display.h @@ -30,7 +30,7 @@ struct command_family; #define COLOR_BLUE "\x1B[94m" #define COLOR_YELLOW "\x1b[33m" #define COLOR_OFF "\x1B[0m" -#define CLEAR_SCREEN "\033[2J" +#define CLEAR_SCREEN "\x1b[2J" #define MARGIN " " void display(const char *format, ...) From patchwork Wed Jul 6 22:19:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908734 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DCC72F21 for ; Wed, 6 Jul 2022 22:21:34 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id y9so1417097pff.12 for ; Wed, 06 Jul 2022 15:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LjUbAX5exqphHX/0ekLoQPosN77EU5bMuXY8UfgraCQ=; b=Lzk2opgfdK40mvuPzpTdemDviAufrxJVnBGAqxehxFYPxPZkA1nzvQJact0bHfWJA8 mOu4+ki2v+3U8UsdrIBuvzZztsl760Nvs8nmGs3x3qA+GRoGTAxzbp1RH7pJfiLW/pUI HZakig47tFb+Tk3ApsI7+kFVGl7uyeGmLz0/easYkJfjA9Wn7oaSzWuBq+LedKmmnQpt NizcpYklTDtVhz/DNRc5u3dfShTEL0+ngjo+eNbh6J4z5uDLP7ukoogr9HyLT8DXbKcn qiVoZfMdsqbog9xkraCZmw+VSvSmAR4JHxOw/7Kuq3QLLmfzBN4PbTtTzg9g1Rz17Ktg AGkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LjUbAX5exqphHX/0ekLoQPosN77EU5bMuXY8UfgraCQ=; b=2MLxkz8MtQ/0mE32U+fYrEQ8mdlnxuZHc5mHmYMwNG8hkhdsIlYna+4ksdmZ225D2l GwEm3YkD2d5S9sW4zUjiumVYf71apkNzOXWVcsiNiarmX3cwZBDCKF+x08huC/Ngz9UB HqbWkmKtklsQH0P1aimRkTSPRugiVp3xfIKwqsgTy/ZYchwuedMmZ1VTnuyOSmLFdhZv cE9NR+e0zkzy3Ay/Wn71NMtRjn4v+8263BVBK0QavuF0VE/bSvHMyurHavQmpxFR12JJ /AjkYNaLwoPKar05d50fkcNpzoV4p/apcT1d2eTn7Vf6mX5HzIG8mdUzHB8xoITvlttY PNXQ== X-Gm-Message-State: AJIora9s/1frm80AZGxbGHyt6JkP5b+77NHqFh9ujc2oI4BHh+XUsFUg DNXO80r8b9MB2Z/jia4EysvBLGxEDKk= X-Google-Smtp-Source: AGRyM1tCAJZx48kq3yZzNAB94TV4vTt5ZjHt+QQqHMTNW3XbjKM4g/IwEcLA6A1PYopc/D0Wl/T5Mg== X-Received: by 2002:a63:9c4:0:b0:401:a7b6:ad18 with SMTP id 187-20020a6309c4000000b00401a7b6ad18mr36518272pgj.523.1657146093486; Wed, 06 Jul 2022 15:21:33 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:33 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 08/14] client: make COLOR_* macros take a string input Date: Wed, 6 Jul 2022 15:19:01 -0700 Message-Id: <20220706221907.126408-8-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The existing color code escape sequences required the user to set the color, write the string, then unset with COLOR_OFF. Instead the macros can be made to take the string itself and automatically terminate the color with COLOR_OFF. This makes for much more concise strings. --- client/agent.c | 4 ++-- client/dbus-proxy.c | 2 +- client/display.c | 22 +++++++++++----------- client/display.h | 19 +++++++++---------- client/known-networks.c | 4 ++-- client/station.c | 8 ++++---- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/client/agent.c b/client/agent.c index 037ae785..6f2c9874 100644 --- a/client/agent.c +++ b/client/agent.c @@ -301,8 +301,8 @@ static struct l_dbus_message *request_user_password_method_call( display("Type the network password for %s.\n", proxy_interface_get_identity_str(proxy)); - username_prompt = l_strdup_printf(COLOR_BLUE PROMPT_USERNAME " " - COLOR_OFF "%s\n", username); + username_prompt = l_strdup_printf(COLOR_BLUE(PROMPT_USERNAME " ") + "%s\n", username); display("%s", username_prompt); l_free(username_prompt); diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c index bbb97eb5..1534488e 100644 --- a/client/dbus-proxy.c +++ b/client/dbus-proxy.c @@ -76,7 +76,7 @@ void proxy_properties_display(const struct proxy_interface *proxy, str = properties[i].tostr(data); display_table_row(MARGIN, 3, 8, properties[i].is_read_write ? - COLOR_BOLDGRAY " *" COLOR_OFF : "", + COLOR_BOLDGRAY(" *") : "", name_column_width, properties[i].name, value_column_width, str ? : ""); } diff --git a/client/display.c b/client/display.c index 7ca3a767..772f523b 100644 --- a/client/display.c +++ b/client/display.c @@ -40,7 +40,7 @@ #include "client/display.h" #define IWD_PROMPT \ - "\001" COLOR_GREEN "\002" "[iwd]" "\001" COLOR_OFF "\002" "# " + "\001" COLOR_GREEN("\002" "[iwd]" "\001") "\002" "# " #define LINE_LEN 81 static struct l_signal *window_change_signal; @@ -234,9 +234,9 @@ static void display_refresh_check_feasibility(void) if (ws.ws_col < LINE_LEN - 1) { if (display_refresh.enabled) { display_refresh.recording = false; - display(COLOR_YELLOW "Auto-refresh is disabled. " + display(COLOR_YELLOW("Auto-refresh is disabled. " "Enlarge window width to at least %u to enable." - "\n" COLOR_OFF, LINE_LEN - 1); + "\n"), LINE_LEN - 1); display_refresh.recording = true; } @@ -317,7 +317,7 @@ void display(const char *fmt, ...) void display_error(const char *error) { - char *text = l_strdup_printf(COLOR_RED "%s" COLOR_OFF "\n", error); + char *text = l_strdup_printf(COLOR_RED("%s\n"), error); display_text(text); @@ -344,14 +344,14 @@ void display_table_header(const char *caption, const char *fmt, ...) int caption_pos = (int) ((sizeof(dashed_line) - 1) / 2 + strlen(caption) / 2); - text = l_strdup_printf("%*s" COLOR_BOLDGRAY "%*c" COLOR_OFF "\n", + text = l_strdup_printf("%*s" COLOR_BOLDGRAY("%*c") "\n", caption_pos, caption, LINE_LEN - 2 - caption_pos, display_refresh.cmd ? get_flasher() : ' '); display_text(text); l_free(text); - text = l_strdup_printf("%s%s%s\n", COLOR_GRAY, dashed_line, COLOR_OFF); + text = l_strdup_printf(COLOR_GRAY("%s\n"), dashed_line); display_text(text); l_free(text); @@ -359,12 +359,12 @@ void display_table_header(const char *caption, const char *fmt, ...) text = l_strdup_vprintf(fmt, args); va_end(args); - body = l_strdup_printf("%s%s%s\n", COLOR_BOLDGRAY, text, COLOR_OFF); + body = l_strdup_printf(COLOR_BOLDGRAY("%s\n"), text); display_text(body); l_free(body); l_free(text); - text = l_strdup_printf("%s%s%s\n", COLOR_GRAY, dashed_line, COLOR_OFF); + text = l_strdup_printf(COLOR_GRAY("%s\n"), dashed_line); display_text(text); l_free(text); } @@ -767,7 +767,7 @@ void display_agent_prompt(const char *label, bool mask_input) if (mask_input) reset_masked_input(); - prompt = l_strdup_printf(COLOR_BLUE "%s " COLOR_OFF, label); + prompt = l_strdup_printf(COLOR_BLUE("%s "), label); if (command_is_interactive_mode()) { if (agent_saved_input) { @@ -813,8 +813,8 @@ void display_agent_prompt_release(const char *label) if (display_refresh.cmd) { char *text = rl_copy_text(0, rl_end); - char *prompt = l_strdup_printf(COLOR_BLUE "%s " COLOR_OFF - "%s\n", label, text); + char *prompt = l_strdup_printf(COLOR_BLUE("%s ") + "%s\n", label, text); l_free(text); l_queue_push_tail(display_refresh.redo_entries, prompt); diff --git a/client/display.h b/client/display.h index 8e597bb5..c1a3cb75 100644 --- a/client/display.h +++ b/client/display.h @@ -22,16 +22,15 @@ struct command; struct command_family; - -#define COLOR_BOLDGRAY "\x1B[1;90m" -#define COLOR_GRAY "\x1b[90m" -#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 "\x1b[2J" -#define MARGIN " " +#define COLOR_OFF "\x1B[0m" +#define COLOR_BOLDGRAY(s) "\x1B[1;90m" s COLOR_OFF +#define COLOR_GRAY(s) "\x1b[90m" s COLOR_OFF +#define COLOR_GREEN(s) "\x1b[32m" s COLOR_OFF +#define COLOR_RED(s) "\x1B[0;91m" s COLOR_OFF +#define COLOR_BLUE(s) "\x1B[94m" s COLOR_OFF +#define COLOR_YELLOW(s) "\x1b[33m" s COLOR_OFF +#define CLEAR_SCREEN "\x1b[2J" +#define MARGIN " " void display(const char *format, ...) __attribute__((format(printf, 1, 2))); diff --git a/client/known-networks.c b/client/known-networks.c index 45f60af2..49e69ddd 100644 --- a/client/known-networks.c +++ b/client/known-networks.c @@ -318,8 +318,8 @@ static const struct proxy_interface *known_network_proxy_find_by_name( if (!network_args.type) { display("Provided network name is ambiguous. " "Specify network security type as follows:\n"); - display("<\"network name" COLOR_BOLDGRAY ".security" - COLOR_OFF "\">\n"); + display("<\"network name" COLOR_BOLDGRAY(".security") + "\">\n"); display("\twhere '.security' is [.psk | .8021x | " ".open]\n"); } diff --git a/client/station.c b/client/station.c index 1a573674..64becdbd 100644 --- a/client/station.c +++ b/client/station.c @@ -387,12 +387,12 @@ static const char *dbms_tostars(int16_t dbms) return "****"; if (dbms >= -6700) - return "***" COLOR_BOLDGRAY "*" COLOR_OFF; + return "***" COLOR_BOLDGRAY("*"); if (dbms >= -7500) - return "**" COLOR_BOLDGRAY "**" COLOR_OFF; + return "**" COLOR_BOLDGRAY("**"); - return "*" COLOR_BOLDGRAY "***" COLOR_OFF; + return "*" COLOR_BOLDGRAY("***"); } #define RSSI_DBMS "rssi-dbms" @@ -440,7 +440,7 @@ static void ordered_networks_display(struct l_queue *ordered_networks) display_table_row(MARGIN, 4, 2, network_is_connected(network_i) ? - COLOR_BOLDGRAY "> " COLOR_OFF: "", + COLOR_BOLDGRAY("> ") : "", 32, network_name, 18, network_type, 6, display_signal_as_dbms ? dbms : dbms_tostars(network->signal_strength)); From patchwork Wed Jul 6 22:19:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908735 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7A6F665F for ; Wed, 6 Jul 2022 22:21:34 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id j3so3001355pfb.6 for ; Wed, 06 Jul 2022 15:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QmMGTTah4w5osCjPVCppx1ln9vzAKse2Sad/xzeQxgs=; b=GTva6RzzfQm1vxlLASRdt/7yss045dCVLLyK8dhLyBKO6AxD7Flepn22+6Mj46+WaT yoblyjb1BJvctF0FHLbNL86+x2pj2mijJu/sctqa8YAlMPlIlK1X4E50Qf3MMJv/C4+7 wuwObgMhuWcjYZktOdXZKPHFIToDpCw/Ju8bgcPUkM6ApVgRN8WZsrWvp1Me74+CV7ti kXeNUSniuEnc2lTD1kYVnOQg/7DOxW7s5O8tjxfjNno6H80/H80Mm9rLsJj1NnjgVIHU 1dKczPe0EwYm2a6VqUTYjFFt+gc7tuDt8B3HFd3gYWBV2XJn/3iMPzxl7YuDJa8fMp7S 557Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QmMGTTah4w5osCjPVCppx1ln9vzAKse2Sad/xzeQxgs=; b=A9Lk/6i8kZefV3474993nMU8KvZBNPfika6IN/CJ9sDPYBL1obF11vjUs5UPPS12A9 Zxn8p8CSCI8Pnl2CSBGfBGc3GaeO6Nv/182CoYJXYHEf6N2QWD7Dfz2Ri+knqwCJ2xYn jRpKyqowNTdwNJcOzSZFn7Z2JZLslvIcqTEpF3Nn4Fjz0s/c9wxMJkXhRAYDOMOGN+FE F6bM+dFpfEh5wHnrKiB8r764JXr00qZWu40VxrT5yT/MbHrP5jjUZ0moaO34c70qY64l HM5J/aFPtaVpLFHSkU3V52K97pn/LDIAxF7XVJRWDo3U8ydjVI5omg3mx6wNaFASJgqF zu1Q== X-Gm-Message-State: AJIora++SS/siDRs4TJ8Mdu7v1gu4poTg6EJSw7PYNSaqxl9nRlU2iSV B9XMs+KB2MoUw45GpV6tlaxmEwQa+MA= X-Google-Smtp-Source: AGRyM1t23CdXlmHsfH0rRJi+wLo4DrUNxPGZ4lWfdHQ7mi1uKTkl9rbo6KvxQ/1xIP94PB0toxl0Jw== X-Received: by 2002:a17:90a:6809:b0:1ec:c213:56c8 with SMTP id p9-20020a17090a680900b001ecc21356c8mr1111723pjj.82.1657146094408; Wed, 06 Jul 2022 15:21:34 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:33 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 09/14] client: update ap to use display_table_row Date: Wed, 6 Jul 2022 15:19:02 -0700 Message-Id: <20220706221907.126408-9-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- client/ap.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) v2: * Make the signal buffer big enough to handle the maximum int16 value which is 7 characters including '\0' diff --git a/client/ap.c b/client/ap.c index b992c792..b8849a1b 100644 --- a/client/ap.c +++ b/client/ap.c @@ -161,9 +161,7 @@ static void display_ap_inline(const char *margin, const void *data) if (!identity) return; - display("%s%-*s%-*s\n", margin, - 20, identity, - 8, get_started_tostr(ap)); + display_table_row(margin, 2, 20, identity, 8, get_started_tostr(ap)); } static enum cmd_status cmd_list(const char *device_name, char **argv, int argc) @@ -173,9 +171,8 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc) proxy_interface_find_all(IWD_ACCESS_POINT_INTERFACE, NULL, NULL); - display_table_header("Devices in Access Point Mode", MARGIN "%-*s%-*s", - 20, "Name", - 8, "Started"); + display_table_header("Devices in Access Point Mode", + MARGIN "%-*s %-*s", 20, "Name", 8, "Started"); if (!match) { display("No devices in access point mode available.\n"); @@ -265,10 +262,10 @@ static void ap_get_diagnostics_callback(struct l_dbus_message *message, } while (l_dbus_message_iter_next_entry(&array, &iter)) { - sprintf(client_num, "Client %u", idx++); - display_table_header(client_num, " %-*s%-*s", + sprintf(client_num, "STA %u", idx++); + display_table_header("", MARGIN "%-*s %-*s %-*s", 8, client_num, 20, "Property", 20, "Value"); - diagnostic_display(&iter, " ", 20, 20); + diagnostic_display(&iter, MARGIN, 20, 20); display_table_footer(); } } @@ -286,10 +283,11 @@ static enum cmd_status cmd_show(const char *device_name, char **argv, int argc) } proxy_properties_display(ap_i, "Access Point Interface", MARGIN, 20, 20); - display_table_footer(); - if (!ap_diagnostic) + if (!ap_diagnostic) { + display_table_footer(); return CMD_STATUS_DONE; + } proxy_interface_method_call(ap_diagnostic, "GetDiagnostics", "", ap_get_diagnostics_callback); @@ -355,14 +353,18 @@ static void ap_display_network(struct l_dbus_message_iter *iter, if (!l_dbus_message_iter_get_variant(&variant, "s", &s)) goto parse_error; - display("%s%-*s%-*s\n", margin, name_width, key, + display_table_row(margin, 2, name_width, key, value_width, s); } else if (!strcmp(key, "SignalStrength")) { + char signal[7]; + if (!l_dbus_message_iter_get_variant(&variant, "n", &n)) goto parse_error; - display("%s%-*s%-*i\n", margin, name_width, key, - value_width, n); + snprintf(signal, sizeof(signal), "%i", n); + + display_table_row(margin, 2, name_width, key, + value_width, signal); } } @@ -386,7 +388,7 @@ static void ap_get_networks_callback(struct l_dbus_message *message, return; } - display_table_header("Networks", " %-*s%-*s", + display_table_header("Networks", " %-*s %-*s", 20, "Property", 20, "Value"); while (l_dbus_message_iter_next_entry(&array, &iter)) { ap_display_network(&iter, " ", 20, 20); From patchwork Wed Jul 6 22:19:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908736 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EACA76667 for ; Wed, 6 Jul 2022 22:21:35 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id i190so2555806pge.7 for ; Wed, 06 Jul 2022 15:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PXAcukMtKn4tMNurUHsF0W8rW62Jn9j4ZVGFC/z9eDg=; b=eKAGHaOY3cPcIRbzTYqcIbZVrcwr+T7ZRZFxyZvjwQzWOjP4hLmbX+7yknxSepudat iuitNMIHCVA6mV6SRmGLx82ECNtecqi2D+SzgvgXdssioeDlKP9uuACTvD2vEi7Z0GD3 1hnq8A8EWLhGAOtiwl0QNqLr3Edd+o8H3GJpb/XCwklygT3hjyodMi4rR6xuTrLEAtfn 1PrEAw+oMQDqT2me7fbpgkYuktLlI2zixx74Y6asFqnIE4jF8VCjRAHx9hgfkHIKFcNg k3iwf1pKUqhOX2y74NzutGkr5EDrg8aRA0k3qztzD2227/5L9BXL7nVRfLFv7z/XaVyB 9LLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PXAcukMtKn4tMNurUHsF0W8rW62Jn9j4ZVGFC/z9eDg=; b=AnTHJtDobtGIcl4SkTHlcqaWEqD6w3jFtE/HbsExjzuTpuqNJLAUi2n4YeqOcWmIuB bBSMm3zMtQnoFXpmE4e8PCfCo0bOMSzpOolKzZ3Gyzokq7KBYifL2BQ5RbBIvF4EhkiH eWagMTYezwWWmSGtJkWiZp835ODtgUbu3p1OdwK6dWIst87Y7TTeHwklqwiPc7EOx3B3 q2Jbb6KNIemjWhnDdBxzBTKGiohtXRn0WN3nCZLCVQ8HShqH25DOLSngG13wVsZb5G4L QTqmpFlN+XqyI1IHHBGkTys1+UcosojMU/enspMkerlCfyCKPxTNURvglkRI7/DYrF0W MIwg== X-Gm-Message-State: AJIora+35Im2begoLqJhy60LpXB2Tx0NlwTVXFC+Fxk1pF5aN5zzoqI5 MIYIxM6yNcKv7j7qh08yuRaNscu2xXw= X-Google-Smtp-Source: AGRyM1sgYEwKwY449jAUHoaW7iiqefVlFpg8TtYetmdTUXgvWb7VDfZjBgN+SSmTJFV2bq8dpv5gOA== X-Received: by 2002:a65:6a50:0:b0:3f6:4566:581d with SMTP id o16-20020a656a50000000b003f64566581dmr35493530pgu.122.1657146095155; Wed, 06 Jul 2022 15:21:35 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:34 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 10/14] client: update known-networks to use display_table_row Date: Wed, 6 Jul 2022 15:19:03 -0700 Message-Id: <20220706221907.126408-10-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- client/known-networks.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/known-networks.c b/client/known-networks.c index 49e69ddd..56c34a2e 100644 --- a/client/known-networks.c +++ b/client/known-networks.c @@ -210,9 +210,9 @@ static void known_network_display_inline(const char *margin, const void *data) l_strdup(format_iso8601(network->last_connected, "%b %e, %l:%M %p")); - display("%s%-*s%-*s%-*s%-*s\n", - margin, 32, network->name, 11, network->type, - 9, get_hidden_tostr(network), 19, last_connected ? : "-"); + display_table_row(margin, 4, 32, network->name, 11, network->type, + 9, get_hidden_tostr(network), + 19, last_connected ? : "-"); l_free(last_connected); } @@ -263,7 +263,7 @@ static void check_errors_method_callback(struct l_dbus_message *message, static enum cmd_status cmd_list(const char *entity, char **args, int argc) { - display_table_header("Known Networks", MARGIN "%-*s%-*s%-*s%-*s", + display_table_header("Known Networks", MARGIN "%-*s %-*s %-*s %-*s", 32, "Name", 11, "Security", 9, "Hidden", 19, "Last connected"); From patchwork Wed Jul 6 22:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908737 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3AFE53BA for ; Wed, 6 Jul 2022 22:21:36 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id g126so1225107pfb.3 for ; Wed, 06 Jul 2022 15:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rRdtgstkk3/2WInkCaBSCRTBij0JsCS6mhIC+ypjjWA=; b=XfLlNlAHR/XXarLS2hlkrKE+5pkd39gPQwiKpSge2nMbf2uIqrRl1HF7GjrTq2IIAm pfe0eqbfsaSoEfITb8IvobBMT659z4yE1TfY+K+KYSt36yj2phcb4dcYwKnvvW9AODo2 Ka41I9TRbomyQ29jy0aQ7qDg/grxwbHDJQTlH3259bgVcw9MLKyqGN1Fm024ywx62cUd QJw7hFlKV1ZJnAwkvv+1taMIj9AmRDx4BXqiCDEMycTG89R1IintHZSe2IMmL8mijTXe P48I1tPLlhBWFYbQMr83kGcVlL3m9mQmUwo5JPb4nxYuhb0kkoRhUFK/fueob9Z0ud0s dZ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rRdtgstkk3/2WInkCaBSCRTBij0JsCS6mhIC+ypjjWA=; b=JcqjDQ9G4OgpaC8zbi9p9q8WZftRZzZNTSevFGYD1i97GOg1DApToODtx9to4+lAJ2 fcFdkTWl4eWhxMFJxGae4OwYJhgdhAYydwaG0oVIzi7ArPvYSEyqfToVr0rqln5m10/u IGofnFzsjQSGwSuR79ErHEj0UCbvM+o193/naKOdkT2b6KTwADJRzIJKJDgf4OwlnVh1 mIP+h5IXPvcohNsudVgZRMurSC/rGicJ+iJOvqoJ8Xa8DytcOorM7WEYQs6Y2ubj1Vu+ pPzk15yeKjBdad4olVuhHm6j6GbbpUQvGsB/BfqPbY4C68Ezycq8P6jCp/BkfTqttUIK bd3A== X-Gm-Message-State: AJIora/2LlSDCQFqvZgaz6h8IA4GK56PXcusC2HGJ5CFyGgFldGXHXuE D/zwV6YcW9EJMqGXpuBBypkc4DeioXE= X-Google-Smtp-Source: AGRyM1teE/75/hxh3hZ4K/Nvrvr/DMjNVVbY7xFqBLc5W4OEFOwBgCEZl0/oug5eezC2OcT2ue1bGg== X-Received: by 2002:a17:90a:a884:b0:1ef:8eb8:7473 with SMTP id h4-20020a17090aa88400b001ef8eb87473mr1048877pjq.161.1657146095961; Wed, 06 Jul 2022 15:21:35 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:35 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 11/14] client: update command table header Date: Wed, 6 Jul 2022 15:19:04 -0700 Message-Id: <20220706221907.126408-11-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The table header needs to be adjusted to include spaces between columns. --- client/command.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/command.c b/client/command.c index 74f11c4a..c0576e97 100644 --- a/client/command.c +++ b/client/command.c @@ -509,16 +509,16 @@ static void list_commands(const char *command_family, static void list_cmd_options(void) { - display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_USERNAME, + display(MARGIN "--%-*s %s\n", 48, COMMAND_OPTION_USERNAME, "Provide username"); - display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_PASSWORD, + display(MARGIN "--%-*s %s\n", 48, COMMAND_OPTION_PASSWORD, "Provide password"); - display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_PASSPHRASE, + display(MARGIN "--%-*s %s\n", 48, COMMAND_OPTION_PASSPHRASE, "Provide passphrase"); - display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_DONTASK, + display(MARGIN "--%-*s %s\n", 48, COMMAND_OPTION_DONTASK, "Don't ask for missing\n" - "\t\t\t\t\t\t credentials"); - display(MARGIN "--%-*s%s\n", 48, "help", "Display help"); + "\t\t\t\t\t\t credentials"); + display(MARGIN "--%-*s %s\n", 48, "help", "Display help"); } static void list_cmd_families(void) @@ -542,12 +542,12 @@ static void command_display_help(void) display(MARGIN "iwctl [--options] [commands]\n"); display_table_footer(); - display_table_header("Available options", MARGIN "%-*s%-*s", + display_table_header("Available options", MARGIN "%-*s %-*s", 50, "Options", 28, "Description"); list_cmd_options(); display_table_footer(); - display_table_header("Available commands", MARGIN "%-*s%-*s", + display_table_header("Available commands", MARGIN "%-*s %-*s", 50, "Commands", 28, "Description"); list_cmd_families(); display_table_footer(); From patchwork Wed Jul 6 22:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908738 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A8586646 for ; Wed, 6 Jul 2022 22:21:37 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id s206so15174567pgs.3 for ; Wed, 06 Jul 2022 15:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bK+1hhQOyVtvJnFigsHxDF6e/MUMdEEF7UQ1BjC5dVE=; b=p5mZOSg+H85CQWNnamGEy1gAAyXVfknXDgQMmXrD++fFMqWg59a+XfOrviUGkMgEN2 bQq8zHfR61lUZRielt2VVPhuLGGxrhndxCQ1tRneTb0DPkTcYZc9QmXkVjLYkJhL81Qi NCUxXJViVU5GHeiJDdydL0vAOC8RkACzB6rb8efrwe0IEOxmDlvcCQ5l0+K40C9t7HjF vGOfPWZt8rei+6m3n12d6hiDxgeD2J++tpwIxtqbU+RtQ1WmmF0Liuwm3HNWFhpiqOvJ BooNuT1R/90qgjrGcP9A67x2Plp5CQjr5DFEPqhnKoKqJNMt5XAzBi/FJ1IKOwS8roYT 6K9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bK+1hhQOyVtvJnFigsHxDF6e/MUMdEEF7UQ1BjC5dVE=; b=4mL/7Ng0CYsLYOsJbabdIyqHf0qIZxPaq8tPCsj9mxnWjL9VKrkPQLuUS5ohV+5waZ USCCowwdYuHKuBbOI7eop0eTU6ZgyjUnlfvZ81YRjSLJ1BhuT0919OQ1Jcg9poOiCqh/ x2mQDvpZD0UHV7qJPIZoxUOGqrX2c3ErPKyDl41MzCMR9Uqs90cJ5MCyEnhVRNooMPKl Mq0Q80p19Wwg7hg57m9q4P0i9rct62RoYBrzw/88cxWFJ3uiSgPw7yo1Nu9UFu8bng9g 2Px6y5b/IQa5MOmRcD4rNEHtjx/35N3/FTZHzBKpZ3FGsMrkLJZ6ots+HxG9vJYdp/S4 m68A== X-Gm-Message-State: AJIora/2ZAp4MoD3pGsj9zrULUT8dnq9n2WF8BU7yeFdnGIiRaqwrsNU mkVjv/EWWMK6YhfbvBCIygzx2DHDxRg= X-Google-Smtp-Source: AGRyM1vwpuRzw4CssGyGLauudfEPjfqAXljQervpnFAp2qHi4+TS3r9kH4V8QkC96xdkHKDbvCJvgQ== X-Received: by 2002:a63:2a82:0:b0:412:82d9:f015 with SMTP id q124-20020a632a82000000b0041282d9f015mr7814288pgq.447.1657146096729; Wed, 06 Jul 2022 15:21:36 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:36 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 12/14] client: update device to use display_table_row Date: Wed, 6 Jul 2022 15:19:05 -0700 Message-Id: <20220706221907.126408-12-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- client/device.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/client/device.c b/client/device.c index 5b971883..9f8d731c 100644 --- a/client/device.c +++ b/client/device.c @@ -54,9 +54,10 @@ static void display_device(const struct proxy_interface *proxy) l_free(caption); if (device->adapter) { - display("%s%*s %-*s%-*s\n", MARGIN, 8, "", 20, "Adapter", 47, - proxy_interface_get_identity_str( + display_table_row(MARGIN, 3, 8, "", 20, "Adapter", 47, + proxy_interface_get_identity_str( device->adapter) ? : ""); + } display_table_footer(); @@ -216,12 +217,11 @@ static void display_device_inline(const char *margin, const void *data) else adapter_str = "-"; - display("%s%-*s%-*s%-*s%-*s%-*s\n", margin, - 20, device->name ? : "", - 20, device->address ? : "", - 10, get_powered_tostr(device), - 10, adapter_str, - 10, device->mode); + display_table_row(margin, 5, 20, device->name ? : "", + 20, device->address ? : "", + 10, get_powered_tostr(device), + 10, adapter_str, + 10, device->mode); } static const char *device_identity(void *data) @@ -368,7 +368,7 @@ static void check_errors_method_callback(struct l_dbus_message *message, static enum cmd_status cmd_list(const char *device_name, char **argv, int argc) { - display_table_header("Devices", MARGIN "%-*s%-*s%-*s%-*s%-*s", + display_table_header("Devices", MARGIN "%-*s %-*s %-*s %-*s %-*s", 20, "Name", 20, "Address", 10, "Powered", 10, "Adapter", 10, "Mode"); From patchwork Wed Jul 6 22:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908739 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A0B8666B for ; Wed, 6 Jul 2022 22:21:38 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id g126so1225228pfb.3 for ; Wed, 06 Jul 2022 15:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nhQtO/Y2h9D6l5zhv4lQX1YLXzkVZFFQJbFi4F+4SY8=; b=HJi8gbUOysrULXTmBQA+nehDJvDR0f9/a9w0wTXw7Zde3MmfRjBHQOfy7uv6QqTUZB tu8M+VIVStttGWY6nBm394NtHNRVcIwho5OEgRf9+pp1+FBjMNn/D32ITa2Ld39P+e45 aXvmg2+zOlkYvcJOhKzgpnP7HYNOKzO4e7SKSNJLy/sWhlCPyZFCe98kRnTQ7UJo9d/3 RF5VyRwElI83RMRkgKpI0OC1GYPlEOAykkVksij1gPvJRSPZfaQw2i5vmN/FV/yw6KG0 58GWlN4ta9GWKo1QCqF8hdAJiLHPoN7ItBhEmV8BtSANeVuFnCKMWEHo/GVc9DLRohtR RZyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nhQtO/Y2h9D6l5zhv4lQX1YLXzkVZFFQJbFi4F+4SY8=; b=sdketImCBkSXjCtGGRfaibCjrG3JiqqyJZUzKnkv48AuHGGIMQ5HzhNtzrrFT9sER7 byVNGREElQ5DFb90Yi4bi55rU1died0nOq5zixJgQZGhS2nUCvQi0WmgR6uBNX8QrD9C YdU/1pBk9nI3o3i1sKAawKnZJ3GwLTZqG3A4AH3pg/U1DA4FGEHFn77w3VrQh7S8T8GG agqudzhsp5FjftBcORKnsmxrOr4azzsaMxfe44P7qo4oG4CwE+qivMmunMUupnirNP8C pJahHR0gARkpB12gUfJK2zW7UB8VeG9DNrYv+OXCR1/Wu3Bg6B7UCEX2NUGU8jYTT9OA 1v+Q== X-Gm-Message-State: AJIora/rQK6XAdjUA5WPUaDWbEEDrblMguSSGmscliIB/y2B3th2fYvN rZwvraXNL4/mnM4+wt8i3qj8ndMpfGc= X-Google-Smtp-Source: AGRyM1vO9Cvd/aOd12Xc1yaa2JANEuiBqz+3xPq2J6pekbDwqi4MXPn/OzObiwK5OAeS913d5Xzxfw== X-Received: by 2002:a63:1f66:0:b0:412:2f72:ec19 with SMTP id q38-20020a631f66000000b004122f72ec19mr17354122pgm.282.1657146097529; Wed, 06 Jul 2022 15:21:37 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:37 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 13/14] client: update adapter table header Date: Wed, 6 Jul 2022 15:19:06 -0700 Message-Id: <20220706221907.126408-13-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The table header needs to be adjusted to include spaces between columns. The 'adapter list' command was also updated to shorted a few columns which were quite long for the data that is actually displayed. --- client/adapter.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/adapter.c b/client/adapter.c index 6a0d3455..394eae0d 100644 --- a/client/adapter.c +++ b/client/adapter.c @@ -185,9 +185,10 @@ static void display_adapter_inline(const char *margin, const void *data) { const struct adapter *adapter = data; - display("%s%-*s%-*s%-.*s%-.*s\n", margin, - 19, adapter->name ? : "-", 10, get_powered_tostr(adapter), - 20, adapter->vendor ? : "-", 20, adapter->model ? : "-"); + display_table_row(margin, 4, 8, adapter->name ? : "-", + 8, get_powered_tostr(adapter), + 20, adapter->vendor ? : "-", + 20, adapter->model ? : "-"); } static void *adapter_create(void) @@ -268,8 +269,9 @@ static const struct proxy_interface *get_adapter_proxy_by_name( static enum cmd_status cmd_list(const char *adapter_name, char **argv, int argc) { - display_table_header("Adapters", MARGIN "%-*s%-*s%-*s%-*s", 19, "Name", - 10, "Powered", 20, "Vendor", 20, "Model"); + display_table_header("Adapters", MARGIN "%-*s %-*s %-*s %-*s", + 8, "Name", 8, "Powered", + 20, "Vendor", 20, "Model"); proxy_interface_display_list(adapter_interface_type.interface); From patchwork Wed Jul 6 22:19:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908740 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1B426646 for ; Wed, 6 Jul 2022 22:21:38 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id g4so15183936pgc.1 for ; Wed, 06 Jul 2022 15:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NBza7GTBinUd6pDhR8LmGnIFuQRHAGBueMNiYVmpyNY=; b=EDFwL54sUMDtcd0oN1OZugemeuPZfiiqVmfEJLbLG0Muy46Ttn7Knz14HnxFJtnLvX lufcy0ufcLfSmxLNmg7sfbzvd8G9IJC/blWUfyZ1gFcbPeUdbuZn5+1iojukMCEStwAD UK7ETwnF/KDdNi3EmQAZwIb/W+O0oL+FsWul+ZrjKrEoahEcU6ZPNBghVx0wJi11FSk9 pfDpXG2KUPNYHdKX2SDn5kAnLji5OqoesCULNlFTkgQephCREXdro7azAnz9AlyKqYRI 5dhIppX0a8dFmR7yNPM0u2dS+pxrz/l759wRA0PGKNjEtr+vU+lMkbMcy8CxxLDInoLw 1xgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NBza7GTBinUd6pDhR8LmGnIFuQRHAGBueMNiYVmpyNY=; b=VfKqPjCRTcbwv/M30hkTKvDn9vUo12AKMtYfJO/+PU0sy85DoiuSIA2NuNhxbndUmg WbIB5HnLpd7JkAaaYUuoFum92SD8DAUq/8u7MHhUwbxLEOxULg2lMPTJoeibf3H1UMPL vV5ZZn2PlIS/9tnz3lTT/fUbD3cfdf26qjtG0C/rhKlSxQhiIN7JS2K8al+wAi6b41vV qipfueNeqGjIO0hNa+ZE43VtmiG95zbWjT6yKUxSdVuO2Vs87Pd5Q6IIyUv92zZJlHvm 3kHDl/Sfpk24ovrT7ZJSzQ20FLXbLh4JLztzzWMX5tCgYmnWQMGsFfiBaQg2DS+tui2f qCUg== X-Gm-Message-State: AJIora9CZPp957SQgM9P7aXOalZEl1HO6cZXMlpv94ef0BfaM9mhQEWh 6ekMBjKvXWKqQk0bOfHQBrDfM3HUmys= X-Google-Smtp-Source: AGRyM1u+eAY4f54FINz/Ah1hoUAqHdk7KEAme2r9W7hYF9Fg8YOXHvqNf8e7H43kGvSU9tIp+tvyzg== X-Received: by 2002:a63:88c3:0:b0:40d:5f26:bfa8 with SMTP id l186-20020a6388c3000000b0040d5f26bfa8mr36125859pgd.608.1657146098332; Wed, 06 Jul 2022 15:21:38 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id u9-20020a170902e80900b0016a163d1cd5sm26517696plg.253.2022.07.06.15.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 15:21:37 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 14/14] client: update ad-hoc table header Date: Wed, 6 Jul 2022 15:19:07 -0700 Message-Id: <20220706221907.126408-14-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706221907.126408-1-prestwoj@gmail.com> References: <20220706221907.126408-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The table header needs to be adjusted to include spaces between columns. --- client/ad-hoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ad-hoc.c b/client/ad-hoc.c index 33bff9ca..49c97f74 100644 --- a/client/ad-hoc.c +++ b/client/ad-hoc.c @@ -117,7 +117,7 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc) struct l_queue *match = proxy_interface_find_all(IWD_AD_HOC_INTERFACE, NULL, NULL); - display_table_header("Devices in Ad-Hoc Mode", MARGIN "%-*s%-*s", + display_table_header("Devices in Ad-Hoc Mode", MARGIN "%-*s %-*s", 20, "Name", 8, "Started"); if (!match) {