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,
|
JUMPY_SCROLLING,
|
||||||
EMPTY_LINE,
|
EMPTY_LINE,
|
||||||
INDICATOR,
|
INDICATOR,
|
||||||
BOOKSTYLE
|
BOOKSTYLE,
|
||||||
|
STATEFLAGS
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Flags for the menus in which a given function should be present. */
|
/* 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
|
#ifndef NANO_TINY
|
||||||
/* TRANSLATORS: The next forty or so strings are option descriptions
|
/* TRANSLATORS: The next forty or so strings are option descriptions
|
||||||
* for the --help output. Try to keep them at most 40 characters. */
|
* 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"));
|
print_opt("-A", "--smarthome", N_("Enable smart home key"));
|
||||||
if (!ISSET(RESTRICTED)) {
|
if (!ISSET(RESTRICTED)) {
|
||||||
print_opt("-B", "--backup", N_("Save backups of existing files"));
|
print_opt("-B", "--backup", N_("Save backups of existing files"));
|
||||||
|
@ -1113,6 +1114,10 @@ void do_toggle(int flag)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ISSET(STATEFLAGS) && (flag == AUTOINDENT ||
|
||||||
|
flag == BREAK_LONG_LINES || flag == SOFTWRAP))
|
||||||
|
titlebar(NULL);
|
||||||
|
|
||||||
enabled = ISSET(flag);
|
enabled = ISSET(flag);
|
||||||
|
|
||||||
if (flag == NO_HELP || flag == NO_SYNTAX)
|
if (flag == NO_HELP || flag == NO_SYNTAX)
|
||||||
|
@ -1528,6 +1533,9 @@ void process_a_keystroke(void)
|
||||||
/* The input buffer for actual characters. */
|
/* The input buffer for actual characters. */
|
||||||
static size_t depth = 0;
|
static size_t depth = 0;
|
||||||
/* The length of the input buffer. */
|
/* The length of the input buffer. */
|
||||||
|
#ifndef NANO_TINY
|
||||||
|
linestruct *was_mark = openfile->mark;
|
||||||
|
#endif
|
||||||
static bool give_a_hint = TRUE;
|
static bool give_a_hint = TRUE;
|
||||||
const keystruct *shortcut;
|
const keystruct *shortcut;
|
||||||
|
|
||||||
|
@ -1667,6 +1675,9 @@ void process_a_keystroke(void)
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (bracketed_paste)
|
if (bracketed_paste)
|
||||||
suck_up_input_and_paste_it();
|
suck_up_input_and_paste_it();
|
||||||
|
|
||||||
|
if (ISSET(STATEFLAGS) && openfile->mark != was_mark)
|
||||||
|
titlebar(NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1750,6 +1761,7 @@ int main(int argc, char **argv)
|
||||||
{"nohelp", 0, NULL, 'x'},
|
{"nohelp", 0, NULL, 'x'},
|
||||||
{"suspendable", 0, NULL, 'z'},
|
{"suspendable", 0, NULL, 'z'},
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
{"stateflags", 0, NULL, '%'},
|
||||||
{"smarthome", 0, NULL, 'A'},
|
{"smarthome", 0, NULL, 'A'},
|
||||||
{"backup", 0, NULL, 'B'},
|
{"backup", 0, NULL, 'B'},
|
||||||
{"backupdir", 1, NULL, 'C'},
|
{"backupdir", 1, NULL, 'C'},
|
||||||
|
@ -1829,10 +1841,13 @@ int main(int argc, char **argv)
|
||||||
if (*(tail(argv[0])) == 'r')
|
if (*(tail(argv[0])) == 'r')
|
||||||
SET(RESTRICTED);
|
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) {
|
"abcdef:ghijklmno:pqr:s:tuvwxyz$", long_options, NULL)) != -1) {
|
||||||
switch (optchr) {
|
switch (optchr) {
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
case '%':
|
||||||
|
SET(STATEFLAGS);
|
||||||
|
break;
|
||||||
case 'A':
|
case 'A':
|
||||||
SET(SMART_HOME);
|
SET(SMART_HOME);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -114,6 +114,7 @@ static const rcoption rcopts[] = {
|
||||||
{"smarthome", SMART_HOME},
|
{"smarthome", SMART_HOME},
|
||||||
{"smooth", SMOOTH_SCROLL}, /* Deprecated; remove in 2021. */
|
{"smooth", SMOOTH_SCROLL}, /* Deprecated; remove in 2021. */
|
||||||
{"softwrap", SOFTWRAP},
|
{"softwrap", SOFTWRAP},
|
||||||
|
{"stateflags", STATEFLAGS},
|
||||||
{"tabstospaces", TABS_TO_SPACES},
|
{"tabstospaces", TABS_TO_SPACES},
|
||||||
{"trimblanks", TRIM_BLANKS},
|
{"trimblanks", TRIM_BLANKS},
|
||||||
{"unix", MAKE_IT_UNIX},
|
{"unix", MAKE_IT_UNIX},
|
||||||
|
|
21
src/winio.c
21
src/winio.c
|
@ -97,6 +97,9 @@ void record_macro(void)
|
||||||
snip_last_keystroke();
|
snip_last_keystroke();
|
||||||
statusbar(_("Stopped recording"));
|
statusbar(_("Stopped recording"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ISSET(STATEFLAGS))
|
||||||
|
titlebar(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the stored sequence of codes into the regular key buffer,
|
/* Copy the stored sequence of codes into the regular key buffer,
|
||||||
|
@ -1973,6 +1976,9 @@ void titlebar(const char *path)
|
||||||
else
|
else
|
||||||
path = openfile->filename;
|
path = openfile->filename;
|
||||||
|
|
||||||
|
if (ISSET(STATEFLAGS) && !ISSET(VIEW_MODE))
|
||||||
|
state = "+.xxxxx";
|
||||||
|
else
|
||||||
if (openfile->modified)
|
if (openfile->modified)
|
||||||
state = _("Modified");
|
state = _("Modified");
|
||||||
else if (ISSET(VIEW_MODE))
|
else if (ISSET(VIEW_MODE))
|
||||||
|
@ -2036,11 +2042,26 @@ void titlebar(const char *path)
|
||||||
free(caption);
|
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. */
|
/* Right-align the state if there's room; otherwise, trim it. */
|
||||||
if (statelen > 0 && statelen <= COLS)
|
if (statelen > 0 && statelen <= COLS)
|
||||||
mvwaddstr(topwin, 0, COLS - statelen, state);
|
mvwaddstr(topwin, 0, COLS - statelen, state);
|
||||||
else if (statelen > 0)
|
else if (statelen > 0)
|
||||||
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
|
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
|
||||||
|
}
|
||||||
|
|
||||||
wattroff(topwin, interface_color_pair[TITLE_BAR]);
|
wattroff(topwin, interface_color_pair[TITLE_BAR]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue