From 283441db92462b01b98e777f49525042cba55706 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Fri, 24 Sep 2004 11:13:11 +0000 Subject: [PATCH] * editdraw.c (status_string): Removed unused parameter. (edit_status): Rewrote to allow longer filenames to be displayed completely whenever possible. --- edit/ChangeLog | 6 +++++ edit/editdraw.c | 58 +++++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/edit/ChangeLog b/edit/ChangeLog index bd381bf84..87f93187c 100644 --- a/edit/ChangeLog +++ b/edit/ChangeLog @@ -1,3 +1,9 @@ +2004-09-24 Roland Illig + + * editdraw.c (status_string): Removed unused parameter. + (edit_status): Rewrote to allow longer filenames to be displayed + completely whenever possible. + 2004-09-19 Roland Illig * editcmd.c (edit_replace_cmd): Added const qualifier. diff --git a/edit/editdraw.c b/edit/editdraw.c index d55cee90d..40146a62b 100644 --- a/edit/editdraw.c +++ b/edit/editdraw.c @@ -45,7 +45,7 @@ #define FONT_MEAN_WIDTH 1 -static void status_string (WEdit * edit, char *s, int w, int fill) +static void status_string (WEdit * edit, char *s, int w) { char byte_str[16]; @@ -83,36 +83,42 @@ static void status_string (WEdit * edit, char *s, int w, int fill) byte_str); } -/* how to get as much onto the status line as is numerically possible :) */ +/* Draw the status line at the top of the widget. The status is displayed + * right-aligned to be able to display long file names unshorteded. */ void edit_status (WEdit *edit) { - int w, i, t; - char *s; - w = edit->widget.cols; - s = g_malloc (w + 16); - if (w < 4) - w = 4; - memset (s, ' ', w); - attrset (SELECTED_COLOR); - if (w > 4) { - widget_move (edit, 0, 0); - if (edit->filename) { - i = w > 24 ? 18 : w - 6; - i = i < 13 ? 13 : i; - strcpy (s, name_trunc (edit->filename, i)); - i = strlen (s); - s[i] = ' '; - } - t = w - 20; - if (t > 1) /* g_snprintf() must write at least '\000' */ - status_string (edit, s + 20, t + 1 /* for '\000' */ , ' '); - } - s[w] = 0; + const int w = edit->widget.cols; + const size_t status_size = w + 1; + char * const status = g_malloc (status_size); + size_t status_len; + const char *fname = ""; + size_t fname_len; + const int gap = 3; /* between the filename and the status */ - printw ("%-*s", w, s); + status_string (edit, status, status_size); + status_len = (int) strlen (status); + + if (edit->filename) + fname = edit->filename; + fname_len = strlen(fname); + + if (fname_len + gap + status_len + 2 >= w) { + if (16 + gap + status_len + 2 >= w) + fname_len = 16; + else + fname_len = w - (gap + status_len + 2); + fname = name_trunc (fname, fname_len); + } + + widget_move (edit, 0, 0); + attrset (SELECTED_COLOR); + printw ("%-*s", fname_len + gap, fname); + if (fname_len + gap < w) + printw ("%-*s ", w - (fname_len + gap), status); attrset (EDITOR_NORMAL_COLOR); - g_free (s); + + g_free (status); } /* this scrolls the text so that cursor is on the screen */