From 01e813a551cd8389f9e190bbd7fbe555b89fc956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Thu, 31 Aug 2017 18:11:07 -0300 Subject: [PATCH] Improve mult-buffer display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Diego Aurélio Mesquita --- src/files.c | 3 +++ src/global.c | 2 ++ src/nano.c | 1 + src/proto.h | 1 + src/winio.c | 24 ++++++++++++++++++++++-- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/files.c b/src/files.c index d137315..105db52 100644 --- a/src/files.c +++ b/src/files.c @@ -68,6 +68,7 @@ void make_new_buffer(void) /* Make the first open file the only element in the list. */ newnode->prev = newnode; newnode->next = newnode; + firstfile = newnode; } else { /* Add the new open file after the current one in the list. */ newnode->prev = openfile; @@ -672,6 +673,8 @@ bool close_buffer(void) /* Close the file buffer we had open before. */ unlink_opennode(openfile->prev); + firstfile = openfile; + /* If now just one buffer remains open, show "Exit" in the help lines. */ if (openfile == openfile->next) exitfunc->desc = exit_tag; diff --git a/src/global.c b/src/global.c index f89d8ef..7c90b40 100644 --- a/src/global.c +++ b/src/global.c @@ -119,6 +119,8 @@ partition *filepart = NULL; /* The "partition" where we store a portion of the current file. */ openfilestruct *openfile = NULL; /* The list of all open file buffers. */ +openfilestruct *firstfile = NULL; + /* First open file buffers. */ #ifndef NANO_TINY char *matchbrackets = NULL; diff --git a/src/nano.c b/src/nano.c index f29cea9..aa503be 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1096,6 +1096,7 @@ void close_and_go(void) if (!close_buffer()) #endif finish(); + total_refresh(); } /* Another placeholder for function mapping. */ diff --git a/src/proto.h b/src/proto.h index 5f04d32..4fed496 100644 --- a/src/proto.h +++ b/src/proto.h @@ -100,6 +100,7 @@ extern filestruct *cutbuffer; extern filestruct *cutbottom; extern partition *filepart; extern openfilestruct *openfile; +extern openfilestruct *firstfile; #ifndef NANO_TINY extern char *matchbrackets; diff --git a/src/winio.c b/src/winio.c index 4fe9db0..d4906e6 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1977,6 +1977,16 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata) return converted; } +int buffer_pos(openfilestruct *buffer) +{ + int count = 1; + while(firstfile != buffer) { + count++; + buffer = buffer->prev; + } + return count; +} + /* If path is NULL, we're in normal editing mode, so display the current * version of nano, the current filename, and whether the current file * has been modified on the titlebar. If path isn't NULL, we're either @@ -1998,6 +2008,8 @@ void titlebar(const char *path) /* The state of the current buffer -- "Modified", "View", or "". */ char *caption; /* The presentable form of the pathname. */ + char *buffer_indication = NULL; + /* Buffer count and position indicator on titlebar. */ /* If the screen is too small, there is no titlebar. */ if (topwin == NULL) @@ -2050,9 +2062,17 @@ void titlebar(const char *path) } /* Only print the version message when there is room for it. */ - if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS) + /* Conditionally replace branding by the number of buffers */ + int display_ind = asprintf(&buffer_indication, "[%d/%d]", buffer_pos(openfile->prev), buffer_pos(firstfile)); + int b_ind_len = strlen(buffer_indication); + if(buffer_pos(firstfile->prev) != 1 && !inhelp && display_ind) { + verlen = b_ind_len; + branding = buffer_indication; + } + if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS) { mvwaddstr(topwin, 0, 2, branding); - else { + free(buffer_indication); + } else { verlen = 2; /* If things don't fit yet, give up the placeholder. */ if (verlen + prefixlen + pathlen + pluglen + statelen > COLS) -- 2.7.4