Add italic text support (#527)

This commit is contained in:
squigz
2022-02-13 18:42:13 -05:00
committed by GitHub
parent 02754534fd
commit 26ee24a938
5 changed files with 38 additions and 3 deletions

View File

@@ -215,6 +215,7 @@
## - 9 - end of current color
## - b - bold text
## - u - underline text
## - i - italic text
## - r - reverse colors
## - a - use alternative character set
##

View File

@@ -30,7 +30,8 @@ void verifyFormats(const NC::FormattedColor::Formats &formats)
if (fmt == NC::Format::NoBold
|| fmt == NC::Format::NoUnderline
|| fmt == NC::Format::NoReverse
|| fmt == NC::Format::NoAltCharset)
|| fmt == NC::Format::NoAltCharset
|| fmt == NC::Format::NoItalic)
throw std::logic_error("FormattedColor can't hold disabling formats");
}
}
@@ -71,6 +72,9 @@ std::istream &NC::operator>>(std::istream &is, NC::FormattedColor &fc)
case 'a':
formats.push_back(NC::Format::AltCharset);
break;
case 'i':
formats.push_back(NC::Format::Italic);
break;
default:
is.setstate(std::ios::failbit);
break;

View File

@@ -346,6 +346,10 @@ NC::Format reverseFormat(NC::Format fmt)
return NC::Format::NoAltCharset;
case NC::Format::NoAltCharset:
return NC::Format::AltCharset;
case NC::Format::Italic:
return NC::Format::NoItalic;
case NC::Format::NoItalic:
return NC::Format::Italic;
}
// Unreachable, silence GCC.
return fmt;
@@ -494,7 +498,8 @@ Window::Window(size_t startx, size_t starty, size_t width, size_t height,
m_bold_counter(0),
m_underline_counter(0),
m_reverse_counter(0),
m_alt_charset_counter(0)
m_alt_charset_counter(0),
m_italic_counter(0)
{
if (m_start_x > size_t(COLS)
|| m_start_y > size_t(LINES)
@@ -542,6 +547,7 @@ Window::Window(const Window &rhs)
, m_underline_counter(rhs.m_underline_counter)
, m_reverse_counter(rhs.m_reverse_counter)
, m_alt_charset_counter(rhs.m_alt_charset_counter)
, m_italic_counter(rhs.m_italic_counter)
{
setColor(m_color);
}
@@ -566,6 +572,7 @@ Window::Window(Window &&rhs)
, m_underline_counter(rhs.m_underline_counter)
, m_reverse_counter(rhs.m_reverse_counter)
, m_alt_charset_counter(rhs.m_alt_charset_counter)
, m_italic_counter(rhs.m_italic_counter)
{
rhs.m_window = nullptr;
}
@@ -591,6 +598,7 @@ Window &Window::operator=(Window rhs)
std::swap(m_underline_counter, rhs.m_underline_counter);
std::swap(m_reverse_counter, rhs.m_reverse_counter);
std::swap(m_alt_charset_counter, rhs.m_alt_charset_counter);
std::swap(m_italic_counter, rhs.m_italic_counter);
return *this;
}
@@ -780,6 +788,11 @@ void Window::altCharset(bool altcharset_state) const
(altcharset_state ? wattron : wattroff)(m_window, A_ALTCHARSET);
}
void Window::italic(bool italic_state) const
{
(italic_state ? wattron : wattroff)(m_window, A_ITALIC);
}
void Window::setTimeout(int timeout)
{
m_window_timeout = timeout;
@@ -1413,6 +1426,12 @@ Window &Window::operator<<(Format format)
case Format::NoAltCharset:
decrease_flag(*this, m_alt_charset_counter, &Window::altCharset);
break;
case Format::Italic:
increase_flag(*this, m_italic_counter, &Window::italic);
break;
case Format::NoItalic:
decrease_flag(*this, m_italic_counter, &Window::italic);
break;
}
return *this;
}

View File

@@ -200,7 +200,8 @@ enum class Format {
Bold, NoBold,
Underline, NoUnderline,
Reverse, NoReverse,
AltCharset, NoAltCharset
AltCharset, NoAltCharset,
Italic, NoItalic
};
NC::Format reverseFormat(NC::Format fmt);
@@ -531,6 +532,11 @@ private:
/// @param altcharset_state state of altcharset attribute
///
void altCharset(bool altcharset_state) const;
/// Sets state of italic attribute (internal use only)
/// @param italic_state state of italic attribute
///
void italic(bool italic_state) const;
/// pointer to helper function used by getString()
/// @see getString()
@@ -562,6 +568,7 @@ private:
int m_underline_counter;
int m_reverse_counter;
int m_alt_charset_counter;
int m_italic_counter;
};
}

View File

@@ -192,6 +192,8 @@ expressions<CharT> parseBracket(const string<CharT> &s,
result.push_back(NC::Format::AltCharset);
else if (flags & Format::Flags::Format && *it == 'r')
result.push_back(NC::Format::Reverse);
else if (flags & Format::Flags::Format && *it == 'i')
result.push_back(NC::Format::Italic);
else if (flags & Format::Flags::Format && *it == '/')
{
++it;
@@ -204,6 +206,8 @@ expressions<CharT> parseBracket(const string<CharT> &s,
result.push_back(NC::Format::NoAltCharset);
else if (*it == 'r')
result.push_back(NC::Format::NoReverse);
else if (*it == 'i')
result.push_back(NC::Format::NoItalic);
else
throwError(s, it, invalidCharacter(*it));
}