[RFC PATCH v2 6/6] status: add advice status hints as table footer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jacob Stopak <jacob@xxxxxxxxxxxxxxxx>
---
 builtin/commit.c |  1 +
 table.c          | 42 +++++++++++++++++++++++++++---------------
 table.h          |  2 +-
 wt-status.c      |  3 ++-
 wt-status.h      |  2 ++
 5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 3f816c117d..b97943e642 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1434,6 +1434,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	s.ignore_submodule_arg = ignore_submodule_arg;
 	s.status_format = status_format;
 	s.verbose = verbose;
+	s.is_cmd_status = 1;
 	if (no_renames != -1)
 		s.detect_rename = !no_renames;
 	if ((intptr_t)rename_score_arg != -1) {
diff --git a/table.c b/table.c
index 3602def17a..36719e3d09 100644
--- a/table.c
+++ b/table.c
@@ -6,6 +6,7 @@
 #include "config.h"
 #include "string-list.h"
 #include "color.h"
+#include "advice.h"
 #include "sys/ioctl.h"
 
 static const char *color(int slot, struct wt_status *s)
@@ -132,7 +133,18 @@ static void print_table_body_line(struct strbuf *buf1, struct strbuf *buf2, stru
 	printf(_("|\n"));
 }
 
-void print_noob_status(struct wt_status *s, int advice)
+static void print_table_hint_line(struct strbuf *buf1, struct strbuf *buf2, struct strbuf *buf3, struct wt_status *s)
+{
+	printf(_("|"));
+	color_fprintf(s->fp, color(WT_STATUS_HINT, s), "%s", buf1->buf);
+	printf(_("|"));
+	color_fprintf(s->fp, color(WT_STATUS_HINT, s), "%s", buf2->buf);
+	printf(_("|"));
+	color_fprintf(s->fp, color(WT_STATUS_HINT, s), "%s", buf3->buf);
+	printf(_("|\n"));
+}
+
+void print_noob_status(struct wt_status *s)
 {
 	struct winsize w;
 	int cols;
@@ -163,20 +175,6 @@ void print_noob_status(struct wt_status *s, int advice)
 	printf(_("%s\n"), table_border.buf);
 	printf(_("|%s|%s|%s|\n"), table_col_entry_1.buf, table_col_entry_2.buf, table_col_entry_3.buf);
 
-	if (advice) {
-		build_table_entry(&table_col_entry_1, "(stage: git add <file>)", cols);
-		build_table_entry(&table_col_entry_2, "(stage: git add <file>)", cols);
-		build_table_entry(&table_col_entry_3, "(unstage: git restore --staged <file>)", cols);
-
-		printf(_("|%s|%s|%s|\n"), table_col_entry_1.buf, table_col_entry_2.buf, table_col_entry_3.buf);
-
-		build_table_entry(&table_col_entry_1, "", cols);
-		build_table_entry(&table_col_entry_2, "(discard: git restore --staged <file>)", cols);
-		build_table_entry(&table_col_entry_3, "", cols);
-
-		printf(_("|%s|%s|%s|\n"), table_col_entry_1.buf, table_col_entry_2.buf, table_col_entry_3.buf);
-	}
-
 	printf(_("%s\n"), table_border.buf);
 
 	/* Draw table body */
@@ -282,6 +280,20 @@ void print_noob_status(struct wt_status *s, int advice)
 	}
 
 	printf(_("%s\n"), table_border.buf);
+
+	if (s->is_cmd_status && advice_enabled(ADVICE_STATUS_HINTS)) {
+		build_table_entry(&table_col_entry_1, "stage: git add ...", cols);
+		build_table_entry(&table_col_entry_2, "stage: git add ...", cols);
+		build_table_entry(&table_col_entry_3, "unstage: git restore --staged ...", cols);
+		print_table_hint_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, s);
+
+		build_table_entry(&table_col_entry_1, "", cols);
+		build_table_entry(&table_col_entry_2, "discard: git restore --staged ...", cols);
+		build_table_entry(&table_col_entry_3, "", cols);
+		print_table_hint_line(&table_col_entry_1, &table_col_entry_2, &table_col_entry_3, s);
+		printf(_("%s\n"), table_border.buf);
+	}
+
 	strbuf_release(&table_border);
 	strbuf_release(&table_col_entry_1);
 	strbuf_release(&table_col_entry_2);
diff --git a/table.h b/table.h
index 5dff7162a4..c9e8c386de 100644
--- a/table.h
+++ b/table.h
@@ -1,6 +1,6 @@
 #ifndef TABLE_H
 #define TABLE_H
 
-void print_noob_status(struct wt_status *s, int i);
+void print_noob_status(struct wt_status *s);
 
 #endif /* TABLE_H */
diff --git a/wt-status.c b/wt-status.c
index 1332d07dba..288817dcf7 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -50,6 +50,7 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RED,    /* WT_STATUS_REMOTE_BRANCH */
 	GIT_COLOR_NIL,    /* WT_STATUS_ONBRANCH */
 	GIT_COLOR_CYAN,   /* WT_STATUS_ARROW */
+	GIT_COLOR_YELLOW, /* WT_STATUS_HINT */
 };
 
 static const char *color(int slot, struct wt_status *s)
@@ -2151,7 +2152,7 @@ static void wt_noobstatus_print(struct wt_status *s)
 		wt_longstatus_print_tracking(s);
 	}
 
-	print_noob_status(s, 0);
+	print_noob_status(s);
 }
 
 static void wt_porcelain_print(struct wt_status *s)
diff --git a/wt-status.h b/wt-status.h
index c6bce8f74a..0a14b4b064 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -20,6 +20,7 @@ enum color_wt_status {
 	WT_STATUS_REMOTE_BRANCH,
 	WT_STATUS_ONBRANCH,
 	WT_STATUS_ARROW,
+	WT_STATUS_HINT,
 	WT_STATUS_MAXSLOT
 };
 
@@ -146,6 +147,7 @@ struct wt_status {
 	struct string_list added;
 	struct string_list restored;
 	uint32_t untracked_in_ms;
+	int is_cmd_status;
 };
 
 size_t wt_status_locate_end(const char *s, size_t len);
-- 
2.42.0.404.g2bcc23f3db





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux