From patchwork Wed Jul 6 21:28:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908667 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 8269253B4 for ; Wed, 6 Jul 2022 21:30:59 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id a15so9619003pjs.0 for ; Wed, 06 Jul 2022 14:30:59 -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=c4dSAKn5jp/k9CsN9AS7R6eFx355vzvohbwXypJnW9nVn8nkw/XE//Wk4x3HTHoCEC 6ERfzTCUxmrbbD3SZfs1diEDgb40iYV6LGH1TPgxRU5ULYmtDiLDWeRdiZDgAW3YP6nl I01M79hkouMKSCjK/JrzKuyDrj9X2Bi4YWBx4U31zSqMyKXWCp0oPkBTjPzBNTTbjAH7 TMryKWqiYyRqmnV+Fhrghzx6+Qh8zG7AvptKlcbIThaOo8deHS2jn70z6oVGZ8mhdUmT icW2bRUAwl1OHFeTGsQuWXRwoIbwbDWNLKf7C1u6nISAeSTUh712YAViWpzMge+Nh/SU vu5g== 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=XmLDdiWWhFlHjJHnQ3Rt6wkPcaUzFLwKb4j3hU91gonKOfcRoKNMjBC9enpkfL7mtJ anfhVKW3z562J1XKUNNQHB4DLN/NSdp4feax6pXFQo6TFiY/NDPVvmGBPhRM2K1mST7T ZNZOiX7Vf1wWeiytVkTN4Ks6/7EJVBQK6ijHu9PVGjH1hj2UkgzEUe1twKKvWBv0C6ED Fs3pc0GqTpO8+46j7u3Sh/Usj7Oc+b6z7k8K55NXlyc/NKZfRN8o1HsA42XAWuxMdVOg Q7J8u/27/ECizPFbZqKtuMPSZPxVO1P+9z5YguZFOJ3NGzZNnnR5FG96gvbEXR/z9KPN I+xg== X-Gm-Message-State: AJIora/zcrnq9I982BMXxAVa7qVd54ua0QHSCpaLAeLblovlfGRIHEH3 Yz3e+ozx4t7zmKx4YMepDWKMfq3qZgQ= X-Google-Smtp-Source: AGRyM1th8Gqafdmk6TIG8dzI0UnTR8erReC/HCwRMafrkjNO3Pyx9GChFPuhXjYt0Bsx/uUnM1YIiw== X-Received: by 2002:a17:902:bc45:b0:16b:d5bf:c465 with SMTP id t5-20020a170902bc4500b0016bd5bfc465mr25774765plz.128.1657143058498; Wed, 06 Jul 2022 14:30:58 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:30:58 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 01/14] client: add generic display function for table rows Date: Wed, 6 Jul 2022 14:28:38 -0700 Message-Id: <20220706212851.92685-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 21:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908668 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 3DF3453B8 for ; Wed, 6 Jul 2022 21:31:00 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id o31-20020a17090a0a2200b001ef7bd037bbso11635484pjo.0 for ; Wed, 06 Jul 2022 14:31:00 -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=J3KgOvycmaErIALRO7UT52728btq7OpS7z7yn1nuCUomL1qFYWNryWMpG5VfIEr5pJ PdXAkyMPyRWHNIWRFswIKXj+W4/hIeX5Njta2XarD2EQszkMY+6nNed2F7WdTEOof3zd Qw3CRuNqPbQ3GV/vmzNKGrcBd4wyRrhYJB6F+81lEuy1uMAooyBOab4/5at3IqG1YETB IBZvwScuALdhpP9KLV1PtY6f5kTHKaW5Mh3+ZXoSIPiOntZvbuW+flBIunpOMnG1RU00 4AJ3fT3LsNhPgrTvPmT39FVv8isNj9zOKKCQhXfa3QuF/lMu2z4GOaAYlHRbEmjycZ6I 0/1g== 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=5hliy74yzKJvpyKTc+jr7DE9LGr0scWVn29NRpcBvs5dYkfHvBvJJsA+CJlTB5cLmn elU6vWBxtOeUoNUb/WYo4zR6Au/Yk1Kv90xFsNYp2VqXyfbNc3KJmleimw+2ZzRtgDrW nXCE2n3UaqItWNgDde2uMe3r06KYjw1Ju+qWfFlngIRqQ+eh+x1pWg6X5glruVODWUg8 /mWlCfhiQ+ZAMbsOeEj6dZjVBGEp5GnEyx6q4F83wvMEqjtjhN/EwhW46ikRdpTWSmzu QoMuFnuH5FBaZUG6lHuuv6HipTNZyr1I2Q8lUzP27FiB0uWx/kK5VSzSd55HjCAraBg1 4lKQ== X-Gm-Message-State: AJIora/vGp4lNMNd01XKHkEpLBrTSdG/wO3Jnbe5M/X1jVEOVSgaUycP JmIDS/opRJUr4lz8QogMHvxixfeBpwA= X-Google-Smtp-Source: AGRyM1sn/H6gyGUecBUyyRP5oy4OaQRQP1/Eyoi3zDbLyj+izudyhFzBMcNRGMTH4Rpr3RZpRBUVTw== X-Received: by 2002:a17:90b:1a8c:b0:1ef:c1b2:b2cd with SMTP id ng12-20020a17090b1a8c00b001efc1b2b2cdmr855112pjb.190.1657143059485; Wed, 06 Jul 2022 14:30:59 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:30:59 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 02/14] client: remove newline/tab encoding from help description Date: Wed, 6 Jul 2022 14:28:39 -0700 Message-Id: <20220706212851.92685-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908669 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 5F5F62F21 for ; Wed, 6 Jul 2022 21:31:01 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id fz10so10248324pjb.2 for ; Wed, 06 Jul 2022 14:31:01 -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=bVkDZpGz6VkpEBpG+5b3SHNCmpdu6bD0MtotbmZgslhYAmmS/5WSwjqgquHSjVXBAe qmFYjpNMiPvMVRIEWSLsiwtr9JfRYxBcPIajVj3agZv7Z+PlKRmPM/CeUeWdGecdodz5 6CEUtTtxp1q8vnaghL9KhAqqi95J+tCv1EGVpap06+qbNXf9FnGGa437SJzCyWGbmADq wU+vy5ZWDCVT+ZYbT0vNU8ZdelUV2ijGO1jkLJWnMbL4BeiYcPQMpDDJANpEnQrydyNw 0JtY1+S0e/byI/L2NtzzBusfAiVAJ+8LFGJXVLmjUVJ74aMKyVqWF1c7la0nSl2Wff7J kYNg== 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=ZK7QZyvLWkFcUyhlirlQMIa4iFNrcquBVrxGp3haYtOYjuMukQPLL0JBxdpkQUhYUd fTAAyNee949wzpP6NPGcdeBs5XoyEawL1kSNEBIoZ4gXo0scdp8XzzF8DY3naRl6SFO3 +DO7GVL4yOcIC3KLdZFLW9mKwgCdB8Ro5p5tJ9gzoYigSIzrzbHGBJTExqOYRKQs8kUV aiC20laAlYKC9PPhlGILAeOMrnm1ymJL6r4LRl3OxGE4aHcix2qJjj002wToIVzi6k4q S6W9+JZ+r+OGe5/FwZD85JwAyMosha6+E9uhtTOFnTWh+5Lyy62MHFvXBqt2RKxlTbNN RZRw== X-Gm-Message-State: AJIora+zpWQdtSlfnEJmuBdoS/tcRa5WVswID/hpDrHFHPzePYtNN1W+ YQiBjWejv9yBlYrOwchlYDLQksbsOd8= X-Google-Smtp-Source: AGRyM1tqV462/M0ZXAzhvlfuWrk+cnm7yZ3Mc7b41fboqMJ6BOJYwEXONZmMDD8TULcg6RVQLkn9rA== X-Received: by 2002:a17:903:11c9:b0:16b:8293:c599 with SMTP id q9-20020a17090311c900b0016b8293c599mr48434097plh.136.1657143060408; Wed, 06 Jul 2022 14:31:00 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:30:59 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 03/14] client: update dbus-proxy to use display_table_row Date: Wed, 6 Jul 2022 14:28:40 -0700 Message-Id: <20220706212851.92685-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908670 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.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 A9B4B2F21 for ; Wed, 6 Jul 2022 21:31:02 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id a15so15429772pfv.13 for ; Wed, 06 Jul 2022 14:31:02 -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=LR34VQCkeob/a4YUJDGVF0r88T+Fo3qS7DVLba4OHpnralfblRSXY7uC1Lp8VGa3ml ztyvvKU3Fsp5ob4A9pe8x05HtIb8GkXaPvXLiFMseJ/H8ohiF6DTq0TnevqUbcQjobEM UNpjTUjs+qwC8ir7fjVHzN4UlmYzMPqG6nFzW5L90ZBZiznSfg65ZbI2JLlwjIErAOIy rLsWh9ey3+AerjmN/N26zyS2GoJprG7jcxEclYbZ+scEA8RLLshE8wdg2yeMxfEMnEys fvnkbj/4iEBehTexCWsBIsvsVFYZ66VTH83qZJBgZ1gqHJTl0iDDoELKqaoot+jx2Ard fHGA== 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=muqivwPzXOWQPujakIs1jW27dDwCW0oVTX1UsYVt0UvRboNUMzEu2XoQwJ3+J/2kRz U4GNeA2AAJdmrrJCJrOtR2d8XJeB2/ofhCYsQguyU2HrtAWGYRw/rYYsR8+GnLkUuZxf tcfzumvyd9nEXDh/nPk9YFeGctd1tmSHLrpWjOboDafyUGOEw3wLCEvpy8v2+NRmm23S 13HU39cOUoYueA+WSPlfvs6UU30UgCpyXNU7gDai9suuZJ04gtv13jOUROGY5CLiu6o8 0dX/8mLNOM/SEk25LIn11MgXnkIiPbU2hSUMBMTMAFXewL5gZkK/BwJLZwkc+UoQaTu+ Em3Q== X-Gm-Message-State: AJIora/b8I++LxScyNgErWE+/3gWMs+jkeEkj9foRXOBmkLpsO+Tg581 pnlT3qSAJw1M1781Pc/kZZbQiHCpWrA= X-Google-Smtp-Source: AGRyM1t2puIZBGq98YTFrGUJswsZTVU/sfYqOMZHjmqP0ZF3MAclmcw1XjEhEMOYvaefY4qeFkRXPg== X-Received: by 2002:a05:6a00:2387:b0:525:7314:7cf with SMTP id f7-20020a056a00238700b00525731407cfmr49907514pfc.84.1657143061830; Wed, 06 Jul 2022 14:31:01 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:01 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 04/14] client: update station to use display_table_row Date: Wed, 6 Jul 2022 14:28:41 -0700 Message-Id: <20220706212851.92685-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908671 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.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 AEC3453BA for ; Wed, 6 Jul 2022 21:31:03 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id n10so14732578plp.0 for ; Wed, 06 Jul 2022 14:31:03 -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=QWqcP/5pkcVmFhqZpGKQiEMk3MJvzSGb5WC05VOZfh/NUv58kEo4X8OuDGyd45iG6u 1OWSl74ep/gumpUzb8wxcGU59XItXEAvJpDfl7WooKTLdxas2RjlhdC4TKwtgNqaL7d8 Od0w+hoL5q39vBFoYnnZBPCafrcyykrmcJh+F3B3R9qnSMGzlz+1xhqwMJVmQlxHtXCB nMK93azQHv82HZOw4J7M6qEIg3bhaU9Mwh7eWp3m4IXVUChDIzcp/GvmDW6aihhklfaB dmWlFibU5F3D1nXQnOBonLvBpdwb7F6+88Y/wl6mRUdj7/Zlq9obt2hWgX4hyxJG1Rp1 4o4Q== 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=4fwzzG3DZsdkw2AzWWJpU9hpFMAEO7PaNjUC5p1Ipmq+qr8e7Arr73AAlrS34VcCvE ZwFbiiXG9W0QOCB+WSrv2YqroRfKo6aPOWX/YaicE5vfMQhf9odC5I2T5xi7BsTggF7g 0jpm+JBob/g6ywVjvdaEu+t8jJuhq4hl7yHo/ssoosXW/uY703JVnI/XoiHr2CTZYGtZ tw0AX8UuKWfMzSQ8bhrXDFnlOk5Bc/BGNN3qSIs8y+BmbrpN/n0WgWtw6Vw9uBbMxO7o Fns8mmeYrvi8IUkAbD0BaBghHsgKtJ0kBa2U9oLY0zZa0I3eKKw83JiS9CbtnPUFowNW OWXw== X-Gm-Message-State: AJIora8LHkPCkZ+5buXANsYpW71KwZ9O+9ZCLuRy1jv8yJbjTGI6m3un sqWS0NOGDjQuHCu+VVTFzwoB2gCyUy8= X-Google-Smtp-Source: AGRyM1uudDvDrNEeKATIVUoh9rjjfaZURFXKFTrqQQ+rkZYA2bZkV0UpYbLZVZL6LCDxnmU1TBcX7g== X-Received: by 2002:a17:90a:8916:b0:1ef:79be:c9a9 with SMTP id u22-20020a17090a891600b001ef79bec9a9mr913445pjn.28.1657143062786; Wed, 06 Jul 2022 14:31:02 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:02 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 05/14] client: dpp: display table footer and set to auto update Date: Wed, 6 Jul 2022 14:28:42 -0700 Message-Id: <20220706212851.92685-5-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908672 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 E6DB62F21 for ; Wed, 6 Jul 2022 21:31:04 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id g126so1034646pfb.3 for ; Wed, 06 Jul 2022 14:31:04 -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=GASr2I7+arOaNehQb6vH6lnXGNgAxWmUN0+6ym1VY1imG4eZrRjtnuUgk5grYIG4XU 7vn2Kd6XtymwUljaIxwgYUU+VTtBdrGoLuwQkDaTerNvK72a2kfgMMqorjrVdqG7M8cO Uassp1QFrCDekY+1z9Tv7lUfldbTwBso1znobY65GUFzM+7Kjh25bbYOc13z9QQXqUx4 5KXdYAV8VqSoUB8PV+St5afYcUKb3roboNY3eTye8gHGLrw/jFKP7oYUvDCU9SvYVD0x huoqThTvlklP49TtUi5zmWmv5c+5Bh0RGf9xW9eqvfBl4RA1eCmNC167nhNGXbA0wMeq +3HA== 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=AOGcqUNsgxhunS5clFTYBRT80AYysCXBcvUx966LOYO22r4bWF9gRLAa+FWP/l91OY GxYvmCnsqOQF0vZfkef4qtj+5zpK+MjRjASD8hDMsG1R5KYSRWKQmta4m95oBUtvf7OM vjq+ya7+lCtio9KarX6OMIOw7az9p7KGhKdCWsH2P6ONr4HX/ZLSeSYDJMgQ7xGc8ov3 Dxd+GAys+wI9CwsCIjJTsEd3osI6+/N8JZIIX5UdTWPIKcL3DwSlOgKlyDFVrDswGV+e Y+7I3FhOKqOnzSxBIiwgY43ZoZqZPewxydMkXGsg7IS9VUq10a24S9nBFe3i2n6A+kzO F6WQ== X-Gm-Message-State: AJIora9z2KJ49ZO40sRc4qdO6WXBrgB3vJSiQZ2rTKPfKcIcCQKPJgK3 k3nllGPhsm6IpZVcs7EHZrXxuY3mI7E= X-Google-Smtp-Source: AGRyM1sOkJaBl05H9wg8c+VdB+wBgmf7YT717ADAYQNg04+YTN9AmnsWwBmpfQlSxluh8J4amut42Q== X-Received: by 2002:a63:8341:0:b0:412:a34a:b9d3 with SMTP id h62-20020a638341000000b00412a34ab9d3mr3504829pge.437.1657143064205; Wed, 06 Jul 2022 14:31:04 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:03 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 06/14] client: check NULL return for DPP cmd_show Date: Wed, 6 Jul 2022 14:28:43 -0700 Message-Id: <20220706212851.92685-6-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908673 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 4072D2F21 for ; Wed, 6 Jul 2022 21:31:06 +0000 (UTC) Received: by mail-pl1-f178.google.com with SMTP id p9so4548051plr.11 for ; Wed, 06 Jul 2022 14:31:06 -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=hn3kSewZ6UF1o6hRDnnV/8T0ZlOjb8BTdFmOqcJgfeAzvSrIhBv3fem8jVcL6kHZeM 2AtZqZBZ1j2NXwlhv2E0IPxzKd2gi5k+UxeZDGsijMMMd7AQzhQb7zow9uiNcN3fIQp5 cKR9U+6IGJm1C8s5blNtIIRvKNxnPsKPeaRFjpKv1toIebdH2ulN+aQcigJac3kmJK+8 Wn6dbWFZyh2Tk0wrU6JjM2Cor9CZy0KkipY21ZwvC5xNBwQTUzSbnAI3maUDpwTKTFYG fpLGp1aIUV5P8JZ3oxQJXQ/dJX8arlRwv3D4bOy8o4lp8Mv5H9IRZha+XTWzS1i8N+O5 YAzw== 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=7tHNDI6PoDuLMg3cQHFYuOclc4bHTHZHXVdS/+Bx5C306cg+ApyMp2c5mAumMXgrY8 CoX7rOvZcj4wU1EKq+Cwd2FL8xTY8OqJeJRF3NNsTkccLOvho8Ng4xuYdcR7P9C8EvEi 3DV8pCIeiUG2DOQN4OzxK1uA2DOepCLIZkY9nh1TjX4Ad7hUtPCUddZMZyUS4RMlKrvD m0+9UUiB1I/4dtjk+nhi2nC1XMoRu5hZvdhTgCFUM8LVxbV9Er/OwT4Ak5r6N73zubYm XrR82aKERfAa/84VwXWI3CF8ZLwEJRAlN+ELgmGlXdxIfhjAVHWMOMR1lMS5B67gkxbM Y5DQ== X-Gm-Message-State: AJIora8/x9xLiArhQjm8vVjxS1Fwpl2c/8I1YuSfr3Yz5Ba3cr/TIlri FeQpDn696RJ5rVTuKBqztZgM+whrag4= X-Google-Smtp-Source: AGRyM1vpeQvjTo53JsaX4gWVW+beC65gwtYJL/0YYR9J7h+aDANWsxkk1WUlwfXtNDiqug4oK4kF1A== X-Received: by 2002:a17:90a:e7c1:b0:1ed:3b8c:7ced with SMTP id kb1-20020a17090ae7c100b001ed3b8c7cedmr854904pjb.77.1657143065455; Wed, 06 Jul 2022 14:31:05 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:05 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 07/14] client: update CLEAR_SCREEN to be consistent with others Date: Wed, 6 Jul 2022 14:28:44 -0700 Message-Id: <20220706212851.92685-7-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908674 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.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 2E1AE6648 for ; Wed, 6 Jul 2022 21:31:07 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id n10so14732702plp.0 for ; Wed, 06 Jul 2022 14:31:07 -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=hJLQuEF3DVoIzYjOGeBKkYnuVyszwHiXzsA7DBahNIULDCAEEN0mLpZUNVks2vWSAu li0cCoHdcEkQx8VaLMRCzrt6TuJKmL6q2E9ayYrAyfAJNWpKgLS3/xsKockSYfOG1y4C GEjqk4tPiBeBdGNszV6dTUMcl0Lr7Oaz0/baTjAQl6hXSS1d1xWsZAfX3ZbeUoY8nddz WJeId2H8rT/GFVWa7lPHBFEe/qn07w2UUwwIEhs6NGmxuNjNpKbB94qfAZN3pTTrDeuu 1johSFfsmUQZGEnfFmmNr9+dPxtWGFcLjvFUcbl/pBBdnuQzL8p1YIvuX3I4Ue52tfIG AlYg== 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=cwkNAtXZH+rxL+kjWTxXsqU8xHVHD85XxeAMnzRijeT/ObaAclWN+hXjRYZ85gxj3Q M/UMCaK2+KggY2cC7SdBEBODdq0zgg9Z6o2aLB1shmigTXXgQ2/egvZrZJTa+kj6GsBZ Ion3ai+NyNhR7oE58n+jbbMPm/1m4xEqWiH4pZWndrf89stpLN+LNiO9ZjW0cPlQQYXc GRdu8mHeMDf8L3H8Jc141IYuvCOBSgAFbhOAH+bjh2Sqa8tnTOpf2XXz79n5kidxMf6b KoofKyEnbfEayjFPpown/19cJ+d7kC5dSg3yIrw8y2pmXjoP84mkRENKFb47uRiye6pJ KnNA== X-Gm-Message-State: AJIora8TqxM3i6xR1dbKoc1J/D6I/4AYrv4lUdDIRzQ31aJWyIrVIVvh pF2gcH50mVl2OEOrvcr3UdHDz/4eq20= X-Google-Smtp-Source: AGRyM1tw0Ox/wfs6mIfjwaa4FirhUzM35lgZS7MaAiAGJMXLE7qoEK7S4YkgQkQHCCsEs/GnfdEhjA== X-Received: by 2002:a17:902:b598:b0:168:b0b2:f05a with SMTP id a24-20020a170902b59800b00168b0b2f05amr49416170pls.0.1657143066527; Wed, 06 Jul 2022 14:31:06 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:06 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 08/14] client: make COLOR_* macros take a string input Date: Wed, 6 Jul 2022 14:28:45 -0700 Message-Id: <20220706212851.92685-8-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908675 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 4F9B32F21 for ; Wed, 6 Jul 2022 21:31:08 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id 70so359673pfx.1 for ; Wed, 06 Jul 2022 14:31:08 -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=iq22vUNPzzTKm6ZCaF0EBv4iOtV6HylvKXEDBEPrz0k=; b=jiFWIOVfUJvEFlpDflBruNK8+3jp/wjY80KWiv8he16MsKCVFEJZM3ZT3Oi/kI19jY srx4m02kfKbger55V77+QdvHX/DaaKcdoxiFegPanV1cJUU+Ixey1wwYPs811xvpjA4j UrcFCS1WU026S73o/Uf+wJ8WzFwl4w9iP3buLOEvnmPvs0Dsxu32O2RcezEyxzxC82Kw OfTCOv66AyDcl0G9VX5SbXdR3jr9U4hC4SsW3gOcWShtmjVGZWWefELyezUbU2g/wn/c hZnfDCovqGXC+64aObvgNPUUsL0BWZAZZFoeEroseTY6IgLgn8psQeyz4DV0arRh1avW RkBA== 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=iq22vUNPzzTKm6ZCaF0EBv4iOtV6HylvKXEDBEPrz0k=; b=wnvKV1WyEvgadk3npclHTVQK1GOrzyqCRH65x+60P7E91eezx0GTKNyD2QA7UX0OVJ enHZUwxmepHL/DZnpBriLYpccEY9xBLyir9sZF+5c0bYJc2UoikF2VmzCAgirH0CiZz4 HVD1NqiFX/oubbQEjPj92BNpLhFApUtDo0PQBYyhJdE3nWSCce34LFwRmsFWx2UsJuEb jKbT8so3ApXd15nt5wuMc6UxviZEWJqOGUPHhddzQ61UmQnakn/P5wyZZn9F/HUMI8TR HvpIR8rHpBk0o5eTd+QaH5ZyzFK62bcox6/taB2VoUVi/dXNp2BbXghY98KiCGOm606M Lyuw== X-Gm-Message-State: AJIora8IUT59oCpSvx/pF1rhUn/cLjDLexRXabFouuj0mERINPPgtKkD WDBVbBxv885dcwI5UBuaC8yGVUrZ4C0= X-Google-Smtp-Source: AGRyM1vzant/pkKuyIHDML4fifnTII0DVkjUqPkxif928cttlueCT0cJnpflMqQlXKWA6SZPtw6fOg== X-Received: by 2002:aa7:90ce:0:b0:528:90a4:73ec with SMTP id k14-20020aa790ce000000b0052890a473ecmr12550645pfk.73.1657143067505; Wed, 06 Jul 2022 14:31:07 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:07 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 09/14] client: update ap to use display_table_row Date: Wed, 6 Jul 2022 14:28:46 -0700 Message-Id: <20220706212851.92685-9-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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..37a15fc3 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[6]; + 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 21:28:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908676 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 99DE82F21 for ; Wed, 6 Jul 2022 21:31:09 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id j12so7899349plj.8 for ; Wed, 06 Jul 2022 14:31:09 -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=d03MitxuaeItEvsZvX2wo4NYid4MonT7X1zFXpAa/4Q3RqsChaFe+P50qcPAkTOM1z ke3sCp9CP7KQE/IeYCO0iitIM5oQOxQOCb3YC1I4ygW/I1/04qsE3NPSaoFgEG4th2Ii Wx6V1rYP2WEbpWpmODHJYwwxm+bbmnZr6HCsB0lYVc1IVnihYIhRe2/jBztVNzckGIYb SRq3fGlSGoqANIB+y/LmZEFfa0e8UpaomAL+zGvU/7rHL6EN5ywWmKF7OusnLTbwiSZm 7rzzCXYXIHbXAJ+UlB452gnO++jyu0Hwcaow4rAoNspu0N0K+wR2WJsynMCdL64EN9s0 cVrQ== 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=FwtfEvTTUNCysEy9psZqty07RlJReTpEokSPMLqIsNX7W2S+fOXWHRjh/i5jE3JX8V BSbyFOYtsO2RgCEG6nvZFyuN2X/6Q/CGLDvaAj80+2EJWB9BoPsY75wY8Md5+An1als8 IJydJaq9iKHMe9Txg1tkDgBrfVSfWCrA4ohcgS27fgxsKwgPzOxDc5oOWyUuduFjHB6J wr6hwl8UXg/ltJ3MuOfvJ1JaiN1FilRZsnDniRzVyq3w3st5YV1dksh4FbTfs3FGyo8f Ro96ah1dZDB4LTE2cLlRclz/g+3mIWlySU7fLrl3gUlATBGtauV2ZzDSVmEmyi+eXMfA p8fw== X-Gm-Message-State: AJIora8N6m6iezlzasSpHEFA6k3JpNg3cgWEfSJCmQAvjKC44a3l3XKY iHu9x/f19R14TZLD3iiZL7n7LzUCgrk= X-Google-Smtp-Source: AGRyM1tJLUqm7icLWinVxyHoo6SjJOQpfah3mmRJs0bdRJwCrXAnGTskQ2M2X0IJAFYrp766mzKWHw== X-Received: by 2002:a17:90b:1b10:b0:1ed:44:d00d with SMTP id nu16-20020a17090b1b1000b001ed0044d00dmr863126pjb.234.1657143068785; Wed, 06 Jul 2022 14:31:08 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:08 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 10/14] client: update known-networks to use display_table_row Date: Wed, 6 Jul 2022 14:28:47 -0700 Message-Id: <20220706212851.92685-10-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908679 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 6DBB653BA for ; Wed, 6 Jul 2022 21:31:10 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id o31-20020a17090a0a2200b001ef7bd037bbso11635878pjo.0 for ; Wed, 06 Jul 2022 14:31:10 -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=kCM38qZ8y0kNhnHaUHJ8jz79GrHgXjgeKoI3n35f2CQEJ9q7zW5rVXO0h3MUYP6q9A lfZ2uFl7vk/K7gCw2z9QA9T58NIIZauqStYbn8I1vf+VPEkCcdb8SSls50ykdpj1qES0 eJzMy/X4RPoppFf9tNDHhdqBt+URfWwGTeKMtsYa4Aq2Ixl+1dAg2Z/h/IlGs5klnd/E ca+0SlU03VRWocsPHZ78+HlcItxQX7QcKdnc9gf+d90c36MOvGw1BlsjlRxx65HbtHXR ZsX04TnqZX6XhZ8gCuE+I/0GA5B22tdxdmYBQJBHYvUFP1EgsbvOYADX5XIL89/sbn1C xQ6Q== 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=4WPt4C4288Zn0HipIn7IL89TyYrShyfTBKNTD53CMvSWgiuNKnlrs56nNVZuAJEYE9 XPShTuSNy5gemgQMMgWC3yF2EyzP+w+Bn3P8xZABaEuI3XaUDbyAAYehy+gdVEaiHwGs dJNeyGSeR8LJ0GyN4vwUBhlU9qjTc44NDdcs/Y3RugXq/36OV3HYCk0MFTbxyi0UGF+i XdWTy1I7Rb/gE2s4zoHVpN+qMc/kcaGn9KVkk7KYXFLknKEqiX9mx/pyUnx8R4hcxe98 mz/KUeYweWfpQl2OfxVnwuqcccF1PV8xQAhb3HTvlvfEimBroanedSAIoXYS7N8fQTVx hBXA== X-Gm-Message-State: AJIora+7Rz/8AXmnikWtk9FNlaJQbAe4S7B2Lja0HLBa2lWcMI5Wd8gD r+A7Hs/0QYfp+tBk4rHUIBjUArjli6U= X-Google-Smtp-Source: AGRyM1ur8KwEFWErTC9V1oInBJZH5K+3OusyDsybBckChMUqPH3geDfEsr4egMKlxZFbKtWCePt91A== X-Received: by 2002:a17:90a:9a8e:b0:1ef:7c8f:4522 with SMTP id e14-20020a17090a9a8e00b001ef7c8f4522mr828392pjp.151.1657143069716; Wed, 06 Jul 2022 14:31:09 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:09 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 11/14] client: update command table header Date: Wed, 6 Jul 2022 14:28:48 -0700 Message-Id: <20220706212851.92685-11-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908677 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 995E86648 for ; Wed, 6 Jul 2022 21:31:11 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id o18so13809801pgu.9 for ; Wed, 06 Jul 2022 14:31:11 -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=iuWU7N6AnrKXkwxutZYkPsVehOOkiEjyf7wPo+ppOEv+UDJ9oIir1S6zyL9BEXJjND OrA7L702fCkqUtWht13q18ijt/0QO2Qy8ltIR6khuAsN5S8Sqko9bFOTwOqnbzxqO9ru BQ0tjd2+fpxFGhw/8XXGO5aBC3wXSIUFDA4DKlle93Y6boFKx7Amw52v3DhtA4ycUhGe b0hfzpBIM8A0+HjTlPoSlfV99mFUIxgjBAFyOG/pnrulcNLhKyvzEZ7Rs5Xv5Vk3qhtV g9zfemtMdG5OsikF/Uvv+zn7HbXyHTd5Rftlo5vxaFgbK370/Ya9s5q8oWTjGp7zwpQz UD6A== 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=utkw21zjYN8wf+FfD4Jwv+MNKAly7463BsYfbC176iWeCNjYNq+5Bn8mqRxkpe9Exv fx7V81S0lvqWIxWCG9wdeY3EbBK/F+2SMGafR2AdcSNv4MU6LUf1716UT9VKpRjS8U9I 2v/Uj9tX6hELKQ5pkFDr3zfHR008tsEFMMprdXNEEW5Wg8wa6WhKw5oWDXRk8qPThzaJ K2d+L2rrljtTwbTc0rQabUcPHOizFQgZOUDNZVzMz+5EBwWyHIpKcPrrT5OIComEhyTq Iu8N4QAjxwD1Qcjo0K4Yy7qf2ATyCDQVTL6tqiWGly04KpKvpnr6WEexurtrYZVbJtGF tRcA== X-Gm-Message-State: AJIora/YOG4UJSc+ylx+a2IWFRSEUvjpAVqeVnZafaXOLOfemTVgyGmk zotzC9ACSVe+d1F7XR2Nsxq5DZI90Mk= X-Google-Smtp-Source: AGRyM1vCQznJvojDyUmf1AoOW8XsUYsZvjq567ZLl+MEe+K2IlYiUlemis1OWXgrGsJ1Dndk+fuf+g== X-Received: by 2002:a05:6a00:18a7:b0:51b:c63f:1989 with SMTP id x39-20020a056a0018a700b0051bc63f1989mr49647933pfh.49.1657143070822; Wed, 06 Jul 2022 14:31:10 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:10 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 12/14] client: update device to use display_table_row Date: Wed, 6 Jul 2022 14:28:49 -0700 Message-Id: <20220706212851.92685-12-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908678 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.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 859C16651 for ; Wed, 6 Jul 2022 21:31:12 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id z1so8899588plb.1 for ; Wed, 06 Jul 2022 14:31:12 -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=bgEUd2cswzSMAEiJh+qfMPA5JaAlnyJanNvsLMuM67Y0r/7TB29fROxxvE6z4gV6Ky XHS3gmmJB3pc8/AuKtg0/Pc/XSMoejixLhC93Rc0Q9dG2UIkazMMfcuN3qhnAwsS2gE4 CzVIUAsh69fX9HrZ7G6/neRGSBBm7DeDOwLFT9QYguyRqrwSYsLVRp7FfNQKIjihUXfR 7yTXfV++rdCsTPKzXhoSJN6Unw9DCY1UMdVwbga7jh85Be1to65nlzCsAJbGHioMVld+ ZALrEItQsygIj0cH6aAxW2MAGeLvUVlBzoYiu4ZJ7mbRbnjJxmMZ34KuDeWnnfYK+mqu jtuw== 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=zPIsP32TO0hFs0FdcONP4JF3p7HFQIh/td7pwSW9A6U6ifEJh5BCKkp/wTpHYT8lI1 6AUfVNdGmrObbwnQGSPkuJeOmU5jPSef2BRJ8hCwZ3GSNCXV4m8QXyCW72ttybfD73nY aIDxFalyv6qaqmKUzOEL7esVQDzitaaCg31kZlc1rpXrokwjKqqXF4uxdnxyzR+k0fxS kBOIF/lisP3OB3JP5OD/ISZJyWETX+HV9ObV5dKI9IVnnK002HHxjBjzfBeOl9Ee3+0N l9k/l6+a1lYN9+yyZb4Mi9WoiWeaeFSIWhfsudLKUBszz0nW5Kl/fZza0c2+1uPmKGlk vg/Q== X-Gm-Message-State: AJIora9y3DGaVRhkHFDVeomTZ6dQSazqVQGO6ylDLWR2BN7V7k76pf8r Sw0cwf5F4DWiy7zPyt2EIUF9dOa6fcY= X-Google-Smtp-Source: AGRyM1uFM0eX8EzwUchIFzZBpm7QEo8dFv2RSrzMVwxdzmbR147M4pP/SeN2iFRyf0o/zWzKemTMPA== X-Received: by 2002:a17:90b:3e85:b0:1ed:5a12:513c with SMTP id rj5-20020a17090b3e8500b001ed5a12513cmr866642pjb.64.1657143071743; Wed, 06 Jul 2022 14:31:11 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:11 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 13/14] client: update adapter table header Date: Wed, 6 Jul 2022 14:28:50 -0700 Message-Id: <20220706212851.92685-13-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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 21:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12908680 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.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 90F156648 for ; Wed, 6 Jul 2022 21:31:13 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id y18so6678691plb.2 for ; Wed, 06 Jul 2022 14:31:13 -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=DL0ZmfvMKAZQIvdbl24SAIxaLpzkjnXrvGbNnJHvIR8jgRx9L92qjRJTOaVd47nTkr g4Kh1aWrrORX5YEKoYOMWjyrfLqOEjweBUc5LhrbEeSWEQjeJI4tco2wQiEVxTfMNJpG /R4iIIXa2wfS5qHMhdKFJTlwGUFG9EYJhTqgm7c3F/A8YADxs6F1Aw8p3nJG6rQWduMr 7wkZWSn16U7AGOQ5Q9rozeTnco0vQt/rt3UPjrau4AGKyByosv3cIPHPZXV7MHywqkMC pXjkhxF1pD02UUhUB6UQrtxGOaInvGrdeUqxOFNjmPtHSYCbbgjaBB8uxHGn4hLGgmzJ JbDg== 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=1Nj3S9G2/NYIpL6QpqBgvVQEheJ+JYhtg8Y5MoZI3FhrkBfo7QcAd0oi//ODktBjVB w7OzT3Bq1bebHL8E/psCXp7lfzdvOywlyKWZje6JgrXA5ODt87FD+3WIoED9vQDCcrTQ /2GcWXkajb1ayFhvz3+/BRXLUAA69gt5kBDSI5PSzaNbzmCdqB+kNI7cZ+l2FVCahh5p Armb6ZW/Y5hzq/a3OO82kOHFsyzxZ/weZQeot/Yp7sLGUdt2EWaRzwsqhGeYEm2cFbil qH99CSZukzhTBLh+8ooXLAlLF453J6THE5xcWRBcXkSAU+g79Kln2VxZPZ5+ne30jVES jOGA== X-Gm-Message-State: AJIora/pEpdB78W0W80iHzDBg3hzfDgzXpXeXLJh5f3BW2S6gyZL+kOq V7+HQXQoziVjDggqOQqh8HxUd/AFjds= X-Google-Smtp-Source: AGRyM1uRC4iJT+psddy9XksWWcfse6azy6Clo41yXDykDw4+yZaxK6vW9sG3dypbuCDZRanUARVbEg== X-Received: by 2002:a17:903:2d1:b0:168:e83e:dab0 with SMTP id s17-20020a17090302d100b00168e83edab0mr47834480plk.118.1657143072771; Wed, 06 Jul 2022 14:31:12 -0700 (PDT) Received: from localhost.localdomain ([50.45.187.22]) by smtp.gmail.com with ESMTPSA id v6-20020aa799c6000000b00527f5aee1a4sm15347609pfi.33.2022.07.06.14.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 14:31:12 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 14/14] client: update ad-hoc table header Date: Wed, 6 Jul 2022 14:28:51 -0700 Message-Id: <20220706212851.92685-14-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706212851.92685-1-prestwoj@gmail.com> References: <20220706212851.92685-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) {