On Sat, Jun 4, 2016 at 11:30 PM, Junio C Hamano <gitster@xxxxxxxxx> wrote: >> The patch does not do fancy stuff like this yet, but it can because >> lines exceeding terminal width is already excluded from column width >> calculation. So far the output looks good on my terminal (192 chars, >> can't overflow or refnames are insanely long) > > Sounds like a sensible approach.... > >> -- 8< -- >> diff --git a/builtin/fetch.c b/builtin/fetch.c >> index a7f152a..5e1e5c9 100644 >> --- a/builtin/fetch.c >> +++ b/builtin/fetch.c >> @@ -15,6 +15,7 @@ >> #include "submodule.h" >> #include "connected.h" >> #include "argv-array.h" >> +#include "utf8.h" >> >> static const char * const builtin_fetch_usage[] = { >> N_("git fetch [<options>] [<repository> [<refspec>...]]"), >> @@ -449,14 +450,26 @@ fail: >> : STORE_REF_ERROR_OTHER; >> } >> >> -#define REFCOL_WIDTH 10 >> +static int refcol_width = 10; >> + >> +static void adjust_refcol_width(const char *remote, const char *local) >> +{ >> + int max = term_columns(); >> + int rlen = utf8_strwidth(remote); >> + int llen = utf8_strwidth(local); >> + >> + if (21 /* flag summary */ + rlen + 4 /* => */ + llen >= max) >> + return; >> + if (refcol_width < rlen) >> + refcol_width = rlen; >> +} >> >> static void format_display(struct strbuf *display, char code, >> const char *summary, const char *error, >> const char *remote, const char *local) >> { >> strbuf_addf(display, "%c %-*s ", code, TRANSPORT_SUMMARY(summary)); >> - strbuf_addf(display, "%-*s -> %s", REFCOL_WIDTH, remote, local); >> + strbuf_addf(display, "%-*s -> %s", refcol_width, remote, local); > > ... and if I understand correctly, this is the only place where you > need to decide if you need to switch to two lines, right? You would > measure width of the remote and compare it with refcol_width or > something like that. Exactly. -- Duy -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html