From patchwork Thu Jul 7 17:54: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: 12910021 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.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 4918D2563 for ; Thu, 7 Jul 2022 17:57:22 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id y141so20895989pfb.7 for ; Thu, 07 Jul 2022 10:57:22 -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=xOM5jVCYT8HDLJC9OsOQuzgGtVxd7IKhBqopko8l0ds=; b=eY7w/jK77vi8B/oMTEVVMY+JRIdLSlBAoiyMLebpDCEdTl3sJzpiHV6kJuS7pYkQef r9hEBfA64SEsUfpgX7ClPdcweoq/P1yWlVQ709a5n1rO5fKQz7GIwi81zXxN1NyVLvuh Ba7yx0BTHrwMqvvf4eThQcnIy6U0be1+It+WUqDy3jYJYh1WDQJWyen3s8XhJrkbsME2 G0ARw1J16x1CI4vU7Kf6D6GQDU61+B+YfDmvoYTzs7gRDysFy9TbeIIfmwiomdTZNcZg WBpUjIhwbDm8lUm2OJ4lYBsXOfxUPatuTAe4Ux2KFrspOFYs04JGS0cZ1zFmjpiBVpcT fGZg== 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=xOM5jVCYT8HDLJC9OsOQuzgGtVxd7IKhBqopko8l0ds=; b=DSzjg+hJ1lpJQuPcdmIuJjYoFD9hR5XlPdV00O6SEFVWE0AqRqrYPCzQQsYsUiF/vb FYd94TuX2jcQJOcA2VgHP2nfo6Ydiz40dMbaKJtfi2955J4ck3RJ/qjXzRjRwOH09ie6 HEiRkwH6LBbxv9OymUXdjdYCdd0k0L8OYIHTlOonKtO2NtgG3mIOnj0JQDpHUQrAt11M emdqSSrPPGUXkmQueX5qmJ5oOEve9+msFyi8u561FCfhD61q2277EQEGbgp2qvYFQA9t /drzPALWB423y34yJXJgvpUtNOZhYcK4ZtmGT4miqoamzjqGjKhse13Foscrji7cHnsA qrPQ== X-Gm-Message-State: AJIora/aa5/Epn3ooJxeJCTsH2FTvXkHIsfBvBNP/4xAXSFzJWe/S+SK hHTR+xgS6BMMdE0SFeL7esbqltivgs0= X-Google-Smtp-Source: AGRyM1tFVognMDGCCBL/Diw+7YPR4NiPEOuo3+slUJK7lSxVNVzDbvP4FT/inLTWHaZW8eTfIbacFA== X-Received: by 2002:a17:902:f785:b0:16a:4f3b:a20c with SMTP id q5-20020a170902f78500b0016a4f3ba20cmr55266583pln.118.1657216641365; Thu, 07 Jul 2022 10:57:21 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:20 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 01/14] client: add generic display function for table rows Date: Thu, 7 Jul 2022 10:54:58 -0700 Message-Id: <20220707175511.224597-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 | 181 ++++++++++++++++++++++++++++++++++++++++++++++- client/display.h | 1 + 2 files changed, 179 insertions(+), 3 deletions(-) diff --git a/client/display.c b/client/display.c index 07cb7bda..8ebbb656 100644 --- a/client/display.c +++ b/client/display.c @@ -376,8 +376,183 @@ void display_table_footer(void) display_refresh_check_applicability(); } -void display_command_line(const char *command_family, - const struct command *cmd) +static unsigned int color_end(char *s) +{ + char *start = s; + + while (*s != 'm' && *s != '\0') + s++; + + return s - start + 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) +{ + 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); + + /* 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; +} + +static bool entires_done(unsigned int num, struct table_entry *e) +{ + unsigned int i; + + for (i = 0; i < num; i++) + if (e[i].next) + return false; + + return true; +} + +/* + * 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; + + 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); + } + + 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 (!entires_done(ncolumns, &entries[0])) { + 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); + } + + 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 +563,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 Thu Jul 7 17:54: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: 12910022 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 0EE962588 for ; Thu, 7 Jul 2022 17:57:22 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id 145so19846845pga.12 for ; Thu, 07 Jul 2022 10:57:22 -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=Rv6Y3UikDfrFpd6c1f1A6LOPQBjGQF9nYOzC5Ij6K98bhv4LRsFr9I64C/Y0G4Ycjc qN2YYibmr9vxpe4JgzCVM8MH13fkw+v4HGWOgJG3K8yATzJFO2bUJYCPYtsdjQ2oUsgc GmfFE8K8uzH1Uob5QxNYjjCZVNnfVNZvdxHUpMLriSsCvnVEzFRI3GOI2ujBruFkrB6n IrFDPy8GiCm+oR+yMSE8JuNZHVA7he06j34LLqdyph8amUPjEvz7yWhm1Cz4pCcAlxUS CK8G06n94bGB+00Qy2D0Fmr08WO0BpIG8+Y72fysU/VY9oGnpY7iuauyUpVWwpsM5wS+ Xi7w== 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=0GtTe5nCxQPQbLWGMCIQME4eW6LjE/rWe3lG9GqGQszX9FkvWHe8oPl7Jo3xDsK6ec U3YqyNF0R4AiMnt22p6Z+YI7z4N/n/icZRm3ZXnrw6V9C13ZEkRUmhMmNlrVbqTc4YI+ 6YxcaRqjWar64Uda9S6ElzKPV0OtKRt8vnR85vl/fcrEliTcAnrIUz2gRmdwdc/aF9Wv IrgE0yHrfwXzKrU91zCVk5RJEmEqx87aAuPRhxxbKyPygT4twdvL41IPp3Wu5lbmKt3l 6z1/XWXmd+h51DgBEoHNqFuIvrSbExyYttw0lUF3BgBB3mD64hECptrmZSPSl2cHlpD2 Ac0Q== X-Gm-Message-State: AJIora85HbZvwGehzzJUvyx6mp6Fw8Dv/djcRFCcXXz1r++AxqXJy441 +ACO5pkF7LAtpfZ5y6aNAXYqG2bq6EU= X-Google-Smtp-Source: AGRyM1vwzz+o+8MXlp5bbH9Kw9ouLUvhF8RO7dIDeyN95deLlRvtbofQqStO/80p5myxJ4M8ZiL90A== X-Received: by 2002:a17:90b:4f8e:b0:1ef:9e43:790b with SMTP id qe14-20020a17090b4f8e00b001ef9e43790bmr6423935pjb.220.1657216642273; Thu, 07 Jul 2022 10:57:22 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:21 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 02/14] client: remove newline/tab encoding from help description Date: Thu, 7 Jul 2022 10:54:59 -0700 Message-Id: <20220707175511.224597-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55: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: 12910023 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 1F9B62563 for ; Thu, 7 Jul 2022 17:57:24 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id i190so7268059pge.7 for ; Thu, 07 Jul 2022 10:57:23 -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=g2iwoh2iqSqtP8D1+imMa87GOklH8CbJwPYi7fdnqKve6IYsy8bgGVrBK1Va2gDQHm Zww1k3ZcuizWf6uZ44oI1HFdvcnMdELLIQnXrHP3Wb56h4fcZCF4xpDKn+rtWrd+4o8C W9ThI/qMlFR164dz1ESOPmy0yHT0OSMqkmfb7POveUCtLQg4AThXWPMYJqyQTNWw/pFV ydPGWOXZC5JeprCLl42oaPhySmlHY1NwtECgmqC9vyAG3y4Mk5BubPU+Mr6OnzKHo6SN FPdV/ekeggC1M4h0aCKn8s3hJbO/8lyjYp5nTZzKElWHoMKbKKni4Pz03qai03bu0Lvh JlFQ== 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=oq7ftlYYZeBpRtZ4WEVs/rqYcXkOfEMm3B1xy23jSmpM/Gyql3YxqXztgsGpwA/bZz jzJGjjsR/79EKj9rjamt2ufFAlNiql9l/fPbdQozB//ZBvoyQ7Z3aFxpZh44niSoaav5 XkQ+QtvByarO/fK/VrvIDnbIV/Eb0mUmeT/uHFrfy6bi/qNPue0rmioUYk/YK2lD7ePj aPvX7BDpQ61/khFd5BbIcsBq8/oj2+x8zo5z9uL8C2iyv1FTSQeB5B5agLAFLr0bngBF kK03IeM67jpLtHYQXN0w+rYRRJTYvex70OgtMle9shFhU1a6KBArUDtJAfzTNfOd76XW NzoA== X-Gm-Message-State: AJIora8oQUYBYrqovNKoMV5Lrb0UQtqWmAE+mdCOc0g0GJRgC2whbjDx EcjfmHQBK8QZ5nlnYCc6F1AGl8cON+Y= X-Google-Smtp-Source: AGRyM1uJpom991KpnGrA4eeiZ1FBuNKOoTLUAmlL6VWivGiGI1l7cfTRmdeiS97S/ai6KXSLBHZtHQ== X-Received: by 2002:a17:903:2cf:b0:151:a932:f1f0 with SMTP id s15-20020a17090302cf00b00151a932f1f0mr55145399plk.130.1657216643193; Thu, 07 Jul 2022 10:57:23 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:22 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 03/14] client: update dbus-proxy to use display_table_row Date: Thu, 7 Jul 2022 10:55:00 -0700 Message-Id: <20220707175511.224597-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55: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: 12910024 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 E70AE2588 for ; Thu, 7 Jul 2022 17:57:24 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id e16so8135114pfm.11 for ; Thu, 07 Jul 2022 10:57:24 -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=fOcFVK0PS27Va0XJN9RAE7EyDyIgTw0fd6lKu8d5n4XuLT2SSbOLfD48hESd/WuOkk Pz+QO/znzojBm+sF8DabSjQ5FiRzh0pK8m218xGmFjDAKO++Q3sxcp7ONfxodxDbh9Dx D4iIOuoyFjfWnmXTbyi7YK2VzMLzxA77E0pzLOe+6wa1aRYmey54OHUP84Rh5HnWahD3 6KIof5JToaLDkoqKCWiAq53UezkK6v6i0XJWjaNQXq0k1WV2zdjf8K1e8KvG4Dje/CSW CsCq6D2KxKMWQpTLiUScn+MSuOp0y1QVnkMXkAfLKhjXX94vVezHbULeQebA7xl7QU64 4LHg== 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=V5nBMDMSg1m8QfRvJXczi6sbqcdtytJbB6BkWKJsZXJc8RlEl6a2g4Exufdgjlqayw xg0LuGkxJ+8IfRfPat4AuCEJRR2eMhWYZ2b3qbVsYBWsvmEA2z08/62DT4w1HNftPhxf siBzNWQCnIOFPb9ccHa3ZYjvVwhKoRuuZFtxEInXxoyVDs5NvhwWDGmwTdHoobuBayrO PHFUiY+oh2e3i1VD2xqmttfwG3PBRV+Tov2s6LZCY6HWifCYlVs3jIWjivbVI70lSiT/ SZU8L3RWzfAHdiBG1nF8/72f+FPzCYvLdShaHZEeoR4OBnMRk662/8633BBoS6ZkkPBR EVTQ== X-Gm-Message-State: AJIora/yPuJANT0xnIrU8P4ETKvmhmXEUj7wx+AvUFvp70iDJq7L+Ft5 dZhR5ejiLQxuNObkbAKiunomTlNM0U0= X-Google-Smtp-Source: AGRyM1tnLYhzkI0Que6hSFbzPA6HMzXpVa5Uz8pcu1K7RoNiPfqsTwFT3axXy9dp23m4WJSqp8++hA== X-Received: by 2002:a17:903:2310:b0:16b:fbc4:bfb1 with SMTP id d16-20020a170903231000b0016bfbc4bfb1mr12689450plh.100.1657216644130; Thu, 07 Jul 2022 10:57:24 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:23 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 04/14] client: update station to use display_table_row Date: Thu, 7 Jul 2022 10:55:01 -0700 Message-Id: <20220707175511.224597-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55: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: 12910025 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 0FCA42563 for ; Thu, 7 Jul 2022 17:57:25 +0000 (UTC) Received: by mail-pf1-f181.google.com with SMTP id w185so17188596pfb.4 for ; Thu, 07 Jul 2022 10:57:25 -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=ffbOG9mhL99EfnHxSJEuvCR2pSgXJUotYAtUWv+Z4w+h+dL8h2hK1oHvEADlLkfFDZ Ras4JIynv1vBMVfv63jku4kE2grn1UlmuxJ3ujhhzYUJb8eXiHB7wa1pnNscTAuXic7G uHSvCD/6fskoGyt7fda8UolxB1PWxMiLHfcY/7eKS5tzkeSw/yWSubbgJWxk8Qy9ETla oUrd5V/Gyhu3Kjpfva/kwZaECia2k56qYq5ZxArFp5gbnNDE1MsAiuLG4wjFD4kbyhFD SN+IkLHwiGGpXsRttxPzUxLjib/WcL4S/yTOByFsEKvTjUyWmBnIKNXGMiQZACUVPhtG SJgw== 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=1UiLd64HQHOTDC8JQ8D3wRCJ94xKvJQ19g21yLB9BnDNjF80KTXPV1uJk27ZucReag kJ7vBgtx49srx3t20UCbatEnE2LSg3fKCkqNCqXjYoxSxyZQwSA3xoOTdynBvq64ouqN YOTqcfL2XdacIIThbVTxLWaRp0Bx0OE62ZrNdy/Dxlc9ujoKln4WmnnvV6Jdl9NfnCGd Q17QzYUtZqnKpE2V+tSPvVSwpiwV9ucJ2/1VJnPuDD+dStstCPCawSG0CXOjlQ1W2uSs LcTIrlteG56YzCarR9jLJRBY/RvCcp/P4aMvgagWLKGbRaRBo2c8cAC7jM8w9nVfcx2Z qkjw== X-Gm-Message-State: AJIora+jWKQhHXEU61QeUzMKTSgj0yNBZiw4Jhh+IUZp7TNakr45Njk4 nG08vQ4dhNmIRMIqdLMzapAAQU+tOaM= X-Google-Smtp-Source: AGRyM1ssx5OGQt77vOfWWbR6o4x7+MWbMIn7PI3HHG+ni8Vo1kz0SZay9kmdya92H006YD8P8O5YKw== X-Received: by 2002:a17:902:dad1:b0:16c:1c97:27fb with SMTP id q17-20020a170902dad100b0016c1c9727fbmr1693923plx.11.1657216645373; Thu, 07 Jul 2022 10:57:25 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:24 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 05/14] client: dpp: display table footer and set to auto update Date: Thu, 7 Jul 2022 10:55:02 -0700 Message-Id: <20220707175511.224597-5-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55: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: 12910026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 5DC022563 for ; Thu, 7 Jul 2022 17:57:27 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id a15so20875657pfv.13 for ; Thu, 07 Jul 2022 10:57:27 -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=q3zOTw+FN+14ilAPxtuzoBQzUeQHOqTyQEmSba93kzMXRlMbBqDZs10favaqY+SDVR VE0Rhu48tRDtNnmK69m5ImjVUVjCxkucQnI/CAZNe6ECGLCopKP5JPuoO20UCBVW086M Jm96ldhM5ztFB0bvKy8IVLp1/uUxgO6jT2e6kyUyDsYwUu9a2xPtRjhVFeNSit8sowYJ Mdg6QOVKeONNFItBfER5fdjXGX21YWY97VWlRVbFtgUFCzXiq+wuTxXxx1JLOcPg7MOU HUZ01o2Hj/t/NgEkzV7xoooS3DMoV+cPKdrsbnDWiJMI8b2o1TVw28bCmHpOUaR6Bejn 03uA== 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=X2uBT22NNw79Av0EMR9TwQE8gbmF5OCSLnYz1tdwJlxo35jHFDy5mdF8CYIQYTO0JD B/o1o3hTP01hSYpqH3jbsK8MWpwkAj/E0To9C1SfZ0XmwCJtfV7Qj3Z1vCL012xyvgGH fuxPyse1dQhnZGPV/8oCMMJCgCTvCYWapZwqE1XKoyrZjLgqv05WkT43BfBwXuvwbMpf 0vdcEVG8sE743fV0Y0VXmSDxXkBzpHn4hxIqq7Gk+mEaBKw+yLbq3TIf2DRw8p9F9LJG pf1zZrrYFgb78dCiBO8HY5aNR0nguZLWqxxWn+cnEorLhB+WP29RlDi/WHYoFomwNtQa UoKA== X-Gm-Message-State: AJIora9pc7duF6ygLAV7e0IshYqDx3RXCieM0o71DUBHpAM6ooa4LsZt L19UqEqdnLwtBQBegFNWBlFEzhtSFFI= X-Google-Smtp-Source: AGRyM1tqJqqHXzRS6kbJzv2q2Fele/3oM3HKHWC9dFKLMRCfM/OtzJ0w7keX3beXHFAogToY6OfxAA== X-Received: by 2002:a17:90b:17cb:b0:1ec:9d52:46f7 with SMTP id me11-20020a17090b17cb00b001ec9d5246f7mr6493869pjb.221.1657216646663; Thu, 07 Jul 2022 10:57:26 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:25 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 06/14] client: check NULL return for DPP cmd_show Date: Thu, 7 Jul 2022 10:55:03 -0700 Message-Id: <20220707175511.224597-6-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55: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: 12910027 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 3CE3F2589 for ; Thu, 7 Jul 2022 17:57:28 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id b9so4879929pfp.10 for ; Thu, 07 Jul 2022 10:57: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=BmMZpc14Ab1wbx04tHduSMqXwFCtXithIXdMgoNEut8=; b=CN1PnVX7agQYi6DaKBGIyE+NTmnlHTJl8Eg56RBP1UzAd4oQ3Ywqz61V8MD2GX75Nz PkmFJjS/WpZX0Ii0xff/vLWcUg9RO8Xjyd3yXMJXHxUJvwVisuubZbSzJS0nVEyiIne2 j2Q1gVT8eepMFXuoN62wZ27rQR0++rITzXsllNtoiGlLXNBdBA+y71pHLgV3QKDB3irO xyXXh8LJmOO64oBI+Y62h8H9t4/s3aHHVKDXxjmXuu5BZgACqDqH1AQgqhPbXx3nWNZv HnU2z+ja9L9d+yEjQNwL8uHWzJzVfXpPSFefEuIE8m35MqJ2HQ/TCjSpmDW6T+Du0tpU DwFg== 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=fbC/3Bgv7kTScj77YFIFokl7F5Bk0SIk1m1KpO38ZCcZ8nru4BwAO2VY0k6Dyr2k6k PhiNY276ozoX6j8i4PZ132hB3zJeIsNucPViIzs9S7SByVPpyAx6zHbWvR4cbj5OTgeW EExoCQPzg98a6zMKWDMGgie/iBCXvJxbPcHeH7JCTG3+TEY6SXwDaT1zW687/66JuIpU OhHwXBkZvUipxnn+RL143kahbSA4tDDCfOocuKEfjp7zXGwtk57mYnTLdQB5uZYizPfc 354KIHKrD3iZAcNzODziVTFvp6ctK7Ra8nqGEqrA8cFHt16+t1pXwlCEbY+ulhQQutC8 U2JA== X-Gm-Message-State: AJIora/vtFMim0LGWT2bJo+7w4XnN+HgEwdUBjD5X7CMMohPyBUaoLYc uB3Ps9oS3RXXimm3jA/dQOqW5DcydsU= X-Google-Smtp-Source: AGRyM1tnm8Y9eq+UTzZMkrddRcClLsPNhV1O3RdaaV+GcpNSqywRRo7aMMRKE8e3tWlInwR7VAtaog== X-Received: by 2002:a17:90b:1a81:b0:1ef:9e9d:a08a with SMTP id ng1-20020a17090b1a8100b001ef9e9da08amr6590052pjb.58.1657216647484; Thu, 07 Jul 2022 10:57:27 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:27 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 07/14] client: update CLEAR_SCREEN to be consistent with others Date: Thu, 7 Jul 2022 10:55:04 -0700 Message-Id: <20220707175511.224597-7-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55: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: 12910028 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 1DDC32563 for ; Thu, 7 Jul 2022 17:57:29 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id e132so19870161pgc.5 for ; Thu, 07 Jul 2022 10:57: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=xRFSUNUSmipN05MnQpN5w2QZdhIlRQ5RwsiNiJvslkc=; b=M1oYB74VKZUkSB2PyUBnZdrbv+kTUwL7PiMZS4ipKKojsdoGH3Y2ThwIl9MY8wCBe8 pWAlDnAepXyuCAe75aK7qrxmdUHBV97y9T5vyIy014tCFMVKMOAYQe7MRPwnH0yiz2xM 370Yt/ijuKMqA3y5fyNdGsFlooT4HUFfEGoijcbL6N854zHRjd+Xh0KOtVuJzXsM0fwJ 6EYOQ6ixmAXsLFqYfa+vBcGRRdAJ0gV1DW/QtKID9E32BcDvABd2TKJMj01Bidbd3v+4 qSXQiaqwCfVVdWYaTSh8tQxjpRSuHV02MfcBgcRr5PGpOb8N2RuSwwCTEaiYYaw5Y45s i9Mw== 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=xRFSUNUSmipN05MnQpN5w2QZdhIlRQ5RwsiNiJvslkc=; b=lPG10i+hRiJtAZ2sMfjEpkGVitNFqXCTAGJXBK1Zn8aYXUdNgGcTghxXj3irCdtDIk dN3i/Cvym4lwcHVcRKIBLubXtl9tqrm/VjOCZ90KXY8WAzVkn6Ov2DIbvBsPKIB149Yn SMESLIMhyPyBHtEdrw9J+f2xmjIEj4HD8pkyXbvJ7PeB5aovsc+tKxnYtLfCkUBZ//p7 bPvdPs5NZRXkksYOxCyBo+OvkuLycAV59EtKWgxIda+0u0ElqY8TEPZ1I2j465zjXDwn nH8oqi+TpbdD1guA33CmAUX66p3Cfq/0MbXyJAAGLZpLXXIeYxlxab9ntTTt78aSJ5kG AGAA== X-Gm-Message-State: AJIora84NKamW5DbQiGsK5VlT7Bsa1Q6Nn2xBJlUX+uaa7cjh8lNFKHh 7d3tVkXL8u5SgSJbqrUAUi0ZkcxFGyQ= X-Google-Smtp-Source: AGRyM1smMWYsvdOjp9/zC4iXtibPaKdaX0hrsy7n/dMIPWI18J1+9uSVna6apsYRWlRiux8G4lN1XA== X-Received: by 2002:a17:902:7e85:b0:16c:593:d91a with SMTP id z5-20020a1709027e8500b0016c0593d91amr8317429pla.155.1657216648306; Thu, 07 Jul 2022 10:57:28 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:27 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 08/14] client: make COLOR_* macros take a string input Date: Thu, 7 Jul 2022 10:55:05 -0700 Message-Id: <20220707175511.224597-8-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 8ebbb656..004b0dea 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); } @@ -774,7 +774,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) { @@ -820,8 +820,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 Thu Jul 7 17:55: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: 12910029 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.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 0660528F2 for ; Thu, 7 Jul 2022 17:57:29 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id q82so12698384pgq.6 for ; Thu, 07 Jul 2022 10:57: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=ELqGjbsMcYDjGvtKz7OxIarL+9ukO7rrB/sK/SQ9ato=; b=oaFd7hcWfowkrHZAXj91K2X/PwXLl67k8FBjlrJUy3DfQws8G1Ch50hb9+3hkvcxEo NpoNktKZEXMyAky+lmJ86OWOmnhU5V48tOD39Pdqdl0R4dwC+j3xb5fPz8H9X4GgjkGq QkL6hpp3g6L8KpZ6knto+4IsBSS+ZeaphRpx6bdQ5EC4ll+khbx5OQwMNRUeaeL5MYD/ JbBmltLsgMrVToLk/I3iQ9ygwmEFYSIfROM48+uTNfucm/loX8NzRxcr0YBinHaP5k3p mk237EAEgeIFy+33d4bZz5GZd/iGXDoOY/H059afaix+tIrTxSHv3CMv6wuNy5eJCW4d P/iA== 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=ELqGjbsMcYDjGvtKz7OxIarL+9ukO7rrB/sK/SQ9ato=; b=IpMBtwCpWvjUq7xI698qPQalLUiY9alPSSq4sVq/ouq6mnZ0iLVwiP3pHtFWEew4Ln z4nLA1QC2OF7q2Ox5eXzNwmWYHM5PHbeFQFEtNDJP9RXDU260TATBwCG7u2zdC4NqHvk E9kXjNY8lR5DQRkorDGrf8MDcqihKWELrWclnHGUtfXAQkDGA2uToh5zMExkohWOMjKL ngbNUdyQldc8B4erAfVaAKZxm/BlQs5HqN3UJafnUHhA9CsgIW5GeD7BCVFAankqhif7 T/9P3pQ0sxWNcQB8qlxcpmSUMk5y4Z1HSI+4RT3UUyikC/xE6xN2o2vJFNgfF3WCVH8B bcBg== X-Gm-Message-State: AJIora/NypPjU36sx28vBphlhDXuJp0jfGP9F0t8KBp1h4s9sq08JYTH uaYhyIiLofzBufsHw6R4bqMsd/VLSZQ= X-Google-Smtp-Source: AGRyM1u0rcmg4Zl1PYOxJcFIQiNXr+V8tNIe8clPrj9kQZYujbNl4qM++2nV22FQPMgXDIzQlwkjog== X-Received: by 2002:a17:902:bd01:b0:16a:65a5:9761 with SMTP id p1-20020a170902bd0100b0016a65a59761mr54608403pls.3.1657216649194; Thu, 07 Jul 2022 10:57:29 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:28 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 09/14] client: update ap to use display_table_row Date: Thu, 7 Jul 2022 10:55:06 -0700 Message-Id: <20220707175511.224597-9-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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(-) 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 Thu Jul 7 17:55: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: 12910030 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 DF3602906 for ; Thu, 7 Jul 2022 17:57:30 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id z14so19928262pgh.0 for ; Thu, 07 Jul 2022 10:57: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=PXAcukMtKn4tMNurUHsF0W8rW62Jn9j4ZVGFC/z9eDg=; b=I1evBFyvCjW2a/qiWOybh7p29Smy/bEEXD5+ibR1lMNZxGE2CDujpedoLyzXNH08t7 tw8REg6eJ2n9iJ7JjsSVJGnO7Wldsa3eIhKCkSVLrWeQsvUhNt2MwM9LwzL7XtsXw/3T wlobCIKaSajfUxECCK1h9CFoKR1/mKhiefT1wKS3e7FeRi2SreF7o+f9RaD3WEKXARkM a5g1zdnlupFxCaccP3uYsiMX032H4XpZYf796djh6LgyR8LWgtjQowKXIXHemqOkGSQB msLHZhGr1NOb9a5Jv4nQsmZgVtllcuKJoq1ulqT7ytd0Z5uyvgINF2cNzwMZ/H4uYSQd /ajw== 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=kvL65UlJlpubtGGewi1fdFFHNFeMT5pptgT93q7SCvfuLPOOWWKc8qdM1TFshRA8iG 5Wahp+D0m3KgQGqjcFg2ZJnMOBgUJQcmb5MUO+oM2OjJT4bcfk8EZpylKd/cGRS4g8Ny 4oMBHfacR3fUSOvvIVvVqfMPipnJCaJRUpFGCgg13tSIvHIEyiKNfcazDpNlzbey3hFq 2Bt+j2261ddsy3j205KwCiw74JKPSAoP1riLhVFDuvmGOERWn/9WxjuyS/ot6R8RE1mo LtsezVX5iiTOGhVb+un/WERp6aKc4qG/AHtKckVt2ieeAvPu0/pUOECr/6yNgLW/Bia3 J/sw== X-Gm-Message-State: AJIora+2FbvunYPYw50cGNLtmSpVT0ZqFEafdB+oeTdkrATzPDFR/hII uBH/JapZ/QgoHaKvV20kJzb1/OaY9LE= X-Google-Smtp-Source: AGRyM1s9J9vAYfyXQjnkfhFf0aYW+mGIs/RSv7vZPbWARNNaEnXHmnpGLCFfGFaxU+YSevhkrCpfqg== X-Received: by 2002:a17:90a:8914:b0:1dc:20c0:40f4 with SMTP id u20-20020a17090a891400b001dc20c040f4mr6497871pjn.11.1657216650113; Thu, 07 Jul 2022 10:57:30 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:29 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 10/14] client: update known-networks to use display_table_row Date: Thu, 7 Jul 2022 10:55:07 -0700 Message-Id: <20220707175511.224597-10-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12910032 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 001EF2599 for ; Thu, 7 Jul 2022 17:57:35 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id 70so5807920pfx.1 for ; Thu, 07 Jul 2022 10:57: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=rRdtgstkk3/2WInkCaBSCRTBij0JsCS6mhIC+ypjjWA=; b=aOMdTn5TNwGCoAVni+Yp6aZcHAAfr0nVpwDBW7E8VZUelj6kMPslO2Ps0/tuZruNRA VuA3/NCKX9Jbif8xe7bJJ9GtoEqLBIF7axPkymQmTCbNRtZv4iu5qSiwr3jr/7mWJzDH E3eyAt/ArcU7x2XdKvTA71XNMqYpfufmJxcJbbve0XfjELr2eERAX93BdonRsk1du+qk IBsaPjFW50nS350cH0547TwimiZHTGjS17cInhEPFbyBSPLmyH7e+NyqsbZvLDZLWFRn Fgilly9lh+PWYgUa6ieNzp9tUT7VQ9ocgLlvNygD+IlFrGQzRfXBkWrb/rvHtaJZGkyK Ut8g== 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=6tiVLnhJH439g7bm1+dI1lhokW9MdW/uWEVx1aAeZ7p7ghH8VTWNfA6SDuyzX1IX6I 1sXxWzO/YgxLfgd2Yr/rfxMdYtLwt9o4L3XsRzCdX7tNLRO85u9Ksk9igVX4duYdZw0D qRfjUymAxNNPqtqGV8qcHjwb9/kd6kfgr2pRCkZvp/ahKKC3FYu0ct3vDAMenOwor6Nu D5hgbaFKXVMom4qUtlMUf9R4P5tg7iXkXqjjyy057H2tMiRxWSsrvXD70Q366KLCEeZG 73GRB9ShdoHiO9QZT+7y2XJfBQ/ImZdhBZnhvqgVxe/gtAUoOGDXFf7Ojf3Kar+Pg6n2 5/tQ== X-Gm-Message-State: AJIora8RoTvh27/buUeRArJ8oO90W7dexsHSocx0vMBCbvWAbS0wV0PC td1z6FtgX0quS6Gg4nG92S+gCvWg6Jk= X-Google-Smtp-Source: AGRyM1ucxqDwKHx5o+GgPAhoxZoB13V8M5XhHun1XW16IiZ1aaF0xvebICGtZ9p7UhCs4dgp/RjjQA== X-Received: by 2002:a17:902:ec8b:b0:16c:1cc2:6794 with SMTP id x11-20020a170902ec8b00b0016c1cc26794mr1582688plg.17.1657216655098; Thu, 07 Jul 2022 10:57:35 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:33 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 11/14] client: update command table header Date: Thu, 7 Jul 2022 10:55:08 -0700 Message-Id: <20220707175511.224597-11-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12910031 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 F13AF258B for ; Thu, 7 Jul 2022 17:57:36 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id g126so6486689pfb.3 for ; Thu, 07 Jul 2022 10:57: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=bK+1hhQOyVtvJnFigsHxDF6e/MUMdEEF7UQ1BjC5dVE=; b=dLn6QfEbcn9ZfbwQ/JGbJM3RSW4NqLI9e2U7YyusxgUCOSEe5Jarg/3LlPqYnYizv5 90xHFZoIYzTHbqjC2yaHzaG57fYkFGjeCZp+0XeJFpzLcClMHcq/4ixBGnx048QAsaFo clNeO4MZCVDsdDfiEIwPgK58XCDA2Wag+V8QTpsZLdhKstII8/Pin3vOdqK78VyoWECR B+Nh1338X7nrK4REB+IoUtjL19cHLo670SUk+cNl//4B/Qv9xdoMVkhT6oKv9XEJm2OY +tDw4MNa2GeppDASM2dEvA+Qrw/JetILIOFVBDZnaT3J4x8cncg1uplSPNaxYa+AvCxE On3Q== 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=wNgAvG1rSsCKVAcqJW3O/4o+ukCPihLBf2Q6BUiaSjWBW3bI19WpsAewabi5jw+Dic upnhLXahjrBa6zlLPfPpGgkG6YQ292IAXZ0EQCzTYDT+8gOOq/95v7OAU0IeaCtJdxhU AqtzjmcKv5JUeYXvrJdMa04uQD2stLKd2FKRZrROLq+lj9mglZXreL3c7N8PRginXrh3 evZGyOdLhfpR0q+j2ndIWnUb89ZEqQRPD+qR70gVIjv4PFxxLRxIYk7Ca5z9xKidVifb IGA996aoYLoR5Gi/HD3i+C9gmfapuakVdFw2+qrTMq4ulGLNyDfk00y6z+6WFx6nw56Q tNiQ== X-Gm-Message-State: AJIora8WL4b6gsALo1SHj2u3LQ+Blv6d4hdUZ17ZTh42kn9bpkHnnL6Q NTkkJ1xYiDY9Vbu+3XKOYglx+rVFX4k= X-Google-Smtp-Source: AGRyM1sql/xR9tZ7yYu5aruF+BoaMV4Un4WjH8bwuC4yPqbj9n1DHe0Jyi2/W+1dQ9aobFRZd+Umaw== X-Received: by 2002:a17:903:228b:b0:16b:ee10:b91 with SMTP id b11-20020a170903228b00b0016bee100b91mr18867676plh.27.1657216656218; Thu, 07 Jul 2022 10:57:36 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:35 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 12/14] client: update device to use display_table_row Date: Thu, 7 Jul 2022 10:55:09 -0700 Message-Id: <20220707175511.224597-12-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12910033 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 887B12595 for ; Thu, 7 Jul 2022 17:57:37 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id a15so20876542pfv.13 for ; Thu, 07 Jul 2022 10:57: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=nhQtO/Y2h9D6l5zhv4lQX1YLXzkVZFFQJbFi4F+4SY8=; b=CJ3LZEAFJwOkOB+9ZHAhscmpEASrzdEaUlYb3CAg1vYB1YFILExLAYaC9Ut53qnAb9 CI4adWDPOFOwzUtGKx/Cu6XuY9hm5oYU1LhFCGj88J8K6Be4iKRysGTEWgc6IZrlYs6d dI2gv2bC8wsMFpHzRPa3Y7eNNeQg85Uy3fyArnXb5VnzjfxpIDzDXmJ2xHlfSEp4M9iJ 9m19z/R88qkSpHq6VaS5WdFF/k1bH/HfyX1K0VYqIImP8rV4JWEXPOOv5lnvQL2pYXmM F1CVxQOxuT6SJMQZmhee/zL22iN+xHF9ApyByfzYJkUOahT2onbNrytLT0klLk15SENq Y/NA== 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=4diw7b70Pa/MYeptG0dLYkM/HdgnKuW0MmuxsZ+3ub6cqXm8ZVfeMCLrz9B0W2uOYl /kxVkfypJb5AAdzoZ8lP6/GPviHeOWj4eYmtlP8mnhY/aNNmNqyso+QDzKAI0clEqbsA YGcSQiKf3E17WRrCHMVKPHrORlOjZGOn0E66kcOSD8jDeTOXXI4fjz+lSCpYQgOzTPlD lAyct/SEFIeDh72JjkjIIcaDFQ9xN1MAOKcIxVFQkY8Ixb+iAPRp2ih0Q5Md7dXCMlIg tK/QS9rtPDr35ovBtC11x2WdkEVRYwUjT6ghzmKbePzxIJ19DbrmYzPh5S+QimQLTnnX IM+g== X-Gm-Message-State: AJIora+Rqhz6plSp1RYPj6v3rtGM9QL3m7JCF1zI/T4gd+UYDg3KAy6I 6lgt2cgTcJosm+RQLWKzQ48QnZurtG0= X-Google-Smtp-Source: AGRyM1tGZcbtoiLZuviiqZJlDQYrwnFQr1xNtecNXSu2bm0g+KHWNboc7BgY9vCKC3Hde/fyD+5VCQ== X-Received: by 2002:a17:90b:3811:b0:1ef:e647:ff34 with SMTP id mq17-20020a17090b381100b001efe647ff34mr1364726pjb.171.1657216657040; Thu, 07 Jul 2022 10:57:37 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:36 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 13/14] client: update adapter table header Date: Thu, 7 Jul 2022 10:55:10 -0700 Message-Id: <20220707175511.224597-13-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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 Thu Jul 7 17:55:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12910034 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 C346E2913 for ; Thu, 7 Jul 2022 17:57:38 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id d10so7124494pfd.9 for ; Thu, 07 Jul 2022 10:57: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=KL7txRJDycl//K1ae5w2kH90y9k9Vvr32QRaSX2Z9Qp1tE24J8zDEKsDIGyLnnqL8u K8jNKSNItyt+bS9oCVmWgjWcELfzvceQuISKGE2woFfzIChgoBN7wdDn9Lz0/f775+ZM HL7wh0J4borM0NhilsYgplxjO0lo0jCJaaWIgiCqx9Z3zOXT4+XLiILI+xoqxooiD7Lu tY6CYvzcJENmXCEr7WO3EJ4G71jvqviPx8j8G/GN/vGgzgC+jPg1Bfbn0l7hKXb5zwC5 08hqo26XeVpRUTvQyR8m0wZQ6umIPFTLQUbh2hrKZP2RSWv/9B49xMEUMoA6Oi9i68rQ UcDw== 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=XhiHK4WGIaZTzKw3BkVDmJAOf69J8CsFQ/ISJSYCpLnA0C4twmM4uF1P61KBaqO1jz mElPyCGybRuGuD8OikXcmOZLyAz0sID5nTQn1q1K55Ui1szsQtt7yV5CP0E1zq23xd82 XNYv6yXiYqbnEO7HKbHE6VAXpfXLUAwdFCjj3KAzY3HbaHPWu9tRBeR2cUIGG3WbCF0W EsJEL91jtj4O7nbcfL0CPmtkXE6gga8Gs7yezMWwkYPVso/t+lHVdAu2TJlLeeWiU0AG dtQRln1sQx9JvGOdlKJAhRzcmTzb1UbjzGMEXp5rOuiHFTWf0qJxXenwRLfcF897FiQx nHfQ== X-Gm-Message-State: AJIora9dVIhy0uduFW8ugeNXqMWJ1ykmzff5SHmUa2qwCeyVjrSTjS/N NYouByrS6ZN0SLZyN3TaPQC6suS9dHE= X-Google-Smtp-Source: AGRyM1sLolCOn5DcIJNvxNAFEPXWM0w57RuU/59eUxSunBGGJRRn8jRFYmSJRzC0S4+XIeFVxXRt8w== X-Received: by 2002:a17:90b:2152:b0:1ef:9c75:66d8 with SMTP id kt18-20020a17090b215200b001ef9c7566d8mr6765873pjb.5.1657216658045; Thu, 07 Jul 2022 10:57:38 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id y3-20020a17090322c300b001618b70dcc9sm28855223plg.101.2022.07.07.10.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 10:57:37 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v3 14/14] client: update ad-hoc table header Date: Thu, 7 Jul 2022 10:55:11 -0700 Message-Id: <20220707175511.224597-14-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707175511.224597-1-prestwoj@gmail.com> References: <20220707175511.224597-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) {