Skip to content

Commit

Permalink
Prepare for 0.2.2 release. Update names of Pastel.parse and Pastel.ap…
Browse files Browse the repository at this point in the history
…ply to be prefixed by unstable to reflect their currently experimental nature (#208)

Summary:
We need to release a new version of Pastel for JSOO compatibility (#207). This should ideally have been done when the usage of Str was removed in favor of Re
Pull Request resolved: #208

Differential Revision: D18341628

Pulled By: bandersongit

fbshipit-source-id: 05fb76a8aa19a7d7234d4f9bbf54be33d5bbe351
  • Loading branch information
bandersongit authored and facebook-github-bot committed Nov 6, 2019
1 parent 236ee6a commit 0eea180
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pastel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reason-native/pastel",
"version": "0.2.1",
"version": "0.2.2",
"description": "Native Reason ANSI terminal styling with an awesome API",
"author": "Facebook Engineering",
"homepage": "https://reason-native.com",
Expand Down
83 changes: 45 additions & 38 deletions src/pastel/Pastel.rei
Original file line number Diff line number Diff line change
Expand Up @@ -117,41 +117,48 @@ let createElement:
) =>
string;

type style;
let emptyStyle: style;

let withColor: (ColorName.colorName, style) => style;
let resetColor: style => style;
let withBackgroundColor: (ColorName.colorName, style) => style;
let resetBackgroundColor: style => style;

let setBold: (bool, style) => style;
let withBold: style => style;
let setDim: (bool, style) => style;
let withDim: style => style;
let setItalic: (bool, style) => style;
let withItalic: style => style;
let setUnderline: (bool, style) => style;
let withUnderline: style => style;
let setInverse: (bool, style) => style;
let withInverse: style => style;
let setHidden: (bool, style) => style;
let withHidden: style => style;
let setStrikethrough: (bool, style) => style;
let withStrikethrough: style => style;
let withReset: style => style;
let setReset: (bool, style) => style;

let getColor: style => option(ColorName.colorName);
let getBackgroundColor: style => option(ColorName.colorName);
let isBold: style => bool;
let isDim: style => bool;
let isItalic: style => bool;
let isUnderline: style => bool;
let isInverse: style => bool;
let isHidden: style => bool;
let isStrikethrough: style => bool;
let isReset: style => bool;

let parse: string => list((style, string));
let apply: list((style, string)) => string;
/** Pastel.style exposes a way to examine and manipulate the styles of existing text in
* order to perform additional formatting operations. This feature is intended to be used primarily
* by libraries (such as Frame). The style API itself is still subject to change until the parse/apply
* API is finalized, however it is extremely unlikely to change */
type style;
let emptyStyle: style;

let withColor: (ColorName.colorName, style) => style;
let resetColor: style => style;
let withBackgroundColor: (ColorName.colorName, style) => style;
let resetBackgroundColor: style => style;

let setBold: (bool, style) => style;
let withBold: style => style;
let setDim: (bool, style) => style;
let withDim: style => style;
let setItalic: (bool, style) => style;
let withItalic: style => style;
let setUnderline: (bool, style) => style;
let withUnderline: style => style;
let setInverse: (bool, style) => style;
let withInverse: style => style;
let setHidden: (bool, style) => style;
let withHidden: style => style;
let setStrikethrough: (bool, style) => style;
let withStrikethrough: style => style;
let withReset: style => style;
let setReset: (bool, style) => style;

let getColor: style => option(ColorName.colorName);
let getBackgroundColor: style => option(ColorName.colorName);
let isBold: style => bool;
let isDim: style => bool;
let isItalic: style => bool;
let isUnderline: style => bool;
let isInverse: style => bool;
let isHidden: style => bool;
let isStrikethrough: style => bool;
let isReset: style => bool;
/** These functions are considered unstable and are subject to change
* unstable_parse takes a (potentially stylized by Pastel) string, and breaks it into segments that share the same styles
* unstable_apply takes a list of stylized segments and constructs a string that correctly displays those styles
*/
let unstable_parse: string => list((style, string));
let unstable_apply: list((style, string)) => string;
4 changes: 2 additions & 2 deletions src/pastel/PastelFactory.re
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,6 @@ module Make = (()) => {
};

let emptyStyle = StateMachine.initialState;
let parse = s => selectedImplementation^.parse(s);
let apply = parts => selectedImplementation^.apply(parts);
let unstable_parse = s => selectedImplementation^.parse(s);
let unstable_apply = parts => selectedImplementation^.apply(parts);
};
4 changes: 2 additions & 2 deletions src/pastel/PastelSig.re
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ module type PastelSig = {
let isStrikethrough: style => bool;
let isReset: style => bool;

let parse: string => list((style, string));
let apply: list((style, string)) => string;
let unstable_parse: string => list((style, string));
let unstable_apply: list((style, string)) => string;

let createElement:
(
Expand Down
26 changes: 13 additions & 13 deletions tests/__tests__/pastel/Parse_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let runTestSuite = (mode, name) => {
"hello"
<Pastel color=Red> "world" </Pastel>
</Pastel>;
let parts = Pastel.parse(input);
let parts = Pastel.unstable_parse(input);
expect.int(List.length(parts)).toBe(2);
let (firstStyle, firstText, secondStyle, secondText) =
switch (parts) {
Expand Down Expand Up @@ -50,7 +50,7 @@ let runTestSuite = (mode, name) => {
<Pastel color=Red> "world" </Pastel>
<Pastel color=Blue> "and goodbye" </Pastel>
</Pastel>;
let parts = Pastel.parse(input);
let parts = Pastel.unstable_parse(input);

expect.int(List.length(parts)).toBe(3);
let (
Expand Down Expand Up @@ -96,7 +96,7 @@ let runTestSuite = (mode, name) => {
"hello"
<Pastel color=Red> "world" </Pastel>
</Pastel>;
let parts = Pastel.parse(input);
let parts = Pastel.unstable_parse(input);

expect.int(List.length(parts)).toBe(2);
let (firstRegion, secondRegion) =
Expand All @@ -108,11 +108,11 @@ let runTestSuite = (mode, name) => {
| _ => raise(Invalid_argument("already verified length"))
};
let reconstructed =
Pastel.apply([
Pastel.unstable_apply([
(firstRegion, "goodbye"),
(secondRegion, "everybody"),
]);
let reconstructedParts = Pastel.parse(reconstructed);
let reconstructedParts = Pastel.unstable_parse(reconstructed);

expect.int(List.length(reconstructedParts)).toBe(2);
let (firstText, secondText) =
Expand All @@ -139,7 +139,7 @@ let runTestSuite = (mode, name) => {
"hello"
<Pastel color=Red> "world" </Pastel>
</Pastel>;
let parts = Pastel.parse(input);
let parts = Pastel.unstable_parse(input);

expect.int(List.length(parts)).toBe(2);
let (firstRegion, secondRegion) =
Expand All @@ -151,12 +151,12 @@ let runTestSuite = (mode, name) => {
| _ => raise(Invalid_argument("already verified length"))
};
let reconstructed =
Pastel.apply([
Pastel.unstable_apply([
(firstRegion, "goodbye"),
(Pastel.emptyStyle, "unstyled text!"),
(secondRegion, "everybody"),
]);
let reconstructedParts = Pastel.parse(reconstructed);
let reconstructedParts = Pastel.unstable_parse(reconstructed);

expect.int(List.length(reconstructedParts)).toBe(3);
let (firstText, secondText, thirdText, secondStyle) =
Expand Down Expand Up @@ -187,7 +187,7 @@ let runTestSuite = (mode, name) => {
"hello"
<Pastel color=Red> "world" </Pastel>
</Pastel>;
let parts = Pastel.parse(input);
let parts = Pastel.unstable_parse(input);
expect.int(List.length(parts)).toBe(2);
let (firstStyle, firstText, secondStyle, secondText) =
switch (parts) {
Expand All @@ -200,14 +200,14 @@ let runTestSuite = (mode, name) => {
| _ => raise(Invalid_argument("already verified length"))
};
let result =
Pastel.apply([
Pastel.unstable_apply([
(firstStyle |> Pastel.withUnderline, firstText),
(
secondStyle |> Pastel.withDim |> Pastel.withColor(Magenta),
secondText,
),
]);
let resultParts = Pastel.parse(result);
let resultParts = Pastel.unstable_parse(result);
expect.int(List.length(resultParts)).toBe(2);
let (firstStyle, firstText, secondStyle, secondText) =
switch (resultParts) {
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("disabled deconstruction", ({test}) => {
"hello "
<Pastel color=Red> "world" </Pastel>
</Pastel>;
let parts = Pastel.parse(input);
let parts = Pastel.unstable_parse(input);

expect.int(List.length(parts)).toBe(1);
let (style, text) = List.hd(parts);
Expand All @@ -260,7 +260,7 @@ describe("disabled deconstruction", ({test}) => {
Disabled,
() => {
let result =
Pastel.apply([
Pastel.unstable_apply([
(Pastel.emptyStyle |> Pastel.withColor(Black), "hello "),
(Pastel.emptyStyle |> Pastel.withHidden, "world"),
]);
Expand Down
6 changes: 3 additions & 3 deletions tests/__tests__/pastel/Pastel_reset_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ describe("Pastel.reset", ({test}) => {
HumanReadablePastel.(emptyStyle |> withReset),
"hello",
);
let result = HumanReadablePastel.apply([stateRegion]);
let result = HumanReadablePastel.unstable_apply([stateRegion]);

expect.string(String.escaped(result)).toEqual("<reset>hello</reset>");
();
});
test("apply reset state terminal", ({expect}) => {
let stateRegion = TerminalPastel.(emptyStyle |> withReset, "hello");
let result = TerminalPastel.apply([stateRegion]);
let result = TerminalPastel.unstable_apply([stateRegion]);

expect.string(String.escaped(result)).toEqual("\\027[0mhello\\027[0m\\027[0m");
();
});
test("apply reset state with other state human readable", ({expect}) => {
let result =
HumanReadablePastel.(
apply([
unstable_apply([
(emptyStyle |> withReset, "hello"),
(emptyStyle |> withColor(Green), "world"),
])
Expand Down

0 comments on commit 0eea180

Please sign in to comment.