From 4d72de73b19fbbd841b77f2494481271b73f864f Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Wed, 12 Apr 2006 15:27:40 +0000 Subject: [PATCH] add the ability to use bold text instead of reverse video text, via the -D/--boldtext command line option and the "boldtext" rcfile option, and reduce USE_UTF8 to a static bool in chars.c git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3368 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 17 ++++++++++++++ doc/man/nano.1 | 5 ++++- doc/man/nanorc.5 | 5 ++++- doc/nanorc.sample | 5 ++++- doc/texinfo/nano.texi | 5 ++++- src/chars.c | 52 +++++++++++++++++++++++++++---------------- src/global.c | 2 ++ src/help.c | 2 +- src/nano.c | 20 ++++++++++++++--- src/nano.h | 2 +- src/prompt.c | 8 +++---- src/proto.h | 5 +++++ src/rcfile.c | 1 + src/winio.c | 24 ++++++++++---------- 14 files changed, 109 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f40d166..3cdc5375 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,23 @@ CVS code - - Change translator-specific comments in global.c and prompt.c so that they show up in nano.pot, and make them all consistent. (Benno Schulenberg) + - Reduce USE_UTF8 to a static bool in chars.c, allow nano.c to + set it via a function, and allow winio.c to read its value + when needed. New functions utf8_init() and using_utf8(); + changes to is_alnum_mbchar(), is_blank_mbchar(), + is_cntrl_mbchar(), is_punct_mbchar(), control_mbrep(), + mbrep(), mbwidth(), mb_cur_max(), make_mbchar(), + parse_mbchar(), mbstrncasecmp(), mbstrcasestr(), + mbrevstrcasestr(), mbstrnlen(), mbstrchr(), mbstrpbrk(), + mbrevstrpbrk(), has_blank_mbchars(), is_valid_mbstring(), + main(), display_string(), and do_credits(). (DLR) + - Add the ability to use bold text instead of reverse video + text, via the -D/--boldtext command line option and the + "boldtext" rcfile option. Changes to do_help(), usage(), + main(), update_statusbar_prompt(), do_yesno_prompt(), + titlebar(), statusbar(), onekey(), edit_draw(), + do_replace_highlight(), nano.1, nanorc.5, nano.texi, and + nanorc.sample. (DLR, suggested by Benno Schulenberg) - files.c: open_file() - Remove redundant wording in the error message when we try to diff --git a/doc/man/nano.1 b/doc/man/nano.1 index 3d57f8a7..e1db5624 100644 --- a/doc/man/nano.1 +++ b/doc/man/nano.1 @@ -7,7 +7,7 @@ .\" warranty. .\" .\" $Id$ -.TH NANO 1 "version 1.3.11" "April 5, 2006" +.TH NANO 1 "version 1.3.11" "April 12, 2006" .\" Please adjust this date whenever revising the manpage. .\" @@ -55,6 +55,9 @@ filename suffixed with a ~. Set the directory where \fBnano\fP puts unique backup files if file backups are enabled. .TP +.B \-D (\-\-boldtext) +Use bold text instead of reverse video text. +.TP .B \-E (\-\-tabstospaces) Convert typed tabs to spaces. .TP diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index 1a381f84..8271a6a1 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -7,7 +7,7 @@ .\" warranty. .\" .\" $Id$ -.TH NANORC 5 "version 1.3.11" "April 5, 2006" +.TH NANORC 5 "version 1.3.11" "April 12, 2006" .\" Please adjust this date whenever revising the manpage. .\" .SH NAME @@ -59,6 +59,9 @@ backups are enabled. .B set/unset backwards Do backwards searches by default. .TP +.B set/unset boldtext +Use bold text instead of reverse video text. +.TP .B set brackets "\fIstring\fP" Set the characters treated as closing brackets. They cannot contain blank characters. Only closing punctuation, optionally followed by diff --git a/doc/nanorc.sample b/doc/nanorc.sample index 2dca1b32..d1de3e11 100644 --- a/doc/nanorc.sample +++ b/doc/nanorc.sample @@ -26,6 +26,9 @@ ## Do backwards searches by default. # set backwards +## Use bold text instead of reverse video text. +# set boldtext + ## The characters treated as closing brackets. They cannot contain ## blank characters. Only closing punctuation, optionally followed by ## closing brackets, can end sentences. @@ -355,7 +358,7 @@ ## highlight possible errors and parameters # icolor brightwhite "^[[:space:]]*(set|unset|syntax|i?color).*$" ## set, unset and syntax -# icolor cyan "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct|quickblank)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace|wordbounds)\>" +# icolor cyan "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|boldtext|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quickblank|quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace|wordbounds)\>" # icolor green "^[[:space:]]*(set|unset|syntax)\>" ## colors # icolor yellow "^[[:space:]]*i?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" diff --git a/doc/texinfo/nano.texi b/doc/texinfo/nano.texi index 2e97124f..7f63e2fb 100644 --- a/doc/texinfo/nano.texi +++ b/doc/texinfo/nano.texi @@ -9,7 +9,7 @@ @smallbook @set EDITION 0.1 @set VERSION 1.3.10 -@set UPDATED 5 Apr 2006 +@set UPDATED 12 Apr 2006 @dircategory Editors @direntry @@ -129,6 +129,9 @@ filename suffixed with a ~. Set the directory where @code{nano} puts unique backup files if file backups are enabled. +@item -D, --boldtext +Use bold text instead of reverse video text. + @item -E, --tabstospaces Convert typed tabs to spaces. diff --git a/src/chars.c b/src/chars.c index 41eaa11f..6a872fad 100644 --- a/src/chars.c +++ b/src/chars.c @@ -34,6 +34,8 @@ #include #endif +static bool use_utf8 = FALSE; + /* Whether we've enabled UTF-8 support. */ static const wchar_t bad_wchar = 0xFFFD; /* If we get an invalid multibyte sequence, we treat it as * Unicode FFFD (Replacement Character), unless we're @@ -41,6 +43,18 @@ static const wchar_t bad_wchar = 0xFFFD; * match to it. */ static const char *bad_mbchar = "\xEF\xBF\xBD"; static const int bad_mbchar_len = 3; + +/* Enable UTF-8 support. */ +void utf8_init(void) +{ + use_utf8 = TRUE; +} + +/* Is UTF-8 support enabled? */ +bool using_utf8(void) +{ + return use_utf8; +} #endif #ifndef HAVE_ISBLANK @@ -72,7 +86,7 @@ bool is_alnum_mbchar(const char *c) assert(c != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { wchar_t wc; if (mbtowc(&wc, c, MB_CUR_MAX) < 0) { @@ -92,7 +106,7 @@ bool is_blank_mbchar(const char *c) assert(c != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { wchar_t wc; if (mbtowc(&wc, c, MB_CUR_MAX) < 0) { @@ -132,7 +146,7 @@ bool is_cntrl_mbchar(const char *c) assert(c != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { wchar_t wc; if (mbtowc(&wc, c, MB_CUR_MAX) < 0) { @@ -152,7 +166,7 @@ bool is_punct_mbchar(const char *c) assert(c != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { wchar_t wc; int c_mb_len = mbtowc(&wc, c, MB_CUR_MAX); @@ -219,7 +233,7 @@ char *control_mbrep(const char *c, char *crep, int *crep_len) assert(c != NULL && crep != NULL && crep_len != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { wchar_t wc; if (mbtowc(&wc, c, MB_CUR_MAX) < 0) { @@ -253,7 +267,7 @@ char *mbrep(const char *c, char *crep, int *crep_len) assert(c != NULL && crep != NULL && crep_len != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { wchar_t wc; /* Reject invalid Unicode characters. */ @@ -286,7 +300,7 @@ int mbwidth(const char *c) assert(c != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { wchar_t wc; int width; @@ -313,7 +327,7 @@ int mb_cur_max(void) { return #ifdef ENABLE_UTF8 - ISSET(USE_UTF8) ? MB_CUR_MAX : + use_utf8 ? MB_CUR_MAX : #endif 1; } @@ -330,7 +344,7 @@ char *make_mbchar(long chr, int *chr_mb_len) assert(chr_mb_len != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { chr_mb = charalloc(MB_CUR_MAX); *chr_mb_len = wctomb(chr_mb, (wchar_t)chr); @@ -361,7 +375,7 @@ int parse_mbchar(const char *buf, char *chr, size_t *col) assert(buf != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { /* Get the number of bytes in the multibyte character. */ buf_mb_len = mblen(buf, MB_CUR_MAX); @@ -505,7 +519,7 @@ int nstrncasecmp(const char *s1, const char *s2, size_t n) int mbstrncasecmp(const char *s1, const char *s2, size_t n) { #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { char *s1_mb = charalloc(MB_CUR_MAX); char *s2_mb = charalloc(MB_CUR_MAX); wchar_t ws1, ws2; @@ -598,7 +612,7 @@ const char *nstrcasestr(const char *haystack, const char *needle) const char *mbstrcasestr(const char *haystack, const char *needle) { #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { char *r_mb = charalloc(MB_CUR_MAX); char *q_mb = charalloc(MB_CUR_MAX); wchar_t wr, wq; @@ -704,7 +718,7 @@ const char *mbrevstrcasestr(const char *haystack, const char *needle, const char *rev_start) { #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { char *r_mb = charalloc(MB_CUR_MAX); char *q_mb = charalloc(MB_CUR_MAX); wchar_t wr, wq; @@ -792,7 +806,7 @@ size_t mbstrnlen(const char *s, size_t maxlen) assert(s != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { size_t n = 0; int s_mb_len; @@ -820,7 +834,7 @@ char *mbstrchr(const char *s, const char *c) assert(s != NULL && c != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { bool bad_s_mb = FALSE, bad_c_mb = FALSE; char *s_mb = charalloc(MB_CUR_MAX); const char *q = s; @@ -868,7 +882,7 @@ char *mbstrpbrk(const char *s, const char *accept) assert(s != NULL && accept != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { while (*s != '\0') { if (mbstrchr(accept, s) != NULL) return (char *)s; @@ -909,7 +923,7 @@ char *mbrevstrpbrk(const char *s, const char *accept, const char assert(s != NULL && accept != NULL && rev_start != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { bool begin_line = FALSE; while (!begin_line) { @@ -954,7 +968,7 @@ bool has_blank_mbchars(const char *s) assert(s != NULL); #ifdef ENABLE_UTF8 - if (ISSET(USE_UTF8)) { + if (use_utf8) { char *chr_mb = charalloc(MB_CUR_MAX); bool retval = FALSE; @@ -999,7 +1013,7 @@ bool is_valid_mbstring(const char *s) return #ifdef ENABLE_UTF8 - ISSET(USE_UTF8) ? + use_utf8 ? (mbstowcs(NULL, s, 0) != (size_t)-1) : #endif diff --git a/src/global.c b/src/global.c index 37a89db5..7ae6cfa2 100644 --- a/src/global.c +++ b/src/global.c @@ -197,6 +197,8 @@ regmatch_t regmatches[10]; * maximum, used in regular expression searches. */ #endif +int reverse_attr = A_REVERSE; + /* The curses attribute we use for reverse video. */ bool curses_ended = FALSE; /* Whether endwin() has ended curses mode and statusbar() * should hence write to stderr instead of displaying on the diff --git a/src/help.c b/src/help.c index 0d0c2c8b..6fd21388 100644 --- a/src/help.c +++ b/src/help.c @@ -54,7 +54,7 @@ void do_help(void (*refresh_func)(void)) curs_set(0); blank_edit(); - wattroff(bottomwin, A_REVERSE); + wattroff(bottomwin, reverse_attr); blank_statusbar(); /* Set help_text as the string to display. */ diff --git a/src/nano.c b/src/nano.c index 1c923999..02bd27d2 100644 --- a/src/nano.c +++ b/src/nano.c @@ -734,6 +734,8 @@ void usage(void) print1opt("-B", "--backup", N_("Save backups of existing files")); print1opt(_("-C [dir]"), _("--backupdir=[dir]"), N_("Directory for saving unique backup files")); + print1opt("-D", "--boldtext", + N_("Use bold instead of reverse video text")); print1opt("-E", "--tabstospaces", N_("Convert typed tabs to spaces")); #endif @@ -1585,6 +1587,7 @@ int main(int argc, char **argv) #ifdef HAVE_GETOPT_LONG const struct option long_options[] = { {"help", 0, NULL, 'h'}, + {"boldtext", 0, NULL, 'D'}, #ifdef ENABLE_MULTIBUFFER {"multibuffer", 0, NULL, 'F'}, #endif @@ -1651,10 +1654,10 @@ int main(int argc, char **argv) if (locale != NULL && (strcasestr(locale, "UTF8") != NULL || strcasestr(locale, "UTF-8") != NULL)) { - SET(USE_UTF8); #ifdef USE_SLANG SLutf8_enable(TRUE); #endif + utf8_init(); } } #else @@ -1676,11 +1679,11 @@ int main(int argc, char **argv) while ((optchr = #ifdef HAVE_GETOPT_LONG getopt_long(argc, argv, - "h?ABC:EFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz", + "h?ABC:DEFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz", long_options, NULL) #else getopt(argc, argv, - "h?ABC:EFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz") + "h?ABC:DEFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz") #endif ) != -1) { switch (optchr) { @@ -1702,6 +1705,11 @@ int main(int argc, char **argv) case 'C': backup_dir = mallocstrcpy(backup_dir, optarg); break; +#endif + case 'D': + SET(BOLD_TEXT); + break; +#ifndef NANO_TINY case 'E': SET(TABS_TO_SPACES); break; @@ -1930,7 +1938,13 @@ int main(int argc, char **argv) #endif #endif /* ENABLE_NANORC */ + /* If we're using bold text instead of reverse video text, set it up + * now. */ + if (ISSET(BOLD_TEXT)) + reverse_attr = A_BOLD; + #ifndef NANO_TINY + /* Set up the search/replace history. */ history_init(); #ifdef ENABLE_NANORC if (!ISSET(NO_RCFILE) && ISSET(HISTORYLOG)) diff --git a/src/nano.h b/src/nano.h index 829b8473..86a61c06 100644 --- a/src/nano.h +++ b/src/nano.h @@ -370,7 +370,7 @@ typedef struct rcoption { #define QUICK_BLANK (1<<28) #define WORD_BOUNDS (1<<29) #define NO_NEWLINES (1<<30) -#define USE_UTF8 (1<<31) +#define BOLD_TEXT (1<<31) /* Control key sequences. Changing these would be very, very bad. */ #define NANO_CONTROL_SPACE 0 diff --git a/src/prompt.c b/src/prompt.c index 276cf905..ce3edcbb 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -857,7 +857,7 @@ void update_statusbar_line(const char *curranswer, size_t index) index = strnlenpt(curranswer, index); page_start = get_statusbar_page_start(start_col, start_col + index); - wattron(bottomwin, A_REVERSE); + wattron(bottomwin, reverse_attr); blank_statusbar(); @@ -872,7 +872,7 @@ void update_statusbar_line(const char *curranswer, size_t index) reset_statusbar_cursor(); - wattroff(bottomwin, A_REVERSE); + wattroff(bottomwin, reverse_attr); } /* Put the cursor in the statusbar prompt at statusbar_x. */ @@ -1247,12 +1247,12 @@ int do_yesno_prompt(bool all, const char *msg) onekey("^C", _("Cancel"), width); } - wattron(bottomwin, A_REVERSE); + wattron(bottomwin, reverse_attr); blank_statusbar(); mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); - wattroff(bottomwin, A_REVERSE); + wattroff(bottomwin, reverse_attr); /* Refresh the edit window and the statusbar before getting * input. */ diff --git a/src/proto.h b/src/proto.h index 78caf80a..d6724726 100644 --- a/src/proto.h +++ b/src/proto.h @@ -132,6 +132,7 @@ extern regex_t search_regexp; extern regmatch_t regmatches[10]; #endif +extern int reverse_attr; extern bool curses_ended; extern char *homedir; @@ -155,6 +156,10 @@ void striponedir(char *path); #endif /* Public functions in chars.c. */ +#ifdef ENABLE_UTF8 +void utf8_init(void); +bool using_utf8(void); +#endif #ifndef HAVE_ISBLANK bool nisblank(int c); #endif diff --git a/src/rcfile.c b/src/rcfile.c index c988a905..97762ecc 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -33,6 +33,7 @@ #ifdef ENABLE_NANORC const static rcoption rcopts[] = { + {"boldtext", BOLD_TEXT}, #ifndef DISABLE_JUSTIFY {"brackets", 0}, #endif diff --git a/src/winio.c b/src/winio.c index f2f98ddb..d922de20 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1857,7 +1857,7 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool } } #ifdef ENABLE_UTF8 - else if (ISSET(USE_UTF8) && mbwidth(buf_mb) > 1) { + else if (using_utf8() && mbwidth(buf_mb) > 1) { converted[index++] = ' '; start_col++; @@ -1992,7 +1992,7 @@ void titlebar(const char *path) assert(path != NULL || openfile->filename != NULL); - wattron(topwin, A_REVERSE); + wattron(topwin, reverse_attr); blank_titlebar(); /* space has to be at least 4: two spaces before the version message, @@ -2117,7 +2117,7 @@ void titlebar(const char *path) } } - wattroff(topwin, A_REVERSE); + wattroff(topwin, reverse_attr); wnoutrefresh(topwin); reset_cursor(); @@ -2176,12 +2176,12 @@ void statusbar(const char *msg, ...) start_x = (COLS - foo_len - 4) / 2; wmove(bottomwin, 0, start_x); - wattron(bottomwin, A_REVERSE); + wattron(bottomwin, reverse_attr); waddstr(bottomwin, "[ "); waddstr(bottomwin, foo); free(foo); waddstr(bottomwin, " ]"); - wattroff(bottomwin, A_REVERSE); + wattroff(bottomwin, reverse_attr); wnoutrefresh(bottomwin); reset_cursor(); wnoutrefresh(edit); @@ -2266,9 +2266,9 @@ void onekey(const char *keystroke, const char *desc, size_t len) assert(keystroke != NULL && desc != NULL); - wattron(bottomwin, A_REVERSE); + wattron(bottomwin, reverse_attr); waddnstr(bottomwin, keystroke, actual_x(keystroke, len)); - wattroff(bottomwin, A_REVERSE); + wattroff(bottomwin, reverse_attr); if (len > keystroke_len) len -= keystroke_len; @@ -2626,10 +2626,10 @@ void edit_draw(const filestruct *fileptr, const char *converted, int if (paintlen > 0) paintlen = actual_x(converted + index, paintlen); - wattron(edit, A_REVERSE); + wattron(edit, reverse_attr); mvwaddnstr(edit, line, x_start, converted + index, paintlen); - wattroff(edit, A_REVERSE); + wattroff(edit, reverse_attr); } } #endif /* !NANO_TINY */ @@ -3052,7 +3052,7 @@ void do_replace_highlight(bool highlight, const char *word) reset_cursor(); if (highlight) - wattron(edit, A_REVERSE); + wattron(edit, reverse_attr); #ifdef HAVE_REGEX_H /* This is so we can show zero-length regexes. */ @@ -3066,7 +3066,7 @@ void do_replace_highlight(bool highlight, const char *word) waddch(edit, '$'); if (highlight) - wattroff(edit, A_REVERSE); + wattroff(edit, reverse_attr); } #ifdef NANO_EXTRA @@ -3154,7 +3154,7 @@ void do_credits(void) * Small Letter O with Diaresis) if applicable. */ credits[15] = #ifdef ENABLE_UTF8 - ISSET(USE_UTF8) ? "Florian K\xC3\xB6nig" : + using_utf8() ? "Florian K\xC3\xB6nig" : #endif "Florian K\xF6nig"; -- 2.39.5