From 9b440eeedf94ff8b06cdeb53e8bd4dec597bb54f Mon Sep 17 00:00:00 2001 From: OIX Date: Sat, 19 Dec 2020 01:56:22 +0100 Subject: [PATCH] tweak: changed how the stateflag string is created and placed in top window could not figure out a reason why there is a 7 character stateflag placeholder used, for the 5 possible state flags. and later, when the state flag position is calculated to display them, the formula adds 2 to the window size, to compensate for the 2 additional chars to correctly right align the flags. also, state variabe was only used as placeholder to enable length calculation, while later the state flags were rendered to screen on the fly, letter by letter w/o actually using the state string. changed code to set the state variabe to the actual flag states when the use of state flags is detected, and later just render the state string to the display. --- src/winio.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/winio.c b/src/winio.c index 03a12c4..b755286 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1886,6 +1886,9 @@ void titlebar(const char *path) /* What is shown before the path -- "DIR:" or nothing. */ const char *state = ""; /* The state of the current buffer -- "Modified", "View", or "". */ +#ifndef NANO_TINY + char sf[] = "IMLRS"; // stateflag string +#endif char *caption; /* The presentable form of the pathname. */ char *ranking = NULL; @@ -1937,8 +1940,15 @@ void titlebar(const char *path) if (ISSET(VIEW_MODE)) state = _("View"); #ifndef NANO_TINY - else if (ISSET(STATEFLAGS)) - state = "+.xxxxx"; + else if (ISSET(STATEFLAGS)) { + const char CLEAR=' '; + if(!ISSET(AUTOINDENT)) sf[0]=CLEAR; // I + if(!(openfile->mark)) sf[1]=CLEAR; // M + if(!ISSET(BREAK_LONG_LINES)) sf[2]=CLEAR; // L + if(!recording) sf[3]=CLEAR; // R + if(!ISSET(SOFTWRAP)) sf[4]=CLEAR; // S + state = sf; + } #endif else if (openfile->modified) state = _("Modified"); @@ -2007,14 +2017,8 @@ void titlebar(const char *path) if (ISSET(STATEFLAGS) && !ISSET(VIEW_MODE)) { if (openfile->modified && COLS > 1) waddstr(topwin, " *"); - if (statelen > 2 && statelen < COLS) { - wmove(topwin, 0, COLS + 2 - statelen); - waddstr(topwin, ISSET(AUTOINDENT) ? "I" : " "); - waddstr(topwin, openfile->mark ? "M" : " "); - waddstr(topwin, ISSET(BREAK_LONG_LINES) ? "L" : " "); - waddstr(topwin, recording ? "R" : " "); - waddstr(topwin, ISSET(SOFTWRAP) ? "S" : " "); - } + if (statelen && statelen < COLS) + mvwaddstr(topwin, 0, COLS - statelen, state); } else #endif { -- 2.7.4