@softwarefactory-project/re-ansi 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -81,6 +81,10 @@ Make sure to read about [React][reason-react] and [Reason][rescript-lang] too.
81
81
 
82
82
  ## Changes
83
83
 
84
+ ### 0.6.0
85
+
86
+ - Fix support for bright colors.
87
+
84
88
  ### 0.5.0
85
89
 
86
90
  - Add support for `[m` and `[K`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwarefactory-project/re-ansi",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "ANSI code to HTML",
5
5
  "files": ["README.md", "LICENSE", "bsconfig.json", "src"],
6
6
  "main": "./src/Ansi.bs.js",
package/src/Ansi.bs.js CHANGED
@@ -50,6 +50,30 @@ function fourBitColors(code) {
50
50
  }
51
51
  }
52
52
 
53
+ function threeBitColors(code) {
54
+ switch (code) {
55
+ case 0 :
56
+ return "grey";
57
+ case 1 :
58
+ return "red";
59
+ case 2 :
60
+ return "green";
61
+ case 3 :
62
+ return "yellow";
63
+ case 4 :
64
+ return "blue";
65
+ case 5 :
66
+ return "magenta";
67
+ case 6 :
68
+ return "cyan";
69
+ case 7 :
70
+ return "white";
71
+ default:
72
+ console.log("Unknown color value:", code);
73
+ return ;
74
+ }
75
+ }
76
+
53
77
  function combine(css1, css2) {
54
78
  return Object.assign({}, css1, css2);
55
79
  }
@@ -78,10 +102,15 @@ function int_of_cp(c) {
78
102
 
79
103
  function getColorStyle(colorMode, colorValue) {
80
104
  switch (colorMode) {
105
+ case 3 :
106
+ return {
107
+ TAG: /* Foreground */0,
108
+ _0: colorValue
109
+ };
81
110
  case 0 :
82
111
  case 4 :
83
112
  return {
84
- TAG: /* Background */1,
113
+ TAG: /* Background */2,
85
114
  _0: colorValue
86
115
  };
87
116
  case 1 :
@@ -91,10 +120,9 @@ function getColorStyle(colorMode, colorValue) {
91
120
  case 7 :
92
121
  case 8 :
93
122
  break;
94
- case 3 :
95
123
  case 9 :
96
124
  return {
97
- TAG: /* Foreground */0,
125
+ TAG: /* BrightForeground */1,
98
126
  _0: colorValue
99
127
  };
100
128
  default:
@@ -105,18 +133,27 @@ function getColorStyle(colorMode, colorValue) {
105
133
  }
106
134
 
107
135
  function getColorStyleCss(color) {
108
- if (color.TAG) {
109
- return Belt_Option.flatMap(fourBitColors(color._0), (function (background) {
110
- return {
111
- background: background
112
- };
113
- }));
114
- } else {
115
- return Belt_Option.flatMap(fourBitColors(color._0), (function (color) {
116
- return {
117
- color: color
118
- };
119
- }));
136
+ switch (color.TAG | 0) {
137
+ case /* Foreground */0 :
138
+ return Belt_Option.flatMap(fourBitColors(color._0), (function (color) {
139
+ return {
140
+ color: color
141
+ };
142
+ }));
143
+ case /* BrightForeground */1 :
144
+ return Belt_Option.flatMap(threeBitColors(color._0), (function (color) {
145
+ return {
146
+ color: color,
147
+ fontWeight: "bold"
148
+ };
149
+ }));
150
+ case /* Background */2 :
151
+ return Belt_Option.flatMap(fourBitColors(color._0), (function (background) {
152
+ return {
153
+ background: background
154
+ };
155
+ }));
156
+
120
157
  }
121
158
  }
122
159
 
@@ -718,6 +755,7 @@ function parse(txt, pos) {
718
755
 
719
756
  var AnsiCode = {
720
757
  fourBitColors: fourBitColors,
758
+ threeBitColors: threeBitColors,
721
759
  combine: combine,
722
760
  addWeight: addWeight,
723
761
  addStyle: addStyle,
package/src/Ansi.re CHANGED
@@ -59,6 +59,21 @@ module AnsiCode = {
59
59
  None;
60
60
  };
61
61
 
62
+ let threeBitColors = (code: int): option(string) =>
63
+ switch (code) {
64
+ | 00 => "grey"->Some
65
+ | 01 => "red"->Some
66
+ | 02 => "green"->Some
67
+ | 03 => "yellow"->Some
68
+ | 04 => "blue"->Some
69
+ | 05 => "magenta"->Some
70
+ | 06 => "cyan"->Some
71
+ | 07 => "white"->Some
72
+ | _ =>
73
+ Js.log2("Unknown color value:", code);
74
+ None;
75
+ };
76
+
62
77
  // Css utility
63
78
  let combine = (css1, css2) => ReactDOM.Style.combine(css1, css2);
64
79
  let addWeight = fontWeight => ReactDOM.Style.make(~fontWeight, ());
@@ -70,11 +85,12 @@ module AnsiCode = {
70
85
  module ColorCss = {
71
86
  type t =
72
87
  | Foreground(int)
88
+ | BrightForeground(int)
73
89
  | Background(int);
74
90
  let getColorStyle = (colorMode: int, colorValue: int): option(t) =>
75
91
  switch (colorMode) {
76
- | 3
77
- | 9 => colorValue->Foreground->Some
92
+ | 3 => colorValue->Foreground->Some
93
+ | 9 => colorValue->BrightForeground->Some
78
94
  | 4
79
95
  | 0 => colorValue->Background->Some
80
96
  | _ =>
@@ -88,6 +104,10 @@ module AnsiCode = {
88
104
  v
89
105
  ->fourBitColors
90
106
  ->Option.flatMap(color => ReactDOM.Style.make(~color, ())->Some)
107
+ | BrightForeground(v) =>
108
+ v
109
+ ->threeBitColors
110
+ ->Option.flatMap(color => ReactDOM.Style.make(~color, ~fontWeight="bold", ())->Some)
91
111
  | Background(v) =>
92
112
  v
93
113
  ->fourBitColors
package/src/old.js ADDED
File without changes