Commit 3fc89e08 authored by Marco Diego Aurélio Mesquita's avatar Marco Diego Aurélio Mesquita Committed by Benno Schulenberg
Browse files

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: default avatarMarco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
Signed-off-by: default avatarBenno Schulenberg <bensberg@telfort.nl>
No related merge requests found
Showing with 35 additions and 1 deletion
+35 -1
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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) -
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment