summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVT/CharacterSet.h
blob: 7b1fe9570f8cf6cb89e9644e795adcbf81ff1728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (c) 2021, The SerenityOS Developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Types.h>

namespace VT {

enum CharacterSet {
    Iso_8859_1,
    Null,
    UserDefined,
    VT100,
};

class CharacterSetTranslator {
public:
    u32 translate_code_point(CharacterSet active_set, u32 code_point)
    {
        // Only translate 0x7F and lower
        if (code_point > 127)
            return code_point;

        // FIXME: implement other character sets
        if (active_set != CharacterSet::VT100)
            return code_point;

        // VT100 translation table - https://en.wikipedia.org/wiki/Box-drawing_character#Unix,_CP/M,_BBS
        switch (code_point) {
        case 0x6A:
            return 0x2518;
        case 0x6B:
            return 0x2510;
        case 0x6C:
            return 0x250C;
        case 0x6D:
            return 0x2514;
        case 0x6E:
            return 0x253C;
        case 0x71:
            return 0x2500;
        case 0x74:
            return 0x251C;
        case 0x75:
            return 0x2524;
        case 0x76:
            return 0x2534;
        case 0x77:
            return 0x252C;
        case 0x78:
            return 0x2502;
        }
        return code_point;
    }
};

}