commit 3fc89e085393074eb78a7265b5d11ad6898a4f88
parent ac8eb42a4f8bf3171000efa4acdd47cb2b0280fe
Author: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
Date: Fri, 1 Sep 2017 13:47:19 -0300
new feature: show current and total number of open buffers in title bar
When multiple buffers are open, replace nano's name and version number
with an indication how many buffers are open preceded by the sequence
number of the current buffer.
Signed-off-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
Diffstat:
5 files changed, 35 insertions(+), 1 deletion(-)
diff --git 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;
@@ -669,8 +670,10 @@ bool close_buffer(void)
/* Switch to the next file buffer. */
switch_to_adjacent_buffer(TRUE);
- /* Close the file buffer we had open before. */
+ /* Delete the old file buffer, and adjust the count in the top bar. */
unlink_opennode(openfile->prev);
+ if (!inhelp)
+ titlebar(NULL);
/* If now just one buffer remains open, show "Exit" in the help lines. */
if (openfile == openfile->next)
diff --git 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;
+ /* The first open buffer. */
#ifndef NANO_TINY
char *matchbrackets = NULL;
diff --git a/src/nano.c b/src/nano.c
@@ -507,6 +507,9 @@ void unlink_opennode(openfilestruct *fileptr)
{
assert(fileptr != fileptr->prev && fileptr != fileptr->next);
+ if (fileptr == firstfile)
+ firstfile = firstfile->next;
+
fileptr->prev->next = fileptr->next;
fileptr->next->prev = fileptr->prev;
diff --git 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
@@ -1977,6 +1977,19 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata)
return converted;
}
+/* Determine the sequence number of the given buffer in the circular list. */
+int buffer_number(openfilestruct *buffer)
+{
+ int count = 1;
+
+ while (buffer != firstfile) {
+ buffer = buffer->prev;
+ count++;
+ }
+
+ 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 +2011,8 @@ void titlebar(const char *path)
/* The state of the current buffer -- "Modified", "View", or "". */
char *caption;
/* The presentable form of the pathname. */
+ char *indicator = NULL;
+ /* The buffer sequence number plus buffer count. */
/* If the screen is too small, there is no titlebar. */
if (topwin == NULL)
@@ -2014,6 +2029,14 @@ void titlebar(const char *path)
* first sacrifice the version string, then eat up the side spaces,
* then sacrifice the prefix, and only then start dottifying. */
+ /* When multiple buffers are open, show which one out of how many. */
+ if (path == NULL && firstfile != firstfile->next) {
+ indicator = charalloc(24);
+ sprintf(indicator, "[%i/%i]", buffer_number(openfile),
+ buffer_number(firstfile->prev));
+ branding = indicator;
+ }
+
/* Figure out the path, prefix and state strings. */
if (inhelp)
branding = "";
@@ -2064,6 +2087,8 @@ void titlebar(const char *path)
}
}
+ free(indicator);
+
/* If we have side spaces left, center the path name. */
if (verlen > 0)
offset = verlen + (COLS - (verlen + pluglen + statelen) -