From 0a2a7290f61646704e7f0ddeb4b1f725d1c70bcb Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 19 Sep 2009 03:35:58 +0200 Subject: [PATCH] new feature: support for underlined text --- doc/config | 1 + src/helpers.h | 6 ++++++ src/window.cpp | 14 ++++++++++++++ src/window.h | 14 +++++++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/config b/doc/config index e706ed15..fc59eb81 100644 --- a/doc/config +++ b/doc/config @@ -123,6 +123,7 @@ ## After that you can put: ## ## - b - bold text +## - u - underlined text ## - r - reverse colors ## - a - use alternative character set ## diff --git a/src/helpers.h b/src/helpers.h index 9f46503f..ef5e7ceb 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -103,6 +103,9 @@ template void String2Buffer(const std::basic_string &s, basic_bu case 'b': buf << fmtBold; break; + case 'u': + buf << fmtUnderline; + break; case 'a': buf << fmtAltCharset; break; @@ -115,6 +118,9 @@ template void String2Buffer(const std::basic_string &s, basic_bu case 'b': buf << fmtBoldEnd; break; + case 'u': + buf << fmtUnderlineEnd; + break; case 'a': buf << fmtAltCharsetEnd; break; diff --git a/src/window.cpp b/src/window.cpp index 18aa8099..0c477e1c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -87,6 +87,7 @@ Window::Window(size_t startx, itsBorder(border), itsHistory(0), itsBoldCounter(0), + itsUnderlineCounter(0), itsReverseCounter(0), itsAltCharsetCounter(0) { @@ -137,6 +138,7 @@ Window::Window(const Window &w) : itsWindow(dupwin(w.itsWindow)), itsBorder(w.itsBorder), itsHistory(w.itsHistory), itsBoldCounter(w.itsBoldCounter), + itsUnderlineCounter(w.itsUnderlineCounter), itsReverseCounter(w.itsReverseCounter), itsAltCharsetCounter(w.itsAltCharsetCounter) { @@ -328,6 +330,11 @@ void Window::Bold(bool bold_state) const (bold_state ? wattron : wattroff)(itsWindow, A_BOLD); } +void Window::Underline(bool underline_state) const +{ + (underline_state ? wattron : wattroff)(itsWindow, A_UNDERLINE); +} + void Window::Reverse(bool reverse_state) const { (reverse_state ? wattron : wattroff)(itsWindow, A_REVERSE); @@ -745,6 +752,13 @@ Window &Window::operator<<(Format format) if (--itsBoldCounter <= 0) Bold((itsBoldCounter = 0)); break; + case fmtUnderline: + Underline(++itsUnderlineCounter); + break; + case fmtUnderlineEnd: + if (--itsUnderlineCounter <= 0) + Underline((itsUnderlineCounter = 0)); + break; case fmtReverse: Reverse(++itsReverseCounter); break; diff --git a/src/window.h b/src/window.h index 4ed828c0..e2a275d2 100644 --- a/src/window.h +++ b/src/window.h @@ -85,7 +85,13 @@ namespace NCurses /// Format flags used by NCurses /// - enum Format { fmtNone = 100, fmtBold, fmtBoldEnd, fmtReverse, fmtReverseEnd, fmtAltCharset, fmtAltCharsetEnd }; + enum Format { + fmtNone = clEnd+1, + fmtBold, fmtBoldEnd, + fmtUnderline, fmtUnderlineEnd, + fmtReverse, fmtReverseEnd, + fmtAltCharset, fmtAltCharsetEnd + }; /// Available border colors for window /// @@ -458,6 +464,11 @@ namespace NCurses /// void Bold(bool bold_state) const; + /// Sets state of underline attribute (internal use only) + /// @param underline_state state of underline attribute + /// + void Underline(bool underline_state) const; + /// Sets state of reverse attribute (internal use only) /// @param reverse_state state of reverse attribute /// @@ -543,6 +554,7 @@ namespace NCurses /// counters for format flags int itsBoldCounter; + int itsUnderlineCounter; int itsReverseCounter; int itsAltCharsetCounter; };