Terminal: Fix some missing text attributes

Probably doesn't actually change much yet since we don't support many
text rendering options, but it's at least good to have the options, and
to record things we don't yet support too.
This commit is contained in:
Robin Burchell 2019-05-29 21:10:08 +02:00 committed by Andreas Kling
parent 96db775ac1
commit 004a630bfe
2 changed files with 66 additions and 7 deletions

View file

@ -16,6 +16,8 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
//#define TERMINAL_DEBUG //#define TERMINAL_DEBUG
byte Terminal::Attribute::default_foreground_color = 7;
byte Terminal::Attribute::default_background_color = 0;
Terminal::Terminal(int ptm_fd, RetainPtr<CConfigFile> config) Terminal::Terminal(int ptm_fd, RetainPtr<CConfigFile> config)
: m_ptm_fd(ptm_fd) : m_ptm_fd(ptm_fd)
@ -157,8 +159,34 @@ void Terminal::escape$m(const ParamVector& params)
m_current_attribute.reset(); m_current_attribute.reset();
break; break;
case 1: case 1:
// Bold m_current_attribute.flags |= Attribute::Bold;
//m_current_attribute.bold = true; break;
case 3:
m_current_attribute.flags |= Attribute::Italic;
break;
case 4:
m_current_attribute.flags |= Attribute::Underline;
break;
case 5:
m_current_attribute.flags |= Attribute::Blink;
break;
case 7:
m_current_attribute.flags |= Attribute::Negative;
break;
case 22:
m_current_attribute.flags &= ~Attribute::Bold;
break;
case 23:
m_current_attribute.flags &= ~Attribute::Italic;
break;
case 24:
m_current_attribute.flags &= ~Attribute::Underline;
break;
case 25:
m_current_attribute.flags &= ~Attribute::Blink;
break;
case 27:
m_current_attribute.flags &= ~Attribute::Negative;
break; break;
case 30: case 30:
case 31: case 31:
@ -169,8 +197,14 @@ void Terminal::escape$m(const ParamVector& params)
case 36: case 36:
case 37: case 37:
// Foreground color // Foreground color
if (m_current_attribute.flags & Attribute::Bold)
param += 8;
m_current_attribute.foreground_color = param - 30; m_current_attribute.foreground_color = param - 30;
break; break;
case 39:
// reset foreground
m_current_attribute.foreground_color = Attribute::default_foreground_color;
break;
case 40: case 40:
case 41: case 41:
case 42: case 42:
@ -180,8 +214,16 @@ void Terminal::escape$m(const ParamVector& params)
case 46: case 46:
case 47: case 47:
// Background color // Background color
if (m_current_attribute.flags & Attribute::Bold)
param += 8;
m_current_attribute.background_color = param - 40; m_current_attribute.background_color = param - 40;
break; break;
case 49:
// reset background
m_current_attribute.background_color = Attribute::default_background_color;
break;
default:
dbgprintf("FIXME: escape$m: p: %u\n", param);
} }
} }
} }

View file

@ -77,18 +77,35 @@ private:
struct Attribute { struct Attribute {
Attribute() { reset(); } Attribute() { reset(); }
static byte default_foreground_color;
static byte default_background_color;
void reset() void reset()
{ {
foreground_color = 7; foreground_color = default_foreground_color;
background_color = 0; background_color = default_background_color;
//bold = false; flags = Flags::NoAttributes;
} }
byte foreground_color; byte foreground_color;
byte background_color; byte background_color;
//bool bold : 1;
enum Flags {
NoAttributes = 0x00,
Bold = 0x01,
Italic = 0x02,
Underline = 0x04,
Negative = 0x08,
Blink = 0x10,
};
// TODO: it would be really nice if we had a helper for enums that
// exposed bit ops for class enums...
int flags = Flags::NoAttributes;
bool operator==(const Attribute& other) const bool operator==(const Attribute& other) const
{ {
return foreground_color == other.foreground_color && background_color == other.background_color; return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags;
} }
bool operator!=(const Attribute& other) const bool operator!=(const Attribute& other) const
{ {