From: Jacob Stopak <jacob@initialcommit.io>
To: git@vger.kernel.org
Cc: Jacob Stopak <jacob@initialcommit.io>
Subject: [RFC PATCH 5/5] add: set unique color for -t, --table arrows
Date: Fri, 20 Oct 2023 11:39:47 -0700 [thread overview]
Message-ID: <20231020183947.463882-6-jacob@initialcommit.io> (raw)
In-Reply-To: <20231020183947.463882-1-jacob@initialcommit.io>
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
---
table.c | 62 +++++++++++++++++++++++++++++++----------------------
wt-status.c | 1 +
wt-status.h | 1 +
3 files changed, 38 insertions(+), 26 deletions(-)
diff --git a/table.c b/table.c
index a6fc660fec..390b2e2dd9 100644
--- a/table.c
+++ b/table.c
@@ -5,6 +5,7 @@
#include "wt-status.h"
#include "config.h"
#include "string-list.h"
+#include "color.h"
#include "sys/ioctl.h"
static const char *color(int slot, struct wt_status *s)
@@ -65,52 +66,51 @@ static void build_table_entry(struct strbuf *buf, char *entry, int cols)
strbuf_addchars(buf, ' ', (cols / 3 - len - 1) / 2);
}
-static void add_arrow_to_entry(struct strbuf *buf, int add_after_entry)
+static void build_arrow(struct strbuf *buf, struct strbuf* arrow, int add_after_entry)
{
struct strbuf empty = STRBUF_INIT;
struct strbuf trimmed = STRBUF_INIT;
- struct strbuf holder = STRBUF_INIT;
int len = strlen(buf->buf);
+ strbuf_reset(arrow);
strbuf_addstr(&trimmed, buf->buf);
strbuf_trim(&trimmed);
if (!strbuf_cmp(&trimmed, &empty) && !add_after_entry) {
strbuf_reset(buf);
- strbuf_addchars(buf, '-', len + 1);
+ strbuf_addchars(arrow, '-', len + 1);
} else if (add_after_entry) {
strbuf_rtrim(buf);
- strbuf_addchars(buf, ' ', 1);
- strbuf_addchars(buf, '-', len - strlen(buf->buf) + 1);
+ strbuf_addchars(arrow, ' ', 1);
+ strbuf_addchars(arrow, '-', len - strlen(buf->buf) + 1);
} else if (!add_after_entry) {
strbuf_ltrim(buf);
- strbuf_addchars(&holder, '-', len - strlen(buf->buf) - 2);
- strbuf_addchars(&holder, '>', 1);
- strbuf_addchars(&holder, ' ', 1);
- strbuf_addstr(&holder, buf->buf);
- strbuf_reset(buf);
- strbuf_addstr(buf, holder.buf);
+ strbuf_addchars(arrow, '-', len - strlen(buf->buf) - 3);
+ strbuf_addchars(arrow, '>', 1);
+ strbuf_addchars(arrow, ' ', 1);
}
}
-static void print_table_body_line(struct strbuf *buf1, struct strbuf *buf2, struct strbuf *buf3, struct wt_status *s, int hide_pipe)
+static void print_table_body_line(struct strbuf *buf1, struct strbuf *buf2, struct strbuf *buf3, struct strbuf *arrow1, struct strbuf *arrow2, struct strbuf *arrow3, struct wt_status *s, int hide_pipe)
{
printf(_("|"));
color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", buf1->buf);
+ if (strlen(arrow1->buf) > 0)
+ color_fprintf(s->fp, color(WT_STATUS_ARROW, s), "%s", arrow1->buf);
if (hide_pipe != 1 && hide_pipe != 3)
printf(_("|"));
color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%s", buf2->buf);
+ if (strlen(arrow2->buf) > 0)
+ color_fprintf(s->fp, color(WT_STATUS_ARROW, s), "%s", arrow2->buf);
if (hide_pipe != 2 && hide_pipe != 3)
printf(_("|"));
+ if (strlen(arrow3->buf) > 0) {
+ color_fprintf(s->fp, color(WT_STATUS_ARROW, s), "%s", arrow3->buf);
+ }
color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%s", buf3->buf);
printf(_("|\n"));
}
-static void print_table_body_line_(struct strbuf *buf1, struct strbuf *buf2, struct strbuf *buf3, struct wt_status *s)
-{
- print_table_body_line(buf1, buf2, buf3, s, 0);
-}
-
void build_and_draw_status_table(struct wt_status *s, int advice)
{
struct winsize w;
@@ -119,6 +119,9 @@ void build_and_draw_status_table(struct wt_status *s, int advice)
struct strbuf table_col_entry_1 = STRBUF_INIT;
struct strbuf table_col_entry_2 = STRBUF_INIT;
struct strbuf table_col_entry_3 = STRBUF_INIT;
+ struct strbuf arrow_1 = STRBUF_INIT;
+ struct strbuf arrow_2 = STRBUF_INIT;
+ struct strbuf arrow_3 = STRBUF_INIT;
struct string_list_item *item, *item2;
/* Get terminal width */
@@ -170,17 +173,21 @@ void build_and_draw_status_table(struct wt_status *s, int advice)
strbuf_addstr(&buf_2, item2->string);
if (!strbuf_cmp(&buf_1, &buf_2)) {
build_table_entry(&table_col_entry_3, buf_1.buf, cols);
- add_arrow_to_entry(&table_col_entry_1, 1);
- add_arrow_to_entry(&table_col_entry_2, 0);
- add_arrow_to_entry(&table_col_entry_3, 0);
+ build_arrow(&table_col_entry_1, &arrow_1, 1);
+ build_arrow(&table_col_entry_2, &arrow_2, 0);
+ build_arrow(&table_col_entry_3, &arrow_3, 0);
is_arrow = 1;
}
}
if (!is_arrow)
- print_table_body_line_(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, s);
+ print_table_body_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, &arrow_1, &arrow_2, &arrow_3, s, 0);
else
- print_table_body_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, s, 3);
+ print_table_body_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, &arrow_1, &arrow_2, &arrow_3, s, 3);
+
+ strbuf_reset(&arrow_1);
+ strbuf_reset(&arrow_2);
+ strbuf_reset(&arrow_3);
}
for_each_string_list_item(item, &s->change) {
@@ -203,8 +210,8 @@ void build_and_draw_status_table(struct wt_status *s, int advice)
strbuf_addstr(&buf_2, item2->string);
if (!strbuf_cmp(&buf_1, &buf_2)) {
build_table_entry(&table_col_entry_3, buf_1.buf, cols);
- add_arrow_to_entry(&table_col_entry_2, 1);
- add_arrow_to_entry(&table_col_entry_3, 0);
+ build_arrow(&table_col_entry_2, &arrow_2, 1);
+ build_arrow(&table_col_entry_3, &arrow_3, 0);
is_arrow = 1;
}
}
@@ -215,9 +222,12 @@ void build_and_draw_status_table(struct wt_status *s, int advice)
}
if (!is_arrow)
- print_table_body_line_(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, s);
+ print_table_body_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, &arrow_1, &arrow_2, &arrow_3, s, 0);
else
- print_table_body_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, s, 2);
+ print_table_body_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, &arrow_1, &arrow_2, &arrow_3, s, 2);
+ strbuf_reset(&arrow_1);
+ strbuf_reset(&arrow_2);
+ strbuf_reset(&arrow_3);
}
if (!s->untracked.nr && !s->change.nr) {
diff --git a/wt-status.c b/wt-status.c
index 975cfc01a5..fe38260baa 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -49,6 +49,7 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */
+ GIT_COLOR_CYAN, /* WT_STATUS_ARROW */
};
static const char *color(int slot, struct wt_status *s)
diff --git a/wt-status.h b/wt-status.h
index 5d29c058c1..0517f81e1b 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -19,6 +19,7 @@ enum color_wt_status {
WT_STATUS_LOCAL_BRANCH,
WT_STATUS_REMOTE_BRANCH,
WT_STATUS_ONBRANCH,
+ WT_STATUS_ARROW,
WT_STATUS_MAXSLOT
};
--
2.42.0.402.gbe8243af7b.dirty
next prev parent reply other threads:[~2023-10-20 18:39 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 18:39 [RFC PATCH 0/5] Introduce -t, --table for status/add commands Jacob Stopak
2023-10-20 18:39 ` [RFC PATCH 1/5] status: introduce -t, --table flag Jacob Stopak
2023-10-20 18:39 ` [RFC PATCH 2/5] status: handle long paths with " Jacob Stopak
2023-10-20 18:39 ` [RFC PATCH 3/5] status: add advice arg for " Jacob Stopak
2023-10-20 18:39 ` [RFC PATCH 4/5] add: add -t, --table flag for visual dry runs Jacob Stopak
2023-10-20 18:39 ` Jacob Stopak [this message]
2023-10-20 18:48 ` [RFC PATCH 0/5] Introduce -t, --table for status/add commands Dragan Simic
2023-10-20 21:48 ` Jacob Stopak
2023-10-20 23:02 ` Dragan Simic
2023-10-20 23:28 ` Junio C Hamano
2023-10-22 6:04 ` Jacob Stopak
2023-10-22 6:52 ` Dragan Simic
2023-10-22 5:52 ` Jacob Stopak
2023-10-22 6:38 ` Dragan Simic
2023-10-22 10:30 ` Oswald Buddenhagen
2023-10-22 12:55 ` Dragan Simic
2023-10-23 10:52 ` Oswald Buddenhagen
2023-10-23 14:34 ` Dragan Simic
2023-10-23 17:30 ` Jacob Stopak
2023-10-23 17:59 ` Dragan Simic
2023-10-23 18:16 ` Oswald Buddenhagen
2023-10-23 19:29 ` Jacob Stopak
2023-10-23 20:19 ` Oswald Buddenhagen
2023-10-23 20:51 ` Dragan Simic
2023-10-23 21:14 ` Oswald Buddenhagen
2023-10-23 21:19 ` Dragan Simic
2023-10-23 23:17 ` Jacob Stopak
2023-10-24 1:10 ` Dragan Simic
2023-10-24 2:03 ` Junio C Hamano
2023-10-24 2:21 ` Dragan Simic
2024-01-05 19:14 ` Dragan Simic
2024-01-06 4:44 ` Jacob Stopak
2024-01-06 7:06 ` Dragan Simic
2023-10-23 20:29 ` Dragan Simic
2023-10-23 19:01 ` Junio C Hamano
2023-10-23 19:04 ` Dragan Simic
2023-10-23 20:47 ` Oswald Buddenhagen
2023-10-23 20:59 ` Dragan Simic
2023-10-23 21:23 ` Jacob Stopak
2023-10-23 21:26 ` Dragan Simic
2023-10-23 21:12 ` Jacob Stopak
2023-10-22 15:50 ` Jacob Stopak
2023-10-26 22:46 ` [RFC PATCH v2 0/6] Noobify format for status, add, restore Jacob Stopak
2023-10-26 22:46 ` [RFC PATCH v2 1/6] status: add noob format from status.noob config Jacob Stopak
2023-10-30 1:32 ` Junio C Hamano
2023-10-30 1:38 ` Dragan Simic
2023-10-30 6:06 ` Jacob Stopak
2023-10-26 22:46 ` [RFC PATCH v2 2/6] status: handle long paths in noob format Jacob Stopak
2023-10-26 22:46 ` [RFC PATCH v2 3/6] add: implement noob mode Jacob Stopak
2023-10-26 22:46 ` [RFC PATCH v2 4/6] add: set unique color for noob mode arrows Jacob Stopak
2023-10-26 22:46 ` [RFC PATCH v2 5/6] restore: implement noob mode Jacob Stopak
2023-10-26 22:46 ` [RFC PATCH v2 6/6] status: add advice status hints as table footer Jacob Stopak
2023-10-27 13:32 ` [RFC PATCH v2 0/6] Noobify format for status, add, restore Dragan Simic
2023-10-27 17:13 ` Jacob Stopak
2023-10-28 0:06 ` Dragan Simic
2023-10-28 2:52 ` Jacob Stopak
2023-10-28 5:55 ` Dragan Simic
2023-10-28 15:21 ` Jacob Stopak
2023-10-28 16:20 ` Dragan Simic
2023-10-28 17:35 ` Jacob Stopak
2023-10-28 17:41 ` Dragan Simic
2023-10-28 18:05 ` Jacob Stopak
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=20231020183947.463882-6-jacob@initialcommit.io \
--to=jacob@initialcommit.io \
--cc=git@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).