1 /* ----------------------------------------------------------------------------
2 Copyright (c) 2021, Daan Leijen
3 This is free software; you can redistribute it and/or modify it
4 under the terms of the MIT License. A copy of the license can be
5 found in the "LICENSE" file at the root of this distribution.
6 -----------------------------------------------------------------------------*/
12 #include "stringbuf.h"
14 //-------------------------------------------------------------
16 //-------------------------------------------------------------
22 // try to fit in 64 bits
23 // note: order is important for some compilers
24 // note: each color can actually be 25 bits
25 typedef union attr_s
{
27 unsigned int color
:28;
30 unsigned int bgcolor
:28;
31 signed int underline
:2;
37 ic_private attr_t
attr_none(void);
38 ic_private attr_t
attr_default(void);
39 ic_private attr_t
attr_from_color( ic_color_t color
);
41 ic_private
bool attr_is_none(attr_t attr
);
42 ic_private
bool attr_is_eq(attr_t attr1
, attr_t attr2
);
44 ic_private attr_t
attr_update_with( attr_t attr
, attr_t newattr
);
46 ic_private attr_t
attr_from_sgr( const char* s
, ssize_t len
);
47 ic_private attr_t
attr_from_esc_sgr( const char* s
, ssize_t len
);
49 //-------------------------------------------------------------
50 // attribute buffer used for rich rendering
51 //-------------------------------------------------------------
54 typedef struct attrbuf_s attrbuf_t
;
56 ic_private attrbuf_t
* attrbuf_new( alloc_t
* mem
);
57 ic_private
void attrbuf_free( attrbuf_t
* ab
); // ab can be NULL
58 ic_private
void attrbuf_clear( attrbuf_t
* ab
); // ab can be NULL
59 ic_private ssize_t
attrbuf_len( attrbuf_t
* ab
); // ab can be NULL
60 ic_private
const attr_t
* attrbuf_attrs( attrbuf_t
* ab
, ssize_t expected_len
);
61 ic_private ssize_t
attrbuf_append_n( stringbuf_t
* sb
, attrbuf_t
* ab
, const char* s
, ssize_t len
, attr_t attr
);
63 ic_private
void attrbuf_set_at( attrbuf_t
* ab
, ssize_t pos
, ssize_t count
, attr_t attr
);
64 ic_private
void attrbuf_update_at( attrbuf_t
* ab
, ssize_t pos
, ssize_t count
, attr_t attr
);
65 ic_private
void attrbuf_insert_at( attrbuf_t
* ab
, ssize_t pos
, ssize_t count
, attr_t attr
);
67 ic_private attr_t
attrbuf_attr_at( attrbuf_t
* ab
, ssize_t pos
);
68 ic_private
void attrbuf_delete_at( attrbuf_t
* ab
, ssize_t pos
, ssize_t count
);