From 0515db7380f0f6134e54a2e7587ae908755a0299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Fri, 1 Sep 2017 13:47:19 -0300 Subject: [PATCH] Implement displaying of number of current and total open buffers. 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 | 24 +++++++++++++++++++----- src/global.c | 2 ++ src/nano.c | 1 + src/proto.h | 1 + src/winio.c | 25 +++++++++++++++++++++++-- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/files.c b/src/files.c index d137315..378f7db 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; @@ -1039,6 +1042,8 @@ void do_insertfile(void) { int i; const char *msg; + static char *lastcommand = NULL; + char *prompt; char *given = mallocstrcpy(NULL, ""); /* The last answer the user typed at the statusbar prompt. */ #ifndef NANO_TINY @@ -1069,6 +1074,10 @@ void do_insertfile(void) msg = _("File to insert [from %s]"); } + if(!execute || lastcommand == NULL || asprintf(&prompt, "%s [%s]", msg, lastcommand) == -1) + prompt = (char*)msg; + + present_path = mallocstrcpy(present_path, "./"); i = do_prompt(TRUE, TRUE, @@ -1079,15 +1088,15 @@ void do_insertfile(void) #ifndef DISABLE_HISTORIES NULL, #endif - edit_refresh, msg, + edit_refresh, prompt, #ifndef DISABLE_OPERATINGDIR operating_dir != NULL ? operating_dir : #endif "./"); - /* If we're in multibuffer mode and the filename or command is + /* If we're in multibuffer mode and the filename is * blank, open a new buffer instead of canceling. */ - if (i == -1 || (i == -2 && !ISSET(MULTIBUFFER))) { + if (!execute && (i == -1 || (i == -2 && !ISSET(MULTIBUFFER)))) { statusbar(_("Cancelled")); break; } else { @@ -1128,7 +1137,7 @@ void do_insertfile(void) } #endif /* If we don't have a file yet, go back to the prompt. */ - if (i != 0 && (!ISSET(MULTIBUFFER) || i != -2)) + if (!execute && ((i != 0 && (!ISSET(MULTIBUFFER) || i != -2)))) continue; #ifndef NANO_TINY @@ -1139,7 +1148,12 @@ void do_insertfile(void) open_buffer("", FALSE); #endif /* Save the command's output in the current buffer. */ - execute_command(answer); + if (strcmp(answer, "") !=0) { + execute_command(answer); + lastcommand = strdup(answer); + } else { + execute_command(lastcommand); + } #ifdef ENABLE_MULTIBUFFER /* If this is a new buffer, put the cursor at the top. */ 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..9dcdeff 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,18 @@ 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->prev)); + 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