Patch for the editor



Hi,

I rewrote the code for the statusline of mcedit. Now it only truncates long filenames if necessary, that is if the terminal is not wide enough.

I tested the patch and it works like I expect. As this patch affects the user interface, I would like to hear an "Ok" from you first before I commit it.

Roland
Index: editdraw.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/editdraw.c,v
retrieving revision 1.32
diff -u -r1.32 editdraw.c
--- editdraw.c	29 Oct 2003 08:54:47 -0000	1.32
+++ editdraw.c	22 Sep 2004 18:52:02 -0000
@@ -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,36 @@
 		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);
+    int status_len;
+    int status_x = 18;
+    const char *fname_disp;
+
+    status_string (edit, status, status_size);
+    status_len = (int) strlen (status);
+    if (status_x + status_len + 2 < w)
+    	status_x = w - status_len - 2;
+
+    if (edit->filename)
+        fname_disp = name_trunc (edit->filename, status_x - 2);
+    else
+        fname_disp = "";
 
-    printw ("%-*s", w, s);
+    widget_move (edit, 0, 0);
+    attrset (SELECTED_COLOR);
+    printw ("%-*s", status_x, fname_disp);
+    if (w - status_x > 0)
+        printw ("%-*s", w - status_x, status);
     attrset (EDITOR_NORMAL_COLOR);
-    g_free (s);
+
+    g_free (status);
 }
 
 /* this scrolls the text so that cursor is on the screen */


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