lkml.org 
[lkml]   [2022]   [Nov]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH v1 2/4] perf list: Support newlines in wordwrap
From
Rather than a newline starting from column 0, record a newline was
seen and then add the newline and space before the next word.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-list.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 0450fbfd0a5c..43c635d58627 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -73,17 +73,19 @@ static void wordwrap(const char *s, int start, int max, int corr)
{
int column = start;
int n;
+ bool saw_newline = false;

while (*s) {
- int wlen = strcspn(s, " \t");
+ int wlen = strcspn(s, " \t\n");

- if (column + wlen >= max && column > start) {
+ if ((column + wlen >= max && column > start) || saw_newline) {
printf("\n%*s", start, "");
column = start + corr;
}
n = printf("%s%.*s", column > start ? " " : "", wlen, s);
if (n <= 0)
break;
+ saw_newline = s[wlen] == '\n';
s += wlen;
column += n;
s = skip_spaces(s);
@@ -145,7 +147,7 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
wordwrap(desc, 8, pager_get_columns(), 0);
printf("]\n");
}
-
+ long_desc = long_desc ?: desc;
if (long_desc && print_state->long_desc) {
printf("%*s", 8, "[");
wordwrap(long_desc, 8, pager_get_columns(), 0);
@@ -153,7 +155,8 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
}

if (print_state->detailed && encoding_desc) {
- printf("%*s%s", 8, "", encoding_desc);
+ printf("%*s", 8, "");
+ wordwrap(encoding_desc, 8, pager_get_columns(), 0);
if (metric_name)
printf(" MetricName: %s", metric_name);
if (metric_expr)
--
2.38.1.431.g37b22c650d-goog
\
 
 \ /
  Last update: 2022-11-16 08:14    [W:0.051 / U:0.248 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site