nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/7] feedback: differentiate between remarks, mistakes, and infor


From: Benno Schulenberg
Subject: [PATCH 5/7] feedback: differentiate between remarks, mistakes, and information
Date: Tue, 15 Dec 2020 10:44:07 +0100

Remarks are about unsurprising things but it's good to give feedback
on them; "mistakes" are unexpected things, and get colored like an
error; and information is something that the user requested and thus
needs to stay on the status bar until the next keystroke.
---
 src/cut.c         |  2 +-
 src/definitions.h |  2 +-
 src/files.c       |  6 +++---
 src/nano.c        | 30 +++++++++++++-----------------
 src/search.c      | 28 ++++++++++++++--------------
 src/text.c        | 44 ++++++++++++++++++++++----------------------
 src/winio.c       | 25 +++++++++++++------------
 7 files changed, 67 insertions(+), 70 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index eb40eec0..98933045 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -712,7 +712,7 @@ void paste_text(void)
                /* The leftedge where we started the paste. */
 
        if (cutbuffer == NULL) {
-               statusbar(_("Cutbuffer is empty"));
+               statusline(AHEM, _("Cutbuffer is empty"));
                return;
        }
 
diff --git a/src/definitions.h b/src/definitions.h
index bb02b017..846e7a59 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -250,7 +250,7 @@ typedef enum {
 } format_type;
 
 typedef enum {
-       VACUUM, HUSH, NOTICE, MILD, ALERT
+       VACUUM, HUSH, REMARK, INFO, NOTICE, AHEM, MILD, ALERT
 } message_type;
 
 typedef enum {
diff --git a/src/files.c b/src/files.c
index 2c4af674..97759434 100644
--- a/src/files.c
+++ b/src/files.c
@@ -519,7 +519,7 @@ void redecorate_after_switch(void)
 {
        /* If only one file buffer is open, there is nothing to update. */
        if (openfile == openfile->next) {
-               statusbar(_("No more open file buffers"));
+               statusline(AHEM, _("No more open file buffers"));
                return;
        }
 
@@ -831,7 +831,7 @@ int open_file(const char *filename, bool new_one, FILE **f)
                free(full_filename);
 
                if (new_one) {
-                       statusbar(_("New File"));
+                       statusline(REMARK, _("New File"));
                        return 0;
                } else {
                        statusline(ALERT, _("File \"%s\" not found"), filename);
@@ -2164,7 +2164,7 @@ int do_writeout(bool exiting, bool withprompt)
                                did_credits = TRUE;
                        } else
                                /* TRANSLATORS: Concisely say the screen is too 
small. */
-                               statusbar(_("Too tiny"));
+                               statusline(AHEM, _("Too tiny"));
 
                        free(given);
                        return 0;
diff --git a/src/nano.c b/src/nano.c
index 510d50ca..23931e17 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -197,14 +197,14 @@ void renumber_from(linestruct *line)
 /* Display a warning about a key disabled in view mode. */
 void print_view_warning(void)
 {
-       statusbar(_("Key is invalid in view mode"));
+       statusline(AHEM, _("Key is invalid in view mode"));
 }
 
 /* When in restricted mode, show a warning and return TRUE. */
 bool in_restricted_mode(void)
 {
        if (ISSET(RESTRICTED)) {
-               statusbar(_("This function is disabled in restricted mode"));
+               statusline(AHEM, _("This function is disabled in restricted 
mode"));
                beep();
                return TRUE;
        } else
@@ -953,7 +953,7 @@ void do_suspend(int signal)
 void do_suspend_void(void)
 {
        if (!ISSET(SUSPENDABLE)) {
-               statusbar(_("Suspension is not enabled"));
+               statusline(AHEM, _("Suspension is not enabled"));
                beep();
        } else
                do_suspend(0);
@@ -1113,7 +1113,7 @@ void do_toggle(int flag)
 
        if (!ISSET(MINIBAR) || flag == SMART_HOME || flag == CUT_FROM_CURSOR ||
                                flag == TABS_TO_SPACES || flag == USE_MOUSE || 
flag == SUSPENDABLE)
-               statusline(HUSH, "%s %s", _(flagtostr(flag)),
+               statusline(REMARK, "%s %s", _(flagtostr(flag)),
                                                enabled ? _("enabled") : 
_("disabled"));
 }
 #endif /* !NANO_TINY */
@@ -1255,28 +1255,28 @@ void unbound_key(int code)
        if (code == FOREIGN_SEQUENCE)
                /* TRANSLATORS: This refers to a sequence of escape codes
                 * (from the keyboard) that nano does not recognize. */
-               statusline(ALERT, _("Unknown sequence"));
+               statusline(AHEM, _("Unknown sequence"));
        else if (code > 0x7F)
-               statusline(ALERT, _("Unbound key"));
+               statusline(AHEM, _("Unbound key"));
        else if (meta_key) {
 #ifndef NANO_TINY
                if (code < 0x20)
-                       statusline(ALERT, _("Unbindable key: M-^%c"), code + 
0x40);
+                       statusline(AHEM, _("Unbindable key: M-^%c"), code + 
0x40);
                else
 #endif
 #ifdef ENABLE_NANORC
                if (shifted_metas && 'A' <= code && code <= 'Z')
-                       statusline(ALERT, _("Unbound key: Sh-M-%c"), code);
+                       statusline(AHEM, _("Unbound key: Sh-M-%c"), code);
                else
 #endif
-                       statusline(ALERT, _("Unbound key: M-%c"), 
toupper(code));
+                       statusline(AHEM, _("Unbound key: M-%c"), toupper(code));
        } else if (code == ESC_CODE)
-               statusline(ALERT, _("Unbindable key: ^["));
+               statusline(AHEM, _("Unbindable key: ^["));
        else if (code < 0x20)
-               statusline(ALERT, _("Unbound key: ^%c"), code + 0x40);
+               statusline(AHEM, _("Unbound key: ^%c"), code + 0x40);
 #if defined(ENABLE_BROWSER) || defined (ENABLE_HELP)
        else
-               statusline(ALERT, _("Unbound key: %c"), code);
+               statusline(AHEM, _("Unbound key: %c"), code);
 #endif
        set_blankdelay_to_one();
 }
@@ -2493,10 +2493,6 @@ int main(int argc, char **argv)
                                openfile->next == openfile && !ISSET(NO_HELP))
                statusbar(_("Welcome to nano.  For basic help, type Ctrl+G."));
 #endif
-#ifndef NANO_TINY
-       if (ISSET(MINIBAR) && lastmessage < ALERT)
-               lastmessage = VACUUM;
-#endif
 
        we_are_running = TRUE;
 
@@ -2512,7 +2508,7 @@ int main(int argc, char **argv)
                        bottombars(MMAIN);
 
 #ifndef NANO_TINY
-               if (ISSET(MINIBAR) && COLS > 48 && lastmessage == VACUUM)
+               if (ISSET(MINIBAR) && COLS > 48 && lastmessage < REMARK)
                        minibar();
                else
 #endif
diff --git a/src/search.c b/src/search.c
index c0c89804..24290816 100644
--- a/src/search.c
+++ b/src/search.c
@@ -42,7 +42,7 @@ bool regexp_init(const char *regexp)
                char *str = nmalloc(len);
 
                regerror(value, &search_regexp, str, len);
-               statusline(ALERT, _("Bad regex \"%s\": %s"), regexp, str);
+               statusline(AHEM, _("Bad regex \"%s\": %s"), regexp, str);
                free(str);
 
                return FALSE;
@@ -251,7 +251,7 @@ int findnextstr(const char *needle, bool whole_word_only, 
int modus,
                        line = (ISSET(BACKWARDS_SEARCH)) ? openfile->filebot : 
openfile->filetop;
 
                        if (modus == JUSTFIND) {
-                               statusbar(_("Search Wrapped"));
+                               statusline(REMARK, _("Search Wrapped"));
                                /* Delay the "Searching..." message for at 
least two seconds. */
                                feedback = -2;
                        }
@@ -356,7 +356,7 @@ void do_research(void)
 #endif
 
        if (*last_search == '\0') {
-               statusbar(_("No current search pattern"));
+               statusline(AHEM, _("No current search pattern"));
                return;
        }
 
@@ -394,7 +394,7 @@ void not_found_msg(const char *str)
        char *disp = display_string(str, 0, (COLS / 2) + 1, FALSE, FALSE);
        size_t numchars = actual_x(disp, wideness(disp, COLS / 2));
 
-       statusline(HUSH, _("\"%.*s%s\" not found"), numchars, disp,
+       statusline(AHEM, _("\"%.*s%s\" not found"), numchars, disp,
                                                (disp[numchars] == '\0') ? "" : 
"...");
        free(disp);
 }
@@ -421,14 +421,14 @@ void go_looking(void)
         * where we started searching, then this is the only occurrence. */
        if (didfind == 1 && openfile->current == was_current &&
                                openfile->current_x == was_current_x)
-               statusbar(_("This is the only occurrence"));
+               statusline(REMARK, _("This is the only occurrence"));
        else if (didfind == 1 && LINES == 1)
                refresh_needed = TRUE;
        else if (didfind == 0)
                not_found_msg(last_search);
 
 #ifdef TIMEIT
-       statusline(HUSH, "Took: %.2f", (double)(clock() - start) / 
CLOCKS_PER_SEC);
+       statusline(INFO, "Took: %.2f", (double)(clock() - start) / 
CLOCKS_PER_SEC);
 #endif
 
        edit_redraw(was_current, CENTERING);
@@ -750,7 +750,7 @@ void ask_for_and_do_replacements(void)
        refresh_needed = TRUE;
 
        if (numreplaced >= 0)
-               statusline(HUSH, P_("Replaced %zd occurrence",
+               statusline(REMARK, P_("Replaced %zd occurrence",
                                "Replaced %zd occurrences", numreplaced), 
numreplaced);
 }
 
@@ -798,7 +798,7 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool 
retain_answer,
 
                /* Try to extract one or two numbers from the user's response. 
*/
                if (!parse_line_column(answer, &line, &column)) {
-                       statusline(ALERT, _("Invalid line or column number"));
+                       statusline(AHEM, _("Invalid line or column number"));
                        return;
                }
        } else {
@@ -946,7 +946,7 @@ void do_find_bracket(void)
        ch = mbstrchr(matchbrackets, openfile->current->data + 
openfile->current_x);
 
        if (ch == NULL) {
-               statusbar(_("Not a bracket"));
+               statusline(AHEM, _("Not a bracket"));
                return;
        }
 
@@ -989,7 +989,7 @@ void do_find_bracket(void)
                }
        }
 
-       statusbar(_("No matching bracket"));
+       statusline(AHEM, _("No matching bracket"));
 
        /* Restore the cursor position. */
        openfile->current = was_current;
@@ -1004,9 +1004,9 @@ void put_or_lift_anchor(void)
        update_line(openfile->current, openfile->current_x);
 
        if (openfile->current->has_anchor)
-               statusbar(_("Placed anchor"));
+               statusline(REMARK, _("Placed anchor"));
        else
-               statusbar(_("Removed anchor"));
+               statusline(REMARK, _("Removed anchor"));
 }
 
 /* Make the given line the current line, or report the anchoredness. */
@@ -1020,9 +1020,9 @@ void go_to_and_confirm(linestruct *line)
                edit_redraw(was_current, CENTERING);
                statusbar(_("Jumped to anchor"));
        } else if (openfile->current->has_anchor)
-               statusbar(_("This is the only anchor"));
+               statusline(REMARK, _("This is the only anchor"));
        else
-               statusbar(_("There are no anchors"));
+               statusline(AHEM, _("There are no anchors"));
 }
 
 /* Jump to the first anchor before the current line; wrap around at the top. */
diff --git a/src/text.c b/src/text.c
index 0ed285da..add5e590 100644
--- a/src/text.c
+++ b/src/text.c
@@ -387,7 +387,7 @@ void do_comment(void)
                comment_seq = openfile->syntax->comment;
 
        if (*comment_seq == '\0') {
-               statusbar(_("Commenting is not supported for this file type"));
+               statusline(AHEM, _("Commenting is not supported for this file 
type"));
                return;
        }
 #endif
@@ -397,7 +397,7 @@ void do_comment(void)
 
        /* If only the magic line is selected, don't do anything. */
        if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) {
-               statusbar(_("Cannot comment past end of file"));
+               statusline(AHEM, _("Cannot comment past end of file"));
                return;
        }
 
@@ -519,7 +519,7 @@ void do_undo(void)
        size_t original_x, regain_from_x;
 
        if (u == NULL) {
-               statusbar(_("Nothing to undo"));
+               statusline(AHEM, _("Nothing to undo"));
                return;
        }
 
@@ -696,7 +696,7 @@ void do_redo(void)
        undostruct *u = openfile->undotop;
 
        if (u == NULL || u == openfile->current_undo) {
-               statusbar(_("Nothing to redo"));
+               statusline(AHEM, _("Nothing to redo"));
                return;
        }
 
@@ -1786,7 +1786,7 @@ void do_justify(bool full_justify)
 
                /* When the marked region is empty, do nothing. */
                if (startline == endline && start_x == end_x) {
-                       statusline(ALERT, _("Selection is empty"));
+                       statusline(AHEM, _("Selection is empty"));
                        discard_until(openfile->undotop->next);
                        return;
                }
@@ -1998,7 +1998,7 @@ void do_justify(bool full_justify)
        /* Show what we justified on the status bar. */
 #ifndef NANO_TINY
        if (openfile->mark)
-               statusbar(_("Justified selection"));
+               statusline(REMARK, _("Justified selection"));
        else
 #endif
        if (full_justify)
@@ -2106,10 +2106,10 @@ void treat(char *tempfile_name, char *theprogram, bool 
spelling)
                if (fileinfo.st_size == 0) {
 #ifndef NANO_TINY
                        if (spelling && openfile->mark)
-                               statusline(ALERT, _("Selection is empty"));
+                               statusline(AHEM, _("Selection is empty"));
                        else
 #endif
-                               statusbar(_("Buffer is empty"));
+                               statusline(AHEM, _("Buffer is empty"));
                        return;
                }
 
@@ -2155,7 +2155,7 @@ void treat(char *tempfile_name, char *theprogram, bool 
spelling)
        if (timestamp_sec > 0 && stat(tempfile_name, &fileinfo) == 0 &&
                                        (long)fileinfo.st_mtim.tv_sec == 
timestamp_sec &&
                                        (long)fileinfo.st_mtim.tv_nsec == 
timestamp_nsec) {
-               statusbar(_("Nothing changed"));
+               statusline(REMARK, _("Nothing changed"));
                return;
        }
 
@@ -2203,9 +2203,9 @@ void treat(char *tempfile_name, char *theprogram, bool 
spelling)
        adjust_viewport(STATIONARY);
 
        if (spelling)
-               statusbar(_("Finished checking spelling"));
+               statusline(REMARK, _("Finished checking spelling"));
        else
-               statusbar(_("Buffer has been processed"));
+               statusline(REMARK, _("Buffer has been processed"));
 }
 #endif /* ENABLE_SPELLER || ENABLE_COLOR */
 
@@ -2490,7 +2490,7 @@ void do_int_speller(const char *tempfile_name)
        else if (WIFEXITED(spell_status) == 0 || WEXITSTATUS(spell_status))
                statusline(ALERT, _("Error invoking \"spell\""));
        else
-               statusbar(_("Finished checking spelling"));
+               statusline(REMARK, _("Finished checking spelling"));
 }
 
 /* Spell check the current file.  If an alternate spell checker is
@@ -2573,7 +2573,7 @@ void do_linter(void)
                return;
 
        if (!openfile->syntax || !openfile->syntax->linter) {
-               statusbar(_("No linter is defined for this type of file"));
+               statusline(AHEM, _("No linter is defined for this type of 
file"));
                return;
        }
 
@@ -2733,7 +2733,7 @@ void do_linter(void)
        }
 
        if (!parsesuccess) {
-               statusline(HUSH, _("Got 0 parsable lines from command: %s"),
+               statusline(REMARK, _("Got 0 parsable lines from command: %s"),
                                                openfile->syntax->linter);
                return;
        }
@@ -2810,7 +2810,7 @@ void do_linter(void)
                                        free(dontwantfile);
 
                                        if (restlint == NULL) {
-                                               statusbar(_("No messages for 
this file"));
+                                               statusline(REMARK, _("No 
messages for this file"));
                                                break;
                                        } else {
                                                curlint = restlint;
@@ -2912,7 +2912,7 @@ void do_formatter(void)
                return;
 
        if (!openfile->syntax || !openfile->syntax->formatter) {
-               statusbar(_("No formatter is defined for this type of file"));
+               statusline(AHEM, _("No formatter is defined for this type of 
file"));
                return;
        }
 
@@ -2989,7 +2989,7 @@ void do_wordlinechar_count(void)
        openfile->current_x = was_x;
 
        /* Report on the status bar the number of lines, words, and characters. 
*/
-       statusline(HUSH, _("%s%zd %s,  %zu %s,  %zu %s"),
+       statusline(INFO, _("%s%zd %s,  %zu %s,  %zu %s"),
                                                openfile->mark ? _("In 
Selection:  ") : "",
                                                lines, P_("line", "lines", 
lines),
                                                words, P_("word", "words", 
words),
@@ -3004,7 +3004,7 @@ void do_verbatim_input(void)
        char *bytes;
 
        /* TRANSLATORS: Shown when the next keystroke will be inserted 
verbatim. */
-       statusbar(_("Verbatim Input"));
+       statusline(INFO, _("Verbatim Input"));
        place_the_cursor();
 
        /* Read in the first one or two bytes of the next keystroke. */
@@ -3022,7 +3022,7 @@ void do_verbatim_input(void)
                wipe_statusbar();
        } else
                /* TRANSLATORS: An invalid verbatim Unicode code was typed. */
-               statusline(ALERT, _("Invalid code"));
+               statusline(AHEM, _("Invalid code"));
 
        free(bytes);
 }
@@ -3098,7 +3098,7 @@ void complete_a_word(void)
        /* If there is no word fragment before the cursor, do nothing. */
        if (start_of_shard == openfile->current_x) {
                /* TRANSLATORS: Shown when no text is directly left of the 
cursor. */
-               statusbar(_("No word fragment"));
+               statusline(AHEM, _("No word fragment"));
                pletion_line = NULL;
                return;
        }
@@ -3190,11 +3190,11 @@ void complete_a_word(void)
 
        /* The search has reached the end of the file. */
        if (list_of_completions != NULL) {
-               statusline(ALERT, _("No further matches"));
+               statusline(AHEM, _("No further matches"));
                refresh_needed = TRUE;
        } else
                /* TRANSLATORS: Shown when there are zero possible completions. 
*/
-               statusline(ALERT, _("No matches"));
+               statusline(AHEM, _("No matches"));
 
        free(shard);
 }
