[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH] statusbar: prevent error messages from overwriting
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH] statusbar: prevent error messages from overwriting each other |
Date: |
Sat, 30 Apr 2016 17:52:39 +0200 |
If during startup there are multiple error messages, currently only
the last of them is readable. To improve on that, introduce a short
pause between error messages -- it's maybe not enough to read them all,
but at least the user will be aware that there are multiple ones.
---
src/browser.c | 22 ++++-----
src/color.c | 6 +--
src/files.c | 150 +++++++++++++++++++++++++++++-----------------------------
src/global.c | 2 +
src/nano.c | 4 +-
src/nano.h | 4 ++
src/proto.h | 4 +-
src/search.c | 6 +--
src/text.c | 33 ++++++-------
src/winio.c | 23 ++++++++-
10 files changed, 141 insertions(+), 113 deletions(-)
diff --git a/src/browser.c b/src/browser.c
index 974b643..9362fa8 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -113,6 +113,7 @@ char *do_browser(char *path, DIR *dir)
/* Make sure that the cursor is off. */
curs_set(0);
+ alerted = FALSE;
#ifndef NANO_TINY
if (kbinput == KEY_WINCH) {
@@ -241,8 +242,8 @@ char *do_browser(char *path, DIR *dir)
if (check_operating_dir(new_path, FALSE)) {
/* TRANSLATORS: This refers to the option --operatingdir,
* not to --restricted. */
- statusbar(_("Can't go outside of %s in confined mode"),
- operating_dir);
+ statusline(ALERT, _("Can't go outside of %s "
+ "in confined mode"), operating_dir);
free(new_path);
continue;
}
@@ -252,9 +253,8 @@ char *do_browser(char *path, DIR *dir)
if (dir == NULL) {
/* We can't open this directory for some reason.
* Complain. */
- statusbar(_("Error reading %s: %s"), answer,
+ statusline(ALERT, _("Error reading %s: %s"), answer,
strerror(errno));
- beep();
free(new_path);
continue;
}
@@ -278,8 +278,7 @@ char *do_browser(char *path, DIR *dir)
} else if (func == do_enter) {
/* We can't move up from "/". */
if (strcmp(filelist[selected], "/..") == 0) {
- statusbar(_("Can't move up a directory"));
- beep();
+ statusline(ALERT, _("Can't move up a directory"));
continue;
}
@@ -288,9 +287,8 @@ char *do_browser(char *path, DIR *dir)
* directory if it's ".." or if it's a symlink to a
* directory outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE)) {
- statusbar(_("Can't go outside of %s in confined mode"),
- operating_dir);
- beep();
+ statusline(ALERT, _("Can't go outside of %s "
+ "in confined mode"), operating_dir);
continue;
}
#endif
@@ -298,9 +296,8 @@ char *do_browser(char *path, DIR *dir)
if (stat(filelist[selected], &st) == -1) {
/* We can't open this file for some reason.
* Complain. */
- statusbar(_("Error reading %s: %s"),
+ statusline(ALERT, _("Error reading %s: %s"),
filelist[selected], strerror(errno));
- beep();
continue;
}
@@ -314,9 +311,8 @@ char *do_browser(char *path, DIR *dir)
dir = opendir(filelist[selected]);
if (dir == NULL) {
- statusbar(_("Error reading %s: %s"),
+ statusline(ALERT, _("Error reading %s: %s"),
filelist[selected], strerror(errno));
- beep();
continue;
}
diff --git a/src/color.c b/src/color.c
index 8b173d7..3362b56 100644
--- a/src/color.c
+++ b/src/color.c
@@ -183,7 +183,7 @@ void color_update(void)
}
if (sint == NULL)
- statusbar(_("Unknown syntax name: %s"), syntaxstr);
+ statusline(ALERT, _("Unknown syntax name: %s"), syntaxstr);
}
/* If no syntax-override string was specified, or it didn't match,
@@ -241,11 +241,11 @@ void color_update(void)
#endif
MAGIC_ERROR);
if (cookie == NULL || magic_load(cookie, NULL) < 0)
- statusbar(_("magic_load() failed: %s"), strerror(errno));
+ statusline(ALERT, _("magic_load() failed: %s"),
strerror(errno));
else {
magicstring = magic_file(cookie, openfile->filename);
if (magicstring == NULL)
- statusbar(_("magic_file(%s) failed: %s"),
+ statusline(ALERT, _("magic_file(%s) failed: %s"),
openfile->filename, magic_error(cookie));
#ifdef DEBUG
fprintf(stderr, "Returned magic string is: %s\n", magicstring);
diff --git a/src/files.c b/src/files.c
index 08c9fd6..9375262 100644
--- a/src/files.c
+++ b/src/files.c
@@ -44,21 +44,18 @@ bool has_valid_path(const char *filename)
if (stat(parentdir, &parentinfo) == -1) {
if (errno == ENOENT)
- statusbar(_("Directory '%s' does not exist"), parentdir);
+ statusline(ALERT, _("Directory '%s' does not exist"), parentdir);
else
- statusbar(_("Path '%s': %s"), parentdir, strerror(errno));
+ statusline(ALERT, _("Path '%s': %s"), parentdir, strerror(errno));
} else if (!S_ISDIR(parentinfo.st_mode))
- statusbar(_("Path '%s' is not a directory"), parentdir);
+ statusline(ALERT, _("Path '%s' is not a directory"), parentdir);
else if (access(parentdir, X_OK) == -1)
- statusbar(_("Path '%s' is not accessible"), parentdir);
+ statusline(ALERT, _("Path '%s' is not accessible"), parentdir);
else
validity = TRUE;
free(namecopy);
- if (!validity)
- beep();
-
return validity;
}
@@ -196,7 +193,8 @@ int write_lockfile(const char *lockfilename, const char
*origfilename, bool modi
if (errno == ENAMETOOLONG)
myhostname[31] = '\0';
else {
- statusbar(_("Couldn't determine hostname for lock file: %s"),
strerror(errno));
+ statusline(HUSH, _("Couldn't determine hostname for lock file: %s"),
+ strerror(errno));
goto free_and_fail;
}
}
@@ -217,8 +215,8 @@ int write_lockfile(const char *lockfilename, const char
*origfilename, bool modi
/* Maybe we just don't have write access. Print an error message
* and continue. */
if (fd < 0) {
- statusbar(_("Error writing lock file %s: %s"), lockfilename,
- strerror(errno));
+ statusline(HUSH, _("Error writing lock file %s: %s"),
+ lockfilename, strerror(errno));
free(lockdata);
return 0;
}
@@ -228,7 +226,7 @@ int write_lockfile(const char *lockfilename, const char
*origfilename, bool modi
filestream = fdopen(fd, "wb");
if (fd < 0 || filestream == NULL) {
- statusbar(_("Error writing lock file %s: %s"), lockfilename,
+ statusline(HUSH, _("Error writing lock file %s: %s"), lockfilename,
strerror(errno));
goto free_and_fail;
}
@@ -265,7 +263,7 @@ int write_lockfile(const char *lockfilename, const char
*origfilename, bool modi
wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream);
if (wroteamt < lockdatalen) {
- statusbar(_("Error writing lock file %s: %s"),
+ statusline(HUSH, _("Error writing lock file %s: %s"),
lockfilename, ferror(filestream));
goto free_and_fail;
}
@@ -275,7 +273,7 @@ int write_lockfile(const char *lockfilename, const char
*origfilename, bool modi
#endif
if (fclose(filestream) == EOF) {
- statusbar(_("Error writing lock file %s: %s"),
+ statusline(HUSH, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno));
goto free_and_fail;
}
@@ -295,7 +293,7 @@ int write_lockfile(const char *lockfilename, const char
*origfilename, bool modi
int delete_lockfile(const char *lockfilename)
{
if (unlink(lockfilename) < 0 && errno != ENOENT) {
- statusbar(_("Error deleting lock file %s: %s"), lockfilename,
+ statusline(HUSH, _("Error deleting lock file %s: %s"), lockfilename,
strerror(errno));
return -1;
}
@@ -330,7 +328,7 @@ int do_lockfile(const char *filename)
int room, ans;
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
- statusbar(_("Error opening lock file %s: %s"),
+ statusline(HUSH, _("Error opening lock file %s: %s"),
lockfilename, strerror(errno));
goto free_the_name;
}
@@ -342,8 +340,8 @@ int do_lockfile(const char *filename)
} while (readamt > 0 && readtot < LOCKBUFSIZE);
if (readtot < 48) {
- statusbar(_("Error reading lock file %s: Not enough data read"),
- lockfilename);
+ statusline(HUSH, _("Error reading lock file %s: "
+ "Not enough data read"), lockfilename);
free(lockbuf);
goto free_the_name;
}
@@ -427,8 +425,8 @@ bool open_buffer(const char *filename, bool undoable)
#ifndef DISABLE_OPERATINGDIR
if (check_operating_dir(filename, FALSE)) {
- statusbar(_("Can't insert file from outside of %s"),
- operating_dir);
+ statusline(ALERT, _("Can't insert file from outside of %s"),
+ operating_dir);
return FALSE;
}
#endif
@@ -442,10 +440,9 @@ bool open_buffer(const char *filename, bool undoable)
if (stat(realname, &fileinfo) == 0 && !S_ISREG(fileinfo.st_mode)) {
if (S_ISDIR(fileinfo.st_mode))
- statusbar(_("\"%s\" is a directory"), realname);
+ statusline(ALERT, _("\"%s\" is a directory"), realname);
else
- statusbar(_("\"%s\" is not a normal file"), realname);
- beep();
+ statusline(ALERT, _("\"%s\" is not a normal file"), realname);
free(realname);
return FALSE;
}
@@ -591,7 +588,7 @@ void switch_to_prevnext_buffer(bool to_next, bool quiet)
/* Indicate the switch on the statusbar. */
if (!quiet)
- statusbar(_("Switched to %s"),
+ statusline(HUSH, _("Switched to %s"),
((openfile->filename[0] == '\0') ?
_("New Buffer") : openfile->filename));
@@ -916,41 +913,48 @@ void read_file(FILE *f, int fd, const char *filename,
bool undoable, bool checkw
if (format == 3) {
if (writable)
- statusbar(P_("Read %lu line (Converted from DOS and Mac format)",
+ statusline(HUSH,
+ P_("Read %lu line (Converted from DOS and Mac format)",
"Read %lu lines (Converted from DOS and Mac format)",
(unsigned long)num_lines), (unsigned long)num_lines);
else
/* TRANSLATORS: Keep the next handful of messages at most 76
characters long. */
- statusbar(P_("Read %lu line (Converted from DOS and Mac format - NO
write permission)",
+ statusline(ALERT,
+ P_("Read %lu line (Converted from DOS and Mac format - NO write
permission)",
"Read %lu lines (Converted from DOS and Mac format - NO write
permission)",
(unsigned long)num_lines), (unsigned long)num_lines);
} else if (format == 2) {
openfile->fmt = MAC_FILE;
if (writable)
- statusbar(P_("Read %lu line (Converted from Mac format)",
+ statusline(HUSH,
+ P_("Read %lu line (Converted from Mac format)",
"Read %lu lines (Converted from Mac format)",
(unsigned long)num_lines), (unsigned long)num_lines);
else
- statusbar(P_("Read %lu line (Converted from Mac format - Warning:
No write permission)",
+ statusline(ALERT,
+ P_("Read %lu line (Converted from Mac format - Warning: No
write permission)",
"Read %lu lines (Converted from Mac format - Warning: No write
permission)",
(unsigned long)num_lines), (unsigned long)num_lines);
} else if (format == 1) {
openfile->fmt = DOS_FILE;
if (writable)
- statusbar(P_("Read %lu line (Converted from DOS format)",
+ statusline(HUSH,
+ P_("Read %lu line (Converted from DOS format)",
"Read %lu lines (Converted from DOS format)",
(unsigned long)num_lines), (unsigned long)num_lines);
else
- statusbar(P_("Read %lu line (Converted from DOS format - Warning:
No write permission)",
+ statusline(ALERT,
+ P_("Read %lu line (Converted from DOS format - Warning: No
write permission)",
"Read %lu lines (Converted from DOS format - Warning: No write
permission)",
(unsigned long)num_lines), (unsigned long)num_lines);
} else
#endif
if (writable)
- statusbar(P_("Read %lu line", "Read %lu lines",
+ statusline(HUSH, P_("Read %lu line", "Read %lu lines",
(unsigned long)num_lines), (unsigned long)num_lines);
else
- statusbar(P_("Read %lu line (Warning: No write permission)",
+ statusline(ALERT,
+ P_("Read %lu line (Warning: No write permission)",
"Read %lu lines (Warning: No write permission)",
(unsigned long)num_lines), (unsigned long)num_lines);
@@ -1001,8 +1005,7 @@ int open_file(const char *filename, bool newfie, bool
quiet, FILE **f)
statusbar(_("New File"));
return -2;
}
- statusbar(_("File \"%s\" not found"), filename);
- beep();
+ statusline(ALERT, _("File \"%s\" not found"), filename);
return -1;
} else if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
S_ISBLK(fileinfo.st_mode)) {
@@ -1010,23 +1013,20 @@ int open_file(const char *filename, bool newfie, bool
quiet, FILE **f)
/* Don't open directories, character files, or block files.
* Sorry, /dev/sndstat! */
- statusbar(S_ISDIR(fileinfo.st_mode) ?
+ statusline(ALERT, S_ISDIR(fileinfo.st_mode) ?
_("\"%s\" is a directory") :
_("\"%s\" is a device file"), filename);
- beep();
return -1;
} else if ((fd = open(full_filename, O_RDONLY)) == -1) {
free(full_filename);
- statusbar(_("Error reading %s: %s"), filename, strerror(errno));
- beep();
+ statusline(ALERT, _("Error reading %s: %s"), filename, strerror(errno));
return -1;
} else {
/* The file is A-OK. Open it. */
*f = fdopen(fd, "rb");
if (*f == NULL) {
- statusbar(_("Error reading %s: %s"), filename, strerror(errno));
- beep();
+ statusline(ALERT, _("Error reading %s: %s"), filename,
strerror(errno));
close(fd);
} else
statusbar(_("Reading File"));
@@ -1776,7 +1776,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
/* If we're writing a temporary file, we're probably going outside
* the operating directory, so skip the operating directory test. */
if (!tmp && check_operating_dir(realname, FALSE)) {
- statusbar(_("Can't write outside of %s"), operating_dir);
+ statusline(ALERT, _("Can't write outside of %s"), operating_dir);
goto cleanup_and_exit;
}
#endif
@@ -1820,9 +1820,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
f = fopen(realname, "rb");
if (f == NULL) {
- statusbar(_("Error reading %s: %s"), realname,
+ statusline(ALERT, _("Error reading %s: %s"), realname,
strerror(errno));
- beep();
/* If we can't read from the original file, go on, since
* only saving the original file is better than saving
* nothing. */
@@ -1860,8 +1859,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
free(backuptemp);
backuptemp = get_next_filename(backupname, "~");
if (*backuptemp == '\0') {
- statusbar(_("Error writing backup file %s: %s"), backupname,
- _("Too many backup files?"));
+ statusline(HUSH, _("Error writing backup file %s: %s"),
+ backupname, _("Too many backup files?"));
free(backuptemp);
free(backupname);
/* If we can't write to the backup, DON'T go on, since
@@ -1885,8 +1884,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
if (unlink(backupname) < 0 && errno != ENOENT &&
!ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
- statusbar(_("Error writing backup file %s: %s"), backupname,
- strerror(errno));
+ statusline(HUSH, _("Error writing backup file %s: %s"),
+ backupname, strerror(errno));
free(backupname);
goto cleanup_and_exit;
}
@@ -1903,8 +1902,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
backup_file = fdopen(backup_fd, "wb");
if (backup_fd < 0 || backup_file == NULL) {
- statusbar(_("Error writing backup file %s: %s"), backupname,
- strerror(errno));
+ statusline(HUSH, _("Error writing backup file %s: %s"),
+ backupname, strerror(errno));
free(backupname);
goto cleanup_and_exit;
}
@@ -1916,8 +1915,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
&& !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
- statusbar(_("Error writing backup file %s: %s"), backupname,
- strerror(errno));
+ statusline(HUSH, _("Error writing backup file %s: %s"),
+ backupname, strerror(errno));
free(backupname);
fclose(backup_file);
goto cleanup_and_exit;
@@ -1927,8 +1926,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
&& !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
- statusbar(_("Error writing backup file %s: %s"), backupname,
- strerror(errno));
+ statusline(HUSH, _("Error writing backup file %s: %s"),
+ backupname, strerror(errno));
free(backupname);
fclose(backup_file);
/* If we can't write to the backup, DONT go on, since
@@ -1946,9 +1945,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
copy_status = copy_file(f, backup_file);
if (copy_status != 0) {
- statusbar(_("Error reading %s: %s"), realname,
+ statusline(ALERT, _("Error reading %s: %s"), realname,
strerror(errno));
- beep();
goto cleanup_and_exit;
}
@@ -1956,8 +1954,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
if (utime(backupname, &filetime) == -1 && !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
- statusbar(_("Error writing backup file %s: %s"), backupname,
- strerror(errno));
+ statusline(HUSH, _("Error writing backup file %s: %s"),
+ backupname, strerror(errno));
/* If we can't write to the backup, DON'T go on, since
* whatever caused the backup file to fail (e.g. disk full
* may well cause the real file write to fail, which means
@@ -1991,9 +1989,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
f = fopen(realname, "rb");
if (f == NULL) {
- statusbar(_("Error reading %s: %s"), realname,
+ statusline(ALERT, _("Error reading %s: %s"), realname,
strerror(errno));
- beep();
goto cleanup_and_exit;
}
}
@@ -2001,7 +1998,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
tempname = safe_tempfile(&f);
if (tempname == NULL) {
- statusbar(_("Error writing temp file: %s"), strerror(errno));
+ statusline(HUSH, _("Error writing temp file: %s"),
+ strerror(errno));
goto cleanup_and_exit;
}
@@ -2011,9 +2009,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
if (fd_source != -1) {
f_source = fdopen(fd_source, "rb");
if (f_source == NULL) {
- statusbar(_("Error reading %s: %s"), realname,
+ statusline(ALERT, _("Error reading %s: %s"), realname,
strerror(errno));
- beep();
close(fd_source);
fclose(f);
unlink(tempname);
@@ -2023,7 +2020,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
}
if (f_source == NULL || copy_file(f_source, f) != 0) {
- statusbar(_("Error writing %s: %s"), tempname, strerror(errno));
+ statusline(HUSH, _("Error writing %s: %s"), tempname,
+ strerror(errno));
unlink(tempname);
goto cleanup_and_exit;
}
@@ -2041,7 +2039,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
/* If we couldn't open the file, give up. */
if (fd == -1) {
- statusbar(_("Error writing %s: %s"), realname, strerror(errno));
+ statusline(HUSH, _("Error writing %s: %s"), realname,
+ strerror(errno));
if (tempname != NULL)
unlink(tempname);
goto cleanup_and_exit;
@@ -2050,7 +2049,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
f = fdopen(fd, (append == APPEND) ? "ab" : "wb");
if (f == NULL) {
- statusbar(_("Error writing %s: %s"), realname, strerror(errno));
+ statusline(HUSH, _("Error writing %s: %s"), realname,
+ strerror(errno));
close(fd);
goto cleanup_and_exit;
}
@@ -2073,7 +2073,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
unsunder(fileptr->data, data_len);
if (size < data_len) {
- statusbar(_("Error writing %s: %s"), realname, strerror(errno));
+ statusline(HUSH, _("Error writing %s: %s"), realname,
+ strerror(errno));
fclose(f);
goto cleanup_and_exit;
}
@@ -2089,7 +2090,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
#ifndef NANO_TINY
if (openfile->fmt == DOS_FILE || openfile->fmt == MAC_FILE) {
if (putc('\r', f) == EOF) {
- statusbar(_("Error writing %s: %s"), realname,
+ statusline(HUSH, _("Error writing %s: %s"), realname,
strerror(errno));
fclose(f);
goto cleanup_and_exit;
@@ -2099,7 +2100,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
if (openfile->fmt != MAC_FILE)
#endif
if (putc('\n', f) == EOF) {
- statusbar(_("Error writing %s: %s"), realname,
+ statusline(HUSH, _("Error writing %s: %s"), realname,
strerror(errno));
fclose(f);
goto cleanup_and_exit;
@@ -2124,20 +2125,22 @@ bool write_file(const char *name, FILE *f_open, bool
tmp, append_type
}
if (f_source == NULL) {
- statusbar(_("Error reading %s: %s"), tempname, strerror(errno));
- beep();
+ statusline(ALERT, _("Error reading %s: %s"), tempname,
+ strerror(errno));
fclose(f);
goto cleanup_and_exit;
}
if (copy_file(f_source, f) == -1) {
- statusbar(_("Error writing %s: %s"), realname, strerror(errno));
+ statusline(HUSH, _("Error writing %s: %s"), realname,
+ strerror(errno));
goto cleanup_and_exit;
}
unlink(tempname);
} else if (fclose(f) != 0) {
- statusbar(_("Error writing %s: %s"), realname, strerror(errno));
+ statusline(HUSH, _("Error writing %s: %s"), realname,
+ strerror(errno));
goto cleanup_and_exit;
}
@@ -2164,9 +2167,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
append_type
stat_with_alloc(realname, &openfile->current_stat);
#endif
- statusbar(P_("Wrote %lu line", "Wrote %lu lines",
- (unsigned long)lineswritten),
- (unsigned long)lineswritten);
+ statusline(HUSH, P_("Wrote %lu line", "Wrote %lu lines",
+ (unsigned long)lineswritten), (unsigned long)lineswritten);
openfile->modified = FALSE;
titlebar(NULL);
}
diff --git a/src/global.c b/src/global.c
index 37de038..eb2e0f4 100644
--- a/src/global.c
+++ b/src/global.c
@@ -39,6 +39,8 @@ bool func_key;
/* Whether the current keystroke is an extended keypad value. */
bool focusing = FALSE;
/* Whether an update of the edit window should center the cursor. */
+bool alerted = FALSE;
+ /* Whether the next important message should wait a bit. */
#ifndef NANO_TINY
int controlleft = CONTROL_LEFT;
diff --git a/src/nano.c b/src/nano.c
index f7ef4a1..678da43 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1453,7 +1453,8 @@ void do_toggle(int flag)
)
enabled = !enabled;
- statusbar("%s %s", _(flagtostr(flag)), enabled ? _("enabled") :
_("disabled"));
+ statusline(HUSH, "%s %s", _(flagtostr(flag)),
+ enabled ? _("enabled") : _("disabled"));
}
#endif /* !NANO_TINY */
@@ -2638,6 +2639,7 @@ int main(int argc, char **argv)
while (TRUE) {
currmenu = MMAIN;
focusing = FALSE;
+ alerted = FALSE;
/* If constant cursor position display is on, and there are no
* keys waiting in the input buffer, display the current cursor
diff --git a/src/nano.h b/src/nano.h
index 7a9e008..7140728 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -56,6 +56,10 @@
/* Suppress warnings for __attribute__((warn_unused_result)). */
#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. */
#define FLAGS(flag) flags[((flag) / (sizeof(unsigned) * 8))]
#define FLAGMASK(flag) (1 << ((flag) % (sizeof(unsigned) * 8)))
diff --git a/src/proto.h b/src/proto.h
index 6ad900b..55040e8 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -33,6 +33,7 @@ extern volatile sig_atomic_t sigwinch_counter;
extern bool meta_key;
extern bool func_key;
extern bool focusing;
+extern bool alerted;
#ifndef NANO_TINY
extern int controlleft;
@@ -784,7 +785,8 @@ char *display_string(const char *buf, size_t start_col,
size_t len, bool
dollars);
void titlebar(const char *path);
extern void set_modified(void);
-void statusbar(const char *msg, ...);
+void statusbar(const char *msg);
+void statusline(bool sound, const char *msg, ...);
void bottombars(int menu);
void onekey(const char *keystroke, const char *desc, int length);
void reset_cursor(void);
diff --git a/src/search.c b/src/search.c
index dd0c1b2..b5beb3d 100644
--- a/src/search.c
+++ b/src/search.c
@@ -58,7 +58,7 @@ bool regexp_init(const char *regexp)
char *str = charalloc(len);
regerror(rc, &search_regexp, str, len);
- statusbar(_("Bad regex \"%s\": %s"), regexp, str);
+ statusline(ALERT, _("Bad regex \"%s\": %s"), regexp, str);
free(str);
return FALSE;
@@ -92,7 +92,7 @@ void not_found_msg(const char *str)
disp = display_string(str, 0, (COLS / 2) + 1, FALSE);
numchars = actual_x(disp, mbstrnlen(disp, COLS / 2));
- statusbar(_("\"%.*s%s\" not found"), numchars, disp,
+ statusline(HUSH, _("\"%.*s%s\" not found"), numchars, disp,
(disp[numchars] == '\0') ? "" : "...");
free(disp);
@@ -861,7 +861,7 @@ void do_replace(void)
edit_refresh();
if (numreplaced >= 0)
- statusbar(P_("Replaced %lu occurrence",
+ statusline(HUSH, P_("Replaced %lu occurrence",
"Replaced %lu occurrences", (unsigned long)numreplaced),
(unsigned long)numreplaced);
diff --git a/src/text.c b/src/text.c
index 00a2be1..29cc6e7 100644
--- a/src/text.c
+++ b/src/text.c
@@ -488,7 +488,7 @@ void do_undo(void)
filestruct *f = fsfromline(u->mark_begin_lineno);
if (!f) {
- statusbar(_("Internal error: can't match line %d. "
+ statusline(ALERT, _("Internal error: can't match line %d. "
"Please save your work."), u->mark_begin_lineno);
return;
}
@@ -608,7 +608,7 @@ void do_undo(void)
}
if (undidmsg)
- statusbar(_("Undid action (%s)"), undidmsg);
+ statusline(HUSH, _("Undid action (%s)"), undidmsg);
renumber(f);
openfile->current_undo = openfile->current_undo->next;
@@ -641,7 +641,7 @@ void do_redo(void)
filestruct *f = fsfromline(u->type == INSERT ? 1 : u->mark_begin_lineno);
if (!f) {
- statusbar(_("Internal error: can't match line %d. "
+ statusline(ALERT, _("Internal error: can't match line %d. "
"Please save your work."), u->mark_begin_lineno);
return;
}
@@ -744,7 +744,7 @@ void do_redo(void)
}
if (redidmsg)
- statusbar(_("Redid action (%s)"), redidmsg);
+ statusline(HUSH, _("Redid action (%s)"), redidmsg);
openfile->current_undo = u;
openfile->last_action = OTHER;
@@ -1860,7 +1860,7 @@ bool find_paragraph(size_t *const quote, size_t *const
par)
#ifdef HAVE_REGEX_H
if (quoterc != 0) {
- statusbar(_("Bad quote string %s: %s"), quotestr, quoteerr);
+ statusline(ALERT, _("Bad quote string %s: %s"), quotestr, quoteerr);
return FALSE;
}
#endif
@@ -2862,7 +2862,7 @@ void do_spell(void)
temp = safe_tempfile(&temp_file);
if (temp == NULL) {
- statusbar(_("Error writing temp file: %s"), strerror(errno));
+ statusline(QUIET, _("Error writing temp file: %s"), strerror(errno));
return;
}
@@ -2874,7 +2874,7 @@ void do_spell(void)
write_file(temp, temp_file, TRUE, OVERWRITE, FALSE);
if (!status) {
- statusbar(_("Error writing temp file: %s"), strerror(errno));
+ statusline(QUIET, _("Error writing temp file: %s"), strerror(errno));
free(temp);
return;
}
@@ -2896,10 +2896,10 @@ void do_spell(void)
if (spell_msg != NULL) {
if (errno == 0)
/* Don't display an error message of "Success". */
- statusbar(_("Spell checking failed: %s"), spell_msg);
+ statusline(ALERT, _("Spell checking failed: %s"), spell_msg);
else
- statusbar(_("Spell checking failed: %s: %s"), spell_msg,
- strerror(errno));
+ statusline(ALERT, _("Spell checking failed: %s: %s"), spell_msg,
+ strerror(errno));
} else
statusbar(_("Finished checking spelling"));
}
@@ -3103,7 +3103,8 @@ void do_linter(void)
free(read_buff);
if (parsesuccess == 0) {
- statusbar(_("Got 0 parsable lines from command: %s"),
openfile->syntax->linter);
+ statusline(HUSH, _("Got 0 parsable lines from command: %s"),
+ openfile->syntax->linter);
goto exit_from_lint;
}
@@ -3242,7 +3243,7 @@ void do_formatter(void)
temp = safe_tempfile(&temp_file);
if (temp == NULL) {
- statusbar(_("Error writing temp file: %s"), strerror(errno));
+ statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
return;
}
@@ -3251,7 +3252,7 @@ void do_formatter(void)
status = write_file(temp, temp_file, TRUE, OVERWRITE, FALSE);
if (!status) {
- statusbar(_("Error writing temp file: %s"), strerror(errno));
+ statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
free(temp);
return;
}
@@ -3394,9 +3395,9 @@ void do_wordlinechar_count(void)
openfile->placewewant = pww_save;
/* Display the total word, line, and character counts on the statusbar. */
- statusbar(_("%sWords: %lu Lines: %ld Chars: %lu"), old_mark_set ?
- _("In Selection: ") : "", (unsigned long)words, (long)nlines,
- (unsigned long)chars);
+ statusline(HUSH, _("%sWords: %lu Lines: %ld Chars: %lu"), old_mark_set ?
+ _("In Selection: ") : "", (unsigned long)words, (long)nlines,
+ (unsigned long)chars);
}
#endif /* !NANO_TINY */
diff --git a/src/winio.c b/src/winio.c
index 7881ee9..02853df 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2105,10 +2105,16 @@ void titlebar(const char *path)
wnoutrefresh(edit);
}
+/* Display a normal message on the statusbar. */
+void statusbar(const char *msg)
+{
+ statusline(HUSH, msg);
+}
+
/* Display a message on the statusbar, and set disable_cursorpos to
* TRUE, so that the message won't be immediately overwritten if
* constant cursor position display is on. */
-void statusbar(const char *msg, ...)
+void statusline(bool sound, const char *msg, ...)
{
va_list ap;
char *bar, *foo;
@@ -2129,6 +2135,19 @@ void statusbar(const char *msg, ...)
return;
}
+ /* If there already was an important message, ignore a normal one and
+ * delay another important one, to allow the earlier one to be noticed. */
+ if (alerted) {
+ if (sound == HUSH)
+ return;
+ napms(1200);
+ }
+
+ if (sound == ALERT) {
+ beep();
+ alerted = TRUE;
+ }
+
/* Turn the cursor off while fiddling in the statusbar. */
curs_set(0);
@@ -3148,7 +3167,7 @@ void do_cursorpos(bool constant)
colpct = 100 * cur_xpt / cur_lenpt;
charpct = (openfile->totsize == 0) ? 0 : 100 * i / openfile->totsize;
- statusbar(
+ statusline(HUSH,
_("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
(long)openfile->current->lineno,
(long)openfile->filebot->lineno, linepct,
--
2.8.1
- [Nano-devel] [PATCH] statusbar: prevent error messages from overwriting each other,
Benno Schulenberg <=