statusbar: add a non-beeping message type that does not get overwritten
Error messages about lock files should not get overwritten by purely informational messages, only by alerting ones. This fixes https://savannah.gnu.org/bugs/?47963.master
parent
c9d1936f02
commit
c8f530af93
|
@ -105,7 +105,7 @@ char *do_browser(char *path, DIR *dir)
|
||||||
|
|
||||||
/* Make sure that the cursor is off. */
|
/* Make sure that the cursor is off. */
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
alerted = FALSE;
|
lastmessage = HUSH;
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (kbinput == KEY_WINCH) {
|
if (kbinput == KEY_WINCH) {
|
||||||
|
|
18
src/files.c
18
src/files.c
|
@ -184,7 +184,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
* old state. */
|
* old state. */
|
||||||
myuid = geteuid();
|
myuid = geteuid();
|
||||||
if ((mypwuid = getpwuid(myuid)) == NULL) {
|
if ((mypwuid = getpwuid(myuid)) == NULL) {
|
||||||
statusline(ALERT, _("Couldn't determine my identity for lock file "
|
statusline(MILD, _("Couldn't determine my identity for lock file "
|
||||||
"(getpwuid() failed)"));
|
"(getpwuid() failed)"));
|
||||||
goto free_and_fail;
|
goto free_and_fail;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
if (errno == ENAMETOOLONG)
|
if (errno == ENAMETOOLONG)
|
||||||
myhostname[31] = '\0';
|
myhostname[31] = '\0';
|
||||||
else {
|
else {
|
||||||
statusline(ALERT, _("Couldn't determine hostname for lock file: %s"),
|
statusline(MILD, _("Couldn't determine hostname for lock file: %s"),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto free_and_fail;
|
goto free_and_fail;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
/* Maybe we just don't have write access. Print an error message
|
/* Maybe we just don't have write access. Print an error message
|
||||||
* and continue. */
|
* and continue. */
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
statusline(ALERT, _("Error writing lock file %s: %s"),
|
statusline(MILD, _("Error writing lock file %s: %s"),
|
||||||
lockfilename, strerror(errno));
|
lockfilename, strerror(errno));
|
||||||
free(lockdata);
|
free(lockdata);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -227,7 +227,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
filestream = fdopen(fd, "wb");
|
filestream = fdopen(fd, "wb");
|
||||||
|
|
||||||
if (fd < 0 || filestream == NULL) {
|
if (fd < 0 || filestream == NULL) {
|
||||||
statusline(ALERT, _("Error writing lock file %s: %s"), lockfilename,
|
statusline(MILD, _("Error writing lock file %s: %s"), lockfilename,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto free_and_fail;
|
goto free_and_fail;
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
|
|
||||||
wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream);
|
wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream);
|
||||||
if (wroteamt < lockdatalen) {
|
if (wroteamt < lockdatalen) {
|
||||||
statusline(ALERT, _("Error writing lock file %s: %s"),
|
statusline(MILD, _("Error writing lock file %s: %s"),
|
||||||
lockfilename, ferror(filestream));
|
lockfilename, ferror(filestream));
|
||||||
goto free_and_fail;
|
goto free_and_fail;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fclose(filestream) == EOF) {
|
if (fclose(filestream) == EOF) {
|
||||||
statusline(ALERT, _("Error writing lock file %s: %s"),
|
statusline(MILD, _("Error writing lock file %s: %s"),
|
||||||
lockfilename, strerror(errno));
|
lockfilename, strerror(errno));
|
||||||
goto free_and_fail;
|
goto free_and_fail;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
int delete_lockfile(const char *lockfilename)
|
int delete_lockfile(const char *lockfilename)
|
||||||
{
|
{
|
||||||
if (unlink(lockfilename) < 0 && errno != ENOENT) {
|
if (unlink(lockfilename) < 0 && errno != ENOENT) {
|
||||||
statusline(ALERT, _("Error deleting lock file %s: %s"), lockfilename,
|
statusline(MILD, _("Error deleting lock file %s: %s"), lockfilename,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ int do_lockfile(const char *filename)
|
||||||
int room, ans;
|
int room, ans;
|
||||||
|
|
||||||
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
|
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
|
||||||
statusline(ALERT, _("Error opening lock file %s: %s"),
|
statusline(MILD, _("Error opening lock file %s: %s"),
|
||||||
lockfilename, strerror(errno));
|
lockfilename, strerror(errno));
|
||||||
goto free_the_name;
|
goto free_the_name;
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ int do_lockfile(const char *filename)
|
||||||
} while (readamt > 0 && readtot < LOCKBUFSIZE);
|
} while (readamt > 0 && readtot < LOCKBUFSIZE);
|
||||||
|
|
||||||
if (readtot < 48) {
|
if (readtot < 48) {
|
||||||
statusline(ALERT, _("Error reading lock file %s: "
|
statusline(MILD, _("Error reading lock file %s: "
|
||||||
"Not enough data read"), lockfilename);
|
"Not enough data read"), lockfilename);
|
||||||
free(lockbuf);
|
free(lockbuf);
|
||||||
goto free_the_name;
|
goto free_the_name;
|
||||||
|
|
|
@ -39,8 +39,9 @@ bool func_key;
|
||||||
/* Whether the current keystroke is an extended keypad value. */
|
/* Whether the current keystroke is an extended keypad value. */
|
||||||
bool focusing = TRUE;
|
bool focusing = TRUE;
|
||||||
/* Whether an update of the edit window should center the cursor. */
|
/* Whether an update of the edit window should center the cursor. */
|
||||||
bool alerted = FALSE;
|
|
||||||
/* Whether the next important message should wait a bit. */
|
message_type lastmessage = HUSH;
|
||||||
|
/* Messages of type HUSH should not overwrite type MILD nor ALERT. */
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
int controlleft = CONTROL_LEFT;
|
int controlleft = CONTROL_LEFT;
|
||||||
|
|
|
@ -118,7 +118,7 @@ void do_help(void)
|
||||||
|
|
||||||
old_line = line;
|
old_line = line;
|
||||||
|
|
||||||
alerted = FALSE;
|
lastmessage = HUSH;
|
||||||
|
|
||||||
kbinput = get_kbinput(edit);
|
kbinput = get_kbinput(edit);
|
||||||
|
|
||||||
|
|
|
@ -2657,7 +2657,7 @@ int main(int argc, char **argv)
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
currmenu = MMAIN;
|
currmenu = MMAIN;
|
||||||
focusing = TRUE;
|
focusing = TRUE;
|
||||||
alerted = FALSE;
|
lastmessage = HUSH;
|
||||||
|
|
||||||
/* If constant cursor position display is on, and there are no
|
/* If constant cursor position display is on, and there are no
|
||||||
* keys waiting in the input buffer, display the current cursor
|
* keys waiting in the input buffer, display the current cursor
|
||||||
|
|
|
@ -56,10 +56,6 @@
|
||||||
/* Suppress warnings for __attribute__((warn_unused_result)). */
|
/* Suppress warnings for __attribute__((warn_unused_result)). */
|
||||||
#define IGNORE_CALL_RESULT(call) do { if (call) {} } while(0)
|
#define IGNORE_CALL_RESULT(call) do { if (call) {} } while(0)
|
||||||
|
|
||||||
/* Whether to beep when showing a statusbar message. */
|
|
||||||
#define ALERT TRUE
|
|
||||||
#define HUSH FALSE
|
|
||||||
|
|
||||||
/* Macros for flags, indexing each bit in a small array. */
|
/* Macros for flags, indexing each bit in a small array. */
|
||||||
#define FLAGS(flag) flags[((flag) / (sizeof(unsigned) * 8))]
|
#define FLAGS(flag) flags[((flag) / (sizeof(unsigned) * 8))]
|
||||||
#define FLAGMASK(flag) (1 << ((flag) % (sizeof(unsigned) * 8)))
|
#define FLAGMASK(flag) (1 << ((flag) % (sizeof(unsigned) * 8)))
|
||||||
|
@ -171,6 +167,10 @@ typedef enum {
|
||||||
NIX_FILE, DOS_FILE, MAC_FILE
|
NIX_FILE, DOS_FILE, MAC_FILE
|
||||||
} file_format;
|
} file_format;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HUSH, MILD, ALERT
|
||||||
|
} message_type;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OVERWRITE, APPEND, PREPEND
|
OVERWRITE, APPEND, PREPEND
|
||||||
} append_type;
|
} append_type;
|
||||||
|
|
|
@ -33,7 +33,8 @@ extern volatile sig_atomic_t sigwinch_counter;
|
||||||
extern bool meta_key;
|
extern bool meta_key;
|
||||||
extern bool func_key;
|
extern bool func_key;
|
||||||
extern bool focusing;
|
extern bool focusing;
|
||||||
extern bool alerted;
|
|
||||||
|
extern message_type lastmessage;
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
extern int controlleft;
|
extern int controlleft;
|
||||||
|
@ -787,7 +788,7 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
|
||||||
void titlebar(const char *path);
|
void titlebar(const char *path);
|
||||||
extern void set_modified(void);
|
extern void set_modified(void);
|
||||||
void statusbar(const char *msg);
|
void statusbar(const char *msg);
|
||||||
void statusline(bool sound, const char *msg, ...);
|
void statusline(message_type importance, const char *msg, ...);
|
||||||
void bottombars(int menu);
|
void bottombars(int menu);
|
||||||
void onekey(const char *keystroke, const char *desc, int length);
|
void onekey(const char *keystroke, const char *desc, int length);
|
||||||
void reset_cursor(void);
|
void reset_cursor(void);
|
||||||
|
|
25
src/winio.c
25
src/winio.c
|
@ -1121,7 +1121,7 @@ int parse_escape_sequence(WINDOW *win, int kbinput)
|
||||||
* (from the keyboard) that nano does not know about. */
|
* (from the keyboard) that nano does not know about. */
|
||||||
statusline(ALERT, _("Unknown sequence"));
|
statusline(ALERT, _("Unknown sequence"));
|
||||||
suppress_cursorpos = FALSE;
|
suppress_cursorpos = FALSE;
|
||||||
alerted = FALSE;
|
lastmessage = HUSH;
|
||||||
if (currmenu == MMAIN) {
|
if (currmenu == MMAIN) {
|
||||||
reset_cursor();
|
reset_cursor();
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
|
@ -2055,7 +2055,7 @@ void statusbar(const char *msg)
|
||||||
/* Display a message on the statusbar, and set suppress_cursorpos to
|
/* Display a message on the statusbar, and set suppress_cursorpos to
|
||||||
* TRUE, so that the message won't be immediately overwritten if
|
* TRUE, so that the message won't be immediately overwritten if
|
||||||
* constant cursor position display is on. */
|
* constant cursor position display is on. */
|
||||||
void statusline(bool sound, const char *msg, ...)
|
void statusline(message_type importance, const char *msg, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *bar, *foo;
|
char *bar, *foo;
|
||||||
|
@ -2076,18 +2076,19 @@ void statusline(bool sound, const char *msg, ...)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there already was an important message, ignore a normal one and
|
/* If there already was an alert message, ignore lesser ones. */
|
||||||
* delay another important one, to allow the earlier one to be noticed. */
|
if ((lastmessage == ALERT && importance != ALERT) ||
|
||||||
if (alerted) {
|
(lastmessage == MILD && importance == HUSH))
|
||||||
if (sound == HUSH)
|
return;
|
||||||
return;
|
|
||||||
napms(1200);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sound == ALERT) {
|
/* Delay another alert message, to allow an earlier one to be noticed. */
|
||||||
|
if (lastmessage == ALERT)
|
||||||
|
napms(1200);
|
||||||
|
|
||||||
|
if (importance == ALERT)
|
||||||
beep();
|
beep();
|
||||||
alerted = TRUE;
|
|
||||||
}
|
lastmessage = importance;
|
||||||
|
|
||||||
/* Turn the cursor off while fiddling in the statusbar. */
|
/* Turn the cursor off while fiddling in the statusbar. */
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
Loading…
Reference in New Issue