-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.erl
89 lines (71 loc) · 2.39 KB
/
utils.erl
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
% rtctree-erl
%
% Copyright (C) 2009-2010
% Geoffrey Biggs
% RT-Synthesis Research Group
% Intelligent Systems Research Institute,
% National Institute of Advanced Industrial Science and Technology (AIST),
% Japan
% All rights reserved.
% Licensed under the Eclipse Public License -v 1.0 (EPL)
% http://www.opensource.org/licenses/eclipse-1.0.txt
%
% Utilities.
-module(utils).
% External use exports
-export([build_attr_string/2]).
% Internal use exports
-export([test/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% External API - execution context functions
build_attr_string(_, false) ->
"";
build_attr_string(Attrs, _) ->
build_attr_string_int(Attrs, [8#33, $[]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Internal functions
attrs() ->
dict:from_list([{reset, "00"},
{bold, "01"},
{faint, "02"},
{underline, "04"},
{blink, "05"},
{blinkfast, "06"},
{negative, "07"},
{normal, "22"},
{nounderline, "24"},
{noblink, "25"},
{positive, "27"},
{black, "30"},
{red, "31"},
{green, "32"},
{brown, "33"},
{blue, "34"},
{purple, "35"},
{cyan, "36"},
{white, "37"},
{bgblack, "40"},
{bgred, "41"},
{bggreen, "42"},
{bgbrown, "43"},
{bgblue, "44"},
{bgpurple, "45"},
{bgcyan, "46"},
{bgwhite, "47"}]).
build_attr_string_int([], Acc) ->
string:concat(string:substr(Acc, 1, length(Acc) - 1), "m");
build_attr_string_int([H|T], Acc) ->
build_attr_string_int(T,
string:concat(string:concat(Acc, dict:fetch(H, attrs())), ";")).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Tests
test() ->
test_no_support(),
test_support(),
ok.
test_no_support() ->
"" = build_attr_string([faint, underline, blinkfast, cyan, bgcyan], false),
ok.
test_support() ->
[8#33] ++ "[01;31;47m" = build_attr_string([bold, red, bgwhite], true),
ok.