Skip to content

Support 24bit colors #69

@certik

Description

@certik

Currently cpp-terminal only supports 4bit colors. We should extend it to also support 24 bit colors:

https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit

We have to add a new function color_24bit (similar to the current function color which is only 4 bit) and use the ESC[ 38;2;⟨r⟩;⟨g⟩;⟨b⟩ m sequence to set it.

Then we need to extend the Window class, currently the color is only represented by the 3bit color vector<fg>. Instead we have to change it to vector<Color>, where the Color struct is something like this:

struct Color {
    enum { bit24, bit3, bit4 } tag;
    union {
        struct {
            char R, G, B;
        };   
        fg color_fg;
        fgB color_fgB;
    };  
};   

and then the set_fg method would become:

void set_fg(size_t x, size_t y, fg c) {
    m_fg[(y-1)*w+(x-1)].tag = bit3;    
    m_fg[(y-1)*w+(x-1)].color_fg = c;  
}

void set_fg_24bit(size_t x, size_t y, char R, char G, char B) {
    m_fg[(y-1)*w+(x-1)].tag = bit24;
    m_fg[(y-1)*w+(x-1)].R = R;      
    m_fg[(y-1)*w+(x-1)].G = G;
    m_fg[(y-1)*w+(x-1)].B = B;
}

Also the render method would need to be updated.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions