Skip to content

Commit

Permalink
Merge pull request #477 from wolfadex/wolfadex/switch-ansi-package
Browse files Browse the repository at this point in the history
Move from vito/elm-ansi to wolfadex/elm-ansi
  • Loading branch information
dillonkearns authored Dec 5, 2024
2 parents 4dea7ea + 1fde2b8 commit 336a7f1
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 62 deletions.
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"robinheghan/fnv1a": "1.0.0 <= v < 2.0.0",
"rtfeldman/elm-css": "18.0.0 <= v < 19.0.0",
"the-sett/elm-syntax-dsl": "6.0.2 <= v < 7.0.0",
"vito/elm-ansi": "10.0.1 <= v < 11.0.0"
"wolfadex/elm-ansi": "3.0.0 <= v < 4.0.0"
},
"test-dependencies": {
"avh4/elm-program-test": "4.0.0 <= v < 5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/base-path/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"the-sett/elm-syntax-dsl": "6.0.2",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/blog-engine/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"the-sett/elm-pretty-printer": "3.1.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"Chadtech/elm-bool-extra": "2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/blog-engine/script/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"the-sett/elm-syntax-dsl": "6.0.3",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"the-sett/elm-pretty-printer": "3.1.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"Chadtech/elm-bool-extra": "2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/end-to-end/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"the-sett/elm-pretty-printer": "3.1.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"ymtszw/elm-xml-decode": "3.2.1"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/end-to-end/script/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"robinheghan/fnv1a": "1.0.0",
"rtfeldman/elm-css": "18.0.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"Chadtech/elm-bool-extra": "2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/escaping/codegen/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"the-sett/elm-syntax-dsl": "6.0.3",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/escaping/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"the-sett/elm-syntax-dsl": "6.0.2",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/escaping/script/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"the-sett/elm-syntax-dsl": "6.0.2",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"the-sett/elm-syntax-dsl": "6.0.2",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.3.1",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"robinheghan/fnv1a": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.4",
"turboMaCk/non-empty-list-alias": "1.3.1",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"elm/file": "1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion examples/pokedex/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"the-sett/elm-syntax-dsl": "6.0.2",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/routing/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"the-sett/elm-pretty-printer": "3.1.0",
"the-sett/elm-syntax-dsl": "6.0.3",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"Chadtech/elm-bool-extra": "2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/smoothies/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"rtfeldman/elm-iso8601-date-strings": "1.1.4",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.3.1",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion examples/todos/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"the-sett/elm-pretty-printer": "3.1.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"Chadtech/elm-bool-extra": "2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/trails/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"rtfeldman/elm-iso8601-date-strings": "1.1.4",
"tripokey/elm-fuzzy": "5.2.1",
"turboMaCk/non-empty-list-alias": "1.3.1",
"vito/elm-ansi": "10.0.1",
"wolfadex/elm-ansi": "3.0.0",
"zwilias/json-decode-exploration": "6.0.0"
},
"indirect": {
Expand Down
2 changes: 1 addition & 1 deletion generator/template/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"rtfeldman/elm-css": "18.0.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"turboMaCk/non-empty-list-alias": "1.4.0",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
},
"indirect": {
"Chadtech/elm-bool-extra": "2.4.2",
Expand Down
2 changes: 1 addition & 1 deletion generator/template/script/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"stil4m/structured-writer": "1.0.3",
"the-sett/elm-pretty-printer": "3.1.0",
"the-sett/elm-syntax-dsl": "6.0.2",
"vito/elm-ansi": "10.0.1"
"wolfadex/elm-ansi": "3.0.0"
}
},
"test-dependencies": {
Expand Down
90 changes: 47 additions & 43 deletions src/TerminalText.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module TerminalText exposing
, yellow
)

import Ansi
import Ansi.Color
import Ansi.Parser
import Json.Encode as Encode


Expand All @@ -32,27 +33,27 @@ text value =

cyan : String -> Text
cyan inner =
Style { blankStyle | color = Just Ansi.Cyan } inner
Style { blankStyle | color = Just Ansi.Color.Cyan } inner


green : String -> Text
green inner =
Style { blankStyle | color = Just Ansi.Green } inner
Style { blankStyle | color = Just Ansi.Color.Green } inner


yellow : String -> Text
yellow inner =
Style { blankStyle | color = Just Ansi.Yellow } inner
Style { blankStyle | color = Just Ansi.Color.Yellow } inner


red : String -> Text
red inner =
Style { blankStyle | color = Just Ansi.Red } inner
Style { blankStyle | color = Just Ansi.Color.Red } inner


blue : String -> Text
blue inner =
Style { blankStyle | color = Just Ansi.Blue } inner
Style { blankStyle | color = Just Ansi.Color.Blue } inner


resetColors : String
Expand All @@ -70,23 +71,23 @@ ansiPrefix =
"\u{001B}"


colorToString : Ansi.Color -> String
colorToString : Ansi.Color.Color -> String
colorToString color =
ansi <|
case color of
Ansi.Red ->
Ansi.Color.Red ->
"[31m"

Ansi.Blue ->
Ansi.Color.Blue ->
"[34m"

Ansi.Green ->
Ansi.Color.Green ->
"[32m"

Ansi.Yellow ->
Ansi.Color.Yellow ->
"[33m"

Ansi.Cyan ->
Ansi.Color.Cyan ->
"[36m"

_ ->
Expand All @@ -104,7 +105,7 @@ toString list =
toString_ : Text -> String
toString_ (Style ansiStyle innerText) =
String.concat
[ ansiStyle.color |> Maybe.withDefault Ansi.White |> colorToString
[ ansiStyle.color |> Maybe.withDefault Ansi.Color.White |> colorToString
, innerText
, resetColors
]
Expand All @@ -119,15 +120,15 @@ toPlainString list =

fromAnsiString : String -> List Text
fromAnsiString ansiString =
Ansi.parseInto ( blankStyle, [] ) parseInto ansiString
Ansi.Parser.parseInto ( blankStyle, [] ) parseInto ansiString
|> Tuple.second
|> List.reverse


type alias AnsiStyle =
{ bold : Bool
, underline : Bool
, color : Maybe Ansi.Color
, color : Maybe Ansi.Color.Color
}


Expand All @@ -139,16 +140,16 @@ blankStyle =
}


parseInto : Ansi.Action -> ( AnsiStyle, List Text ) -> ( AnsiStyle, List Text )
parseInto : Ansi.Parser.Command -> ( AnsiStyle, List Text ) -> ( AnsiStyle, List Text )
parseInto action ( pendingStyle, soFar ) =
case action of
Ansi.Print string ->
Ansi.Parser.Text string ->
( blankStyle, Style pendingStyle string :: soFar )

Ansi.Remainder _ ->
Ansi.Parser.Remainder _ ->
( pendingStyle, soFar )

Ansi.SetForeground maybeColor ->
Ansi.Parser.SetForeground maybeColor ->
case maybeColor of
Just newColor ->
( { pendingStyle
Expand All @@ -160,22 +161,22 @@ parseInto action ( pendingStyle, soFar ) =
Nothing ->
( blankStyle, soFar )

Ansi.SetBold bool ->
Ansi.Parser.SetBold bool ->
( { pendingStyle | bold = bool }, soFar )

Ansi.SetFaint _ ->
Ansi.Parser.SetFaint _ ->
( pendingStyle, soFar )

Ansi.SetItalic _ ->
Ansi.Parser.SetItalic _ ->
( pendingStyle, soFar )

Ansi.SetUnderline bool ->
Ansi.Parser.SetUnderline bool ->
( { pendingStyle | underline = bool }, soFar )

Ansi.SetBackground _ ->
Ansi.Parser.SetBackground _ ->
( pendingStyle, soFar )

Ansi.Linebreak ->
Ansi.Parser.Linebreak ->
case soFar of
next :: rest ->
( pendingStyle, Style blankStyle "\n" :: next :: rest )
Expand All @@ -194,56 +195,59 @@ encoder (Style ansiStyle string) =
, ( "underline", Encode.bool ansiStyle.underline )
, ( "color"
, Encode.string <|
case ansiStyle.color |> Maybe.withDefault Ansi.White of
Ansi.Red ->
case ansiStyle.color |> Maybe.withDefault Ansi.Color.White of
Ansi.Color.Red ->
"red"

Ansi.Blue ->
Ansi.Color.Blue ->
"blue"

Ansi.Green ->
Ansi.Color.Green ->
"green"

Ansi.Yellow ->
Ansi.Color.Yellow ->
"yellow"

Ansi.Cyan ->
Ansi.Color.Cyan ->
"cyan"

Ansi.Black ->
Ansi.Color.Black ->
"black"

Ansi.Magenta ->
Ansi.Color.Magenta ->
"magenta"

Ansi.White ->
Ansi.Color.White ->
"white"

Ansi.BrightBlack ->
Ansi.Color.BrightBlack ->
"BLACK"

Ansi.BrightRed ->
Ansi.Color.BrightRed ->
"RED"

Ansi.BrightGreen ->
Ansi.Color.BrightGreen ->
"GREEN"

Ansi.BrightYellow ->
Ansi.Color.BrightYellow ->
"YELLOW"

Ansi.BrightBlue ->
Ansi.Color.BrightBlue ->
"BLUE"

Ansi.BrightMagenta ->
Ansi.Color.BrightMagenta ->
"MAGENTA"

Ansi.BrightCyan ->
Ansi.Color.BrightCyan ->
"CYAN"

Ansi.BrightWhite ->
Ansi.Color.BrightWhite ->
"WHITE"

Ansi.Custom _ _ _ ->
Ansi.Color.Custom256 _ ->
""

Ansi.Color.CustomTrueColor _ ->
""
)
, ( "string", Encode.string string )
Expand Down

0 comments on commit 336a7f1

Please sign in to comment.