diff --git a/src/winio.c b/src/winio.c index 4fe9db0..7ee306b 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1977,6 +1977,30 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata) return converted; } +int num_buffers(void) +{ + openfilestruct *first = openfile; + openfilestruct *next = first->next; + int count = 1; + while(first != next) { + count++; + next = next->next; + } + return count; +} + +int buffer_pos(void) +{ + openfilestruct *first = openfile; + openfilestruct *next = first->next; + int count = 1; + while(first != next) { + if(first > next) count++; + next = next->next; + } + 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 +2022,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; + /* Buffer count and position indicator on titlebar. */ /* If the screen is too small, there is no titlebar. */ if (topwin == NULL) @@ -2079,9 +2105,21 @@ void titlebar(const char *path) /* Print the full path if there's room; otherwise, dottify it. */ if (pathlen + pluglen + statelen <= COLS) { - caption = display_string(path, 0, pathlen, FALSE); + char *total = malloc(COLS); + int display_ind = asprintf(&buffer_indication, " [%d/%d]", buffer_pos(), num_buffers()); + int b_ind_len = strlen(buffer_indication); + + if(pathlen + pluglen + statelen + b_ind_len > COLS || !display_ind || num_buffers() == 1) + caption = display_string(path, 0, pathlen, FALSE); + else { + sprintf(total, "%s%s", path, buffer_indication); + caption = display_string(total, 0, strlen(total), FALSE); + } + waddstr(topwin, caption); free(caption); + free(buffer_indication); + free(total); } else if (5 + statelen <= COLS) { waddstr(topwin, "..."); caption = display_string(path, 3 + pathlen - COLS + statelen,