Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/extern/isocline/src/attr.h
2727 views
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
-----------------------------------------------------------------------------*/
7
#pragma once
8
#ifndef IC_ATTR_H
9
#define IC_ATTR_H
10
11
#include "common.h"
12
#include "stringbuf.h"
13
14
//-------------------------------------------------------------
15
// text attributes
16
//-------------------------------------------------------------
17
18
#define IC_ON (1)
19
#define IC_OFF (-1)
20
#define IC_NONE (0)
21
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 {
26
struct {
27
unsigned int color:28;
28
signed int bold:2;
29
signed int reverse:2;
30
unsigned int bgcolor:28;
31
signed int underline:2;
32
signed int italic:2;
33
} x;
34
uint64_t value;
35
} attr_t;
36
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 );
40
41
ic_private bool attr_is_none(attr_t attr);
42
ic_private bool attr_is_eq(attr_t attr1, attr_t attr2);
43
44
ic_private attr_t attr_update_with( attr_t attr, attr_t newattr );
45
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);
48
49
//-------------------------------------------------------------
50
// attribute buffer used for rich rendering
51
//-------------------------------------------------------------
52
53
struct attrbuf_s;
54
typedef struct attrbuf_s attrbuf_t;
55
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 );
62
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 );
66
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 );
69
70
#endif // IC_ATTR_H
71
72