From: Daniel Schulte <trilader@schroedingers-bit.net>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, stephen@networkplumber.org,
Daniel Schulte <trilader@schroedingers-bit.net>
Subject: [PATCH netdev-next v2] ss: Remove trailing whitespace when output is not a TTY
Date: Wed, 25 Feb 2026 20:39:03 +0100 [thread overview]
Message-ID: <20260225194104.3182640-1-trilader@schroedingers-bit.net> (raw)
In-Reply-To: <20260225102331.6d09b8b9@phoenix.local>
Sometimes a value in the last column might be very long.
When grepping ss output the matched lines are also padded to the longest value.
In some cases this can result in multiple lines of the terminal getting filled
with spaces.
Don't print right padding in last visible column when ss can't determine the
screen width.
Signed-off-by: Daniel Schulte <trilader@schroedingers-bit.net>
---
Resubmitting as v2 using git send-email.
---
misc/ss.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index b3566f6b..2cd6b470 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1211,7 +1211,7 @@ static int render_screen_width(void)
* aligned across lines. Available screen space is equally spread between fields
* as additional spacing.
*/
-static void render_calc_width(void)
+static bool render_calc_width(void)
{
int screen_width, first, len = 0, linecols = 0;
struct column *c, *eol = columns - 1;
@@ -1245,7 +1245,7 @@ static void render_calc_width(void)
if (compact_output) {
/* Compact output, skip extending columns. */
- return;
+ return compact_output;
}
/* Second pass: find out newlines and distribute available spacing */
@@ -1304,6 +1304,7 @@ newline:
len = 0;
linecols = 0;
}
+ return compact_output;
}
/* Render buffered output with spacing and delimiters, then free up buffers */
@@ -1311,7 +1312,8 @@ static void render(void)
{
struct buf_token *token;
int printed, line_started = 0;
- struct column *f;
+ struct column *f, *last_visible_column = 0;
+ bool compact_output = false;
if (!buffer.head)
return;
@@ -1321,11 +1323,18 @@ static void render(void)
/* Ensure end alignment of last token, it wasn't necessarily flushed */
buffer.tail->end += buffer.cur->len % 2;
- render_calc_width();
+ compact_output = render_calc_width();
/* Rewind and replay */
buffer.tail = buffer.head;
+ f = columns;
+ while (!field_is_last(f)) {
+ if (!f->disabled)
+ last_visible_column = f;
+ f++;
+ }
+
f = columns;
while (!f->width)
f++;
@@ -1340,7 +1349,8 @@ static void render(void)
/* Print field content from token data with spacing */
printed += print_left_spacing(f, token->len, printed);
printed += fwrite(token->data, 1, token->len, stdout);
- print_right_spacing(f, printed);
+ if (!compact_output || f != last_visible_column)
+ print_right_spacing(f, printed);
/* Go to next non-empty field, deal with end-of-line */
do {
--
2.53.0
next prev parent reply other threads:[~2026-02-25 19:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-18 21:19 [PATCH iproute2-next] ss: Remove trailing whitespace when output is not a TTY Daniel Schulte
2026-02-25 18:23 ` Stephen Hemminger
2026-02-25 19:39 ` Daniel Schulte [this message]
2026-02-28 1:10 ` [PATCH netdev-next v2] " patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260225194104.3182640-1-trilader@schroedingers-bit.net \
--to=trilader@schroedingers-bit.net \
--cc=dsahern@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox