xref: /haiku/src/apps/terminal/Colors.h (revision de2ada1f106c1c43ceeebef638d503d5049b88ca)
1 /*
2  * Copyright 2010-2013, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stefano Ceccherini, stefano.ceccherini@gmail.com
7  *		Siarzhuk Zharski, zharik@gmx.li
8  */
9 #ifndef _COLORS_H
10 #define _COLORS_H
11 
12 
13 #include <InterfaceDefs.h>
14 #include <ObjectList.h>
15 
16 
17 struct ansi_color_scheme {
18 	rgb_color black;
19 	rgb_color red;
20 	rgb_color green;
21 	rgb_color yellow;
22 	rgb_color blue;
23 	rgb_color magenta;
24 	rgb_color cyan;
25 	rgb_color white;
26 	bool operator==(const ansi_color_scheme& color);
27 };
28 
29 struct color_scheme {
30 	const char* name;
31 	rgb_color text_fore_color;
32 	rgb_color text_back_color;
33 	rgb_color cursor_fore_color;
34 	rgb_color cursor_back_color;
35 	rgb_color select_fore_color;
36 	rgb_color select_back_color;
37 	ansi_color_scheme ansi_colors;
38 	ansi_color_scheme ansi_colors_h;
39 	bool operator==(const color_scheme& color);
40 };
41 
42 struct FindColorSchemeByName : public UnaryPredicate<const color_scheme> {
FindColorSchemeByNameFindColorSchemeByName43 	FindColorSchemeByName() : scheme_name("") {}
44 
FindColorSchemeByNameFindColorSchemeByName45 	FindColorSchemeByName(const char* name)
46 		: scheme_name(name)
47 	{
48 	}
49 
operatorFindColorSchemeByName50 	int operator()(const color_scheme* item) const
51 	{
52 		return strcmp(item->name, scheme_name);
53 	}
54 
55 	const char*	scheme_name;
56 };
57 
58 extern color_scheme gCustomColorScheme;
59 extern BObjectList<const color_scheme> *gColorSchemes;
60 
61 const uint kANSIColorCount = 16;
62 const uint kTermColorCount = 256;
63 
64 
65 // Helper class handling XColorName/rgb:xxx/xxx/xxx -> rgb_color conversions.
66 // The source of XColorNames is wide available rgb.txt for X11 System.
67 // It is stored in "XColorsTable" application resource as array of
68 // "hash <-> rgb_color" pairs. The table is loaded only on demand.
69 // Name hashes must be sorted to let lookup procedure work properly
70 class XColorsTable {
71 
72 	struct _XColorEntry {
73 		uint32		hash;
74 		rgb_color	color;
75 	};
76 
77 public:
78 							XColorsTable();
79 							~XColorsTable();
80 
81 	status_t				LookUpColor(const char* name, rgb_color* color);
82 private:
83 	status_t				_LoadXColorsTable();
84 	uint32					_HashName(const char* name);
85 
86 	const _XColorEntry*		fTable;
87 	size_t					fCount;
88 };
89 
90 extern XColorsTable gXColorsTable;
91 
92 #endif // _COLORS_H
93