Skip to content

Commit 4f015b7

Browse files
committed
[General] Move ANSI_GRAPHIC macros to new 'ansi-color.h' header
1 parent 6835c5f commit 4f015b7

File tree

2 files changed

+67
-53
lines changed

2 files changed

+67
-53
lines changed

Sources/classdumpctl/ansi-color.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// ansi-color.h
3+
// classdumpctl
4+
//
5+
// Created by Leptos on 8/24/24.
6+
// Copyright © 2024 Leptos. All rights reserved.
7+
//
8+
9+
#ifndef ANSI_COLOR_h
10+
#define ANSI_COLOR_h
11+
12+
/* ANSI color escapes:
13+
* "\033[Em"
14+
* where E is the encoding, and the rest are literals, for example:
15+
* if 'E' -> "0;30" the full string is "\033[0;30m"
16+
* E -> "0" for reset
17+
*
18+
* E -> "T;MC"
19+
* T values:
20+
* 0 for regular
21+
* 1 for bold
22+
* 2 for faint
23+
* 3 for italic
24+
* 4 for underline
25+
* M values:
26+
* 3 for foreground normal
27+
* 4 for background normal
28+
* 9 for foreground bright
29+
* 10 for background bright
30+
* C values:
31+
* 0 for black
32+
* 1 for red
33+
* 2 for green
34+
* 3 for yellow
35+
* 4 for blue
36+
* 5 for purple
37+
* 6 for cyan
38+
* 7 for white
39+
*/
40+
41+
#define ANSI_GRAPHIC_RENDITION(e) "\033[" e "m"
42+
#define ANSI_GRAPHIC_RESET_CODE "0"
43+
#define ANSI_GRAPHIC_COLOR(t, m, c) ANSI_GRAPHIC_RENDITION(t ";" m c)
44+
45+
#define ANSI_GRAPHIC_COLOR_TYPE_REGULAR "0"
46+
#define ANSI_GRAPHIC_COLOR_TYPE_BOLD "1"
47+
#define ANSI_GRAPHIC_COLOR_TYPE_FAINT "2"
48+
#define ANSI_GRAPHIC_COLOR_TYPE_ITALIC "3"
49+
#define ANSI_GRAPHIC_COLOR_TYPE_UNDERLINE "4"
50+
51+
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_FOREGROUND_NORMAL "3"
52+
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_BACKGROUND_NORMAL "4"
53+
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_FOREGROUND_BRIGHT "9"
54+
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_BACKGROUND_BRIGHT "10"
55+
56+
#define ANSI_GRAPHIC_COLOR_CODE_BLACK "0"
57+
#define ANSI_GRAPHIC_COLOR_CODE_RED "1"
58+
#define ANSI_GRAPHIC_COLOR_CODE_GREEN "2"
59+
#define ANSI_GRAPHIC_COLOR_CODE_YELLOW "3"
60+
#define ANSI_GRAPHIC_COLOR_CODE_BLUE "4"
61+
#define ANSI_GRAPHIC_COLOR_CODE_PURPLE "5"
62+
#define ANSI_GRAPHIC_COLOR_CODE_CYAN "6"
63+
#define ANSI_GRAPHIC_COLOR_CODE_WHITE "7"
64+
65+
66+
#endif /* ANSI_COLOR_h */

Sources/classdumpctl/main.m

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,7 @@
1111
#import <dlfcn.h>
1212
#import <getopt.h>
1313

14-
15-
/* ANSI color escapes:
16-
* "\033[Em"
17-
* where E is the encoding, and the rest are literals, for example:
18-
* if 'E' -> "0;30" the full string is "\033[0;30m"
19-
* E -> "0" for reset
20-
*
21-
* E -> "T;MC"
22-
* T values:
23-
* 0 for regular
24-
* 1 for bold
25-
* 2 for faint
26-
* 3 for italic
27-
* 4 for underline
28-
* M values:
29-
* 3 for foreground normal
30-
* 4 for background normal
31-
* 9 for foreground bright
32-
* 10 for background bright
33-
* C values:
34-
* 0 for black
35-
* 1 for red
36-
* 2 for green
37-
* 3 for yellow
38-
* 4 for blue
39-
* 5 for purple
40-
* 6 for cyan
41-
* 7 for white
42-
*/
43-
44-
#define ANSI_GRAPHIC_RENDITION(e) "\033[" e "m"
45-
#define ANSI_GRAPHIC_RESET_CODE "0"
46-
#define ANSI_GRAPHIC_COLOR(t, m, c) ANSI_GRAPHIC_RENDITION(t ";" m c)
47-
48-
#define ANSI_GRAPHIC_COLOR_TYPE_REGULAR "0"
49-
#define ANSI_GRAPHIC_COLOR_TYPE_BOLD "1"
50-
#define ANSI_GRAPHIC_COLOR_TYPE_FAINT "2"
51-
#define ANSI_GRAPHIC_COLOR_TYPE_ITALIC "3"
52-
#define ANSI_GRAPHIC_COLOR_TYPE_UNDERLINE "4"
53-
54-
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_FOREGROUND_NORMAL "3"
55-
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_BACKGROUND_NORMAL "4"
56-
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_FOREGROUND_BRIGHT "9"
57-
#define ANSI_GRAPHIC_COLOR_ATTRIBUTE_BACKGROUND_BRIGHT "10"
58-
59-
#define ANSI_GRAPHIC_COLOR_CODE_BLACK "0"
60-
#define ANSI_GRAPHIC_COLOR_CODE_RED "1"
61-
#define ANSI_GRAPHIC_COLOR_CODE_GREEN "2"
62-
#define ANSI_GRAPHIC_COLOR_CODE_YELLOW "3"
63-
#define ANSI_GRAPHIC_COLOR_CODE_BLUE "4"
64-
#define ANSI_GRAPHIC_COLOR_CODE_PURPLE "5"
65-
#define ANSI_GRAPHIC_COLOR_CODE_CYAN "6"
66-
#define ANSI_GRAPHIC_COLOR_CODE_WHITE "7"
14+
#import "ansi-color.h"
6715

6816

6917
typedef NS_ENUM(NSUInteger, CDOutputColorMode) {

0 commit comments

Comments
 (0)