diff --git a/src/winio.c b/src/winio.c
index 54c0e51d..37a5c06d 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -91,10 +91,10 @@ void record_macro(void)
 
        if (recording) {
                macro_length = 0;
-               statusbar(_("Recording a macro..."));
+               statusline(REMARK, _("Recording a macro..."));
        } else {
                snip_last_keystroke();
-               statusbar(_("Stopped recording"));
+               statusline(REMARK, _("Stopped recording"));
        }
 
        if (ISSET(STATEFLAGS))
@@ -106,13 +106,13 @@ void record_macro(void)
 void run_macro(void)
 {
        if (recording) {
-               statusbar(_("Cannot run macro while recording"));
+               statusline(AHEM, _("Cannot run macro while recording"));
                snip_last_keystroke();
                return;
        }
 
        if (macro_length == 0) {
-               statusbar(_("Macro is empty"));
+               statusline(REMARK, _("Macro is empty"));
                return;
        }
 
@@ -185,8 +185,8 @@ void read_keys_from(WINDOW *win)
                curs_set(1);
 
 #ifndef NANO_TINY
-       if (currmenu == MMAIN && ISSET(MINIBAR) &&
-                                       lastmessage > VACUUM && lastmessage < 
ALERT) {
+       if (currmenu == MMAIN && ISSET(MINIBAR) && lastmessage > HUSH &&
+                                               lastmessage != INFO && 
lastmessage < ALERT) {
                timed = TRUE;
                halfdelay(8);
        }
@@ -208,6 +208,7 @@ void read_keys_from(WINDOW *win)
 
                        if (input == ERR) {
                                minibar();
+                               as_an_at = TRUE;
                                place_the_cursor();
                                doupdate();
                                continue;
@@ -1335,7 +1336,7 @@ long assemble_unicode(int symbol)
 
                /* TRANSLATORS: This is shown while a six-digit hexadecimal
                 * Unicode character code (%s) is being typed in. */
-               statusline(HUSH, _("Unicode Input: %s"), partial);
+               statusline(INFO, _("Unicode Input: %s"), partial);
        }
 
        /* If we have an end result, reset the Unicode digit counter. */
@@ -2133,8 +2134,7 @@ void statusline(message_type importance, const char *msg, 
...)
 #endif
 
        /* Ignore a message with an importance that is lower than the last one. 
*/
-       if ((lastmessage == ALERT && importance != ALERT) ||
-                               (lastmessage == MILD && importance == HUSH))
+       if (importance < lastmessage && lastmessage > NOTICE)
                return;
 
        /* If there are multiple alert messages, add trailing dots to the 
first. */
@@ -2152,8 +2152,9 @@ void statusline(message_type importance, const char *msg, 
...)
                return;
        }
 
-       if (importance == ALERT) {
-               beep();
+       if (importance > NOTICE) {
+               if (importance == ALERT)
+                       beep();
                colorpair = interface_color_pair[ERROR_MESSAGE];
        } else if (importance == NOTICE)
                colorpair = interface_color_pair[SELECTED_TEXT];
@@ -3374,7 +3375,7 @@ void report_cursor_position(void)
        colpct = 100 * column / fullwidth;
        charpct = (openfile->totsize == 0) ? 0 : 100 * sum / openfile->totsize;
 
-       statusline(HUSH,
+       statusline(INFO,
                        _("line %zd/%zd (%d%%), col %zu/%zu (%d%%), char 
%zu/%zu (%d%%)"),
                        openfile->current->lineno, openfile->filebot->lineno, 
linepct,
                        column, fullwidth, colpct, sum, openfile->totsize, 
charpct);
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]