new feature: option --stateflags to show some states in top-right corner
With --stateflags (short form: -%) or 'set stateflags', nano reserves the righthand end of the title bar not for showing "Modified" but for showing the state of auto-indentation (I), the mark (M), the breaking of long lines (L), macro recording (R), and softwrapping (S). When the buffer is modified, this is indicated with a star (*) after the file name (shown in the center of the title bar). This fulfills https://savannah.gnu.org/bugs/?57953. Requested-by: Sébastien Desreux <seb@h-k.fr>master
parent
6d88281357
commit
d679bbc802
|
@ -541,7 +541,8 @@ enum
|
|||
JUMPY_SCROLLING,
|
||||
EMPTY_LINE,
|
||||
INDICATOR,
|
||||
BOOKSTYLE
|
||||
BOOKSTYLE,
|
||||
STATEFLAGS
|
||||
};
|
||||
|
||||
/* Flags for the menus in which a given function should be present. */
|
||||
|
|
17
src/nano.c
17
src/nano.c
|
@ -497,6 +497,7 @@ void usage(void)
|
|||
#ifndef NANO_TINY
|
||||
/* TRANSLATORS: The next forty or so strings are option descriptions
|
||||
* for the --help output. Try to keep them at most 40 characters. */
|
||||
print_opt("-%", "--stateflags", N_("Show some states on the title bar"));
|
||||
print_opt("-A", "--smarthome", N_("Enable smart home key"));
|
||||
if (!ISSET(RESTRICTED)) {
|
||||
print_opt("-B", "--backup", N_("Save backups of existing files"));
|
||||
|
@ -1113,6 +1114,10 @@ void do_toggle(int flag)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (ISSET(STATEFLAGS) && (flag == AUTOINDENT ||
|
||||
flag == BREAK_LONG_LINES || flag == SOFTWRAP))
|
||||
titlebar(NULL);
|
||||
|
||||
enabled = ISSET(flag);
|
||||
|
||||
if (flag == NO_HELP || flag == NO_SYNTAX)
|
||||
|
@ -1528,6 +1533,9 @@ void process_a_keystroke(void)
|
|||
/* The input buffer for actual characters. */
|
||||
static size_t depth = 0;
|
||||
/* The length of the input buffer. */
|
||||
#ifndef NANO_TINY
|
||||
linestruct *was_mark = openfile->mark;
|
||||
#endif
|
||||
static bool give_a_hint = TRUE;
|
||||
const keystruct *shortcut;
|
||||
|
||||
|
@ -1667,6 +1675,9 @@ void process_a_keystroke(void)
|
|||
#ifndef NANO_TINY
|
||||
if (bracketed_paste)
|
||||
suck_up_input_and_paste_it();
|
||||
|
||||
if (ISSET(STATEFLAGS) && openfile->mark != was_mark)
|
||||
titlebar(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1750,6 +1761,7 @@ int main(int argc, char **argv)
|
|||
{"nohelp", 0, NULL, 'x'},
|
||||
{"suspendable", 0, NULL, 'z'},
|
||||
#ifndef NANO_TINY
|
||||
{"stateflags", 0, NULL, '%'},
|
||||
{"smarthome", 0, NULL, 'A'},
|
||||
{"backup", 0, NULL, 'B'},
|
||||
{"backupdir", 1, NULL, 'C'},
|
||||
|
@ -1829,10 +1841,13 @@ int main(int argc, char **argv)
|
|||
if (*(tail(argv[0])) == 'r')
|
||||
SET(RESTRICTED);
|
||||
|
||||
while ((optchr = getopt_long(argc, argv, "ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
|
||||
while ((optchr = getopt_long(argc, argv, "%ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
|
||||
"abcdef:ghijklmno:pqr:s:tuvwxyz$", long_options, NULL)) != -1) {
|
||||
switch (optchr) {
|
||||
#ifndef NANO_TINY
|
||||
case '%':
|
||||
SET(STATEFLAGS);
|
||||
break;
|
||||
case 'A':
|
||||
SET(SMART_HOME);
|
||||
break;
|
||||
|
|
|
@ -114,6 +114,7 @@ static const rcoption rcopts[] = {
|
|||
{"smarthome", SMART_HOME},
|
||||
{"smooth", SMOOTH_SCROLL}, /* Deprecated; remove in 2021. */
|
||||
{"softwrap", SOFTWRAP},
|
||||
{"stateflags", STATEFLAGS},
|
||||
{"tabstospaces", TABS_TO_SPACES},
|
||||
{"trimblanks", TRIM_BLANKS},
|
||||
{"unix", MAKE_IT_UNIX},
|
||||
|
|
21
src/winio.c
21
src/winio.c
|
@ -97,6 +97,9 @@ void record_macro(void)
|
|||
snip_last_keystroke();
|
||||
statusbar(_("Stopped recording"));
|
||||
}
|
||||
|
||||
if (ISSET(STATEFLAGS))
|
||||
titlebar(NULL);
|
||||
}
|
||||
|
||||
/* Copy the stored sequence of codes into the regular key buffer,
|
||||
|
@ -1973,6 +1976,9 @@ void titlebar(const char *path)
|
|||
else
|
||||
path = openfile->filename;
|
||||
|
||||
if (ISSET(STATEFLAGS) && !ISSET(VIEW_MODE))
|
||||
state = "+.xxxxx";
|
||||
else
|
||||
if (openfile->modified)
|
||||
state = _("Modified");
|
||||
else if (ISSET(VIEW_MODE))
|
||||
|
@ -2036,11 +2042,26 @@ void titlebar(const char *path)
|
|||
free(caption);
|
||||
}
|
||||
|
||||
/* When requested, show on the title bar the state of three options and
|
||||
* the state of the mark and whether a macro is being recorded. */
|
||||
if (ISSET(STATEFLAGS) && !ISSET(VIEW_MODE)) {
|
||||
if (COLS > 1)
|
||||
waddstr(topwin, openfile->modified ? " *" : " ");
|
||||
if (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" : " ");
|
||||
}
|
||||
} else {
|
||||
/* Right-align the state if there's room; otherwise, trim it. */
|
||||
if (statelen > 0 && statelen <= COLS)
|
||||
mvwaddstr(topwin, 0, COLS - statelen, state);
|
||||
else if (statelen > 0)
|
||||
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
|
||||
}
|
||||
|
||||
wattroff(topwin, interface_color_pair[TITLE_BAR]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue