{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ViewPatterns #-}

module Unison.CommandLine.Helpers
  ( -- * Pretty Printing
    backtick,
    aside,
    bigproblem,
    note,
    nothingTodo,
    plural,
    plural',
    problem,
    tip,
    warn,
    warnNote,
  )
where

import Data.ListLike (ListLike)
import Unison.Prelude
import Unison.Util.Pretty qualified as P
import Prelude hiding (readFile, writeFile)

warnNote :: String -> String
warnNote :: String -> String
warnNote String
s = String
"⚠️  " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
s

backtick :: (IsString s) => P.Pretty s -> P.Pretty s
backtick :: forall s. IsString s => Pretty s -> Pretty s
backtick Pretty s
s = Pretty s -> Pretty s
forall s. Pretty s -> Pretty s
P.group (Pretty s
"`" Pretty s -> Pretty s -> Pretty s
forall a. Semigroup a => a -> a -> a
<> Pretty s
s Pretty s -> Pretty s -> Pretty s
forall a. Semigroup a => a -> a -> a
<> Pretty s
"`")

tip :: (ListLike s Char, IsString s) => P.Pretty s -> P.Pretty s
tip :: forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
tip Pretty s
s = [(Pretty s, Pretty s)] -> Pretty s
forall s.
(ListLike s Char, IsString s) =>
[(Pretty s, Pretty s)] -> Pretty s
P.column2 [(Pretty s
"Tip:", Pretty s -> Pretty s
forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
P.wrap Pretty s
s)]

note :: (ListLike s Char, IsString s) => P.Pretty s -> P.Pretty s
note :: forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
note Pretty s
s = [(Pretty s, Pretty s)] -> Pretty s
forall s.
(ListLike s Char, IsString s) =>
[(Pretty s, Pretty s)] -> Pretty s
P.column2 [(Pretty s
"Note:", Pretty s -> Pretty s
forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
P.wrap Pretty s
s)]

aside :: (ListLike s Char, IsString s) => P.Pretty s -> P.Pretty s -> P.Pretty s
aside :: forall s.
(ListLike s Char, IsString s) =>
Pretty s -> Pretty s -> Pretty s
aside Pretty s
a Pretty s
b = [(Pretty s, Pretty s)] -> Pretty s
forall s.
(ListLike s Char, IsString s) =>
[(Pretty s, Pretty s)] -> Pretty s
P.column2 [(Pretty s
a Pretty s -> Pretty s -> Pretty s
forall a. Semigroup a => a -> a -> a
<> Pretty s
":", Pretty s
b)]

warn :: (ListLike s Char, IsString s) => P.Pretty s -> P.Pretty s
warn :: forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
warn = String -> Pretty s -> Pretty s
forall s.
(ListLike s Char, IsString s) =>
String -> Pretty s -> Pretty s
emojiNote String
"⚠️"

problem :: (ListLike s Char, IsString s) => P.Pretty s -> P.Pretty s
problem :: forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
problem = String -> Pretty s -> Pretty s
forall s.
(ListLike s Char, IsString s) =>
String -> Pretty s -> Pretty s
emojiNote String
"❗️"

bigproblem :: (ListLike s Char, IsString s) => P.Pretty s -> P.Pretty s
bigproblem :: forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
bigproblem = String -> Pretty s -> Pretty s
forall s.
(ListLike s Char, IsString s) =>
String -> Pretty s -> Pretty s
emojiNote String
"‼️"

emojiNote :: (ListLike s Char, IsString s) => String -> P.Pretty s -> P.Pretty s
emojiNote :: forall s.
(ListLike s Char, IsString s) =>
String -> Pretty s -> Pretty s
emojiNote String
lead Pretty s
s = Pretty s -> Pretty s
forall s. Pretty s -> Pretty s
P.group (String -> Pretty s
forall a. IsString a => String -> a
fromString String
lead) Pretty s -> Pretty s -> Pretty s
forall a. Semigroup a => a -> a -> a
<> Pretty s
"\n" Pretty s -> Pretty s -> Pretty s
forall a. Semigroup a => a -> a -> a
<> Pretty s -> Pretty s
forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
P.wrap Pretty s
s

nothingTodo :: (ListLike s Char, IsString s) => P.Pretty s -> P.Pretty s
nothingTodo :: forall s. (ListLike s Char, IsString s) => Pretty s -> Pretty s
nothingTodo = String -> Pretty s -> Pretty s
forall s.
(ListLike s Char, IsString s) =>
String -> Pretty s -> Pretty s
emojiNote String
"😶"

-- `plural [] "cat" "cats" = "cats"`
-- `plural ["meow"] "cat" "cats" = "cat"`
-- `plural ["meow", "meow"] "cat" "cats" = "cats"`
plural :: (Foldable f) => f a -> b -> b -> b
plural :: forall (f :: * -> *) a b. Foldable f => f a -> b -> b -> b
plural f a
items b
one b
other = case f a -> [a]
forall a. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f a
items of
  [a
_] -> b
one
  [a]
_ -> b
other

plural' :: (Integral a) => a -> b -> b -> b
plural' :: forall a b. Integral a => a -> b -> b -> b
plural' a
1 b
one b
_other = b
one
plural' a
_ b
_one b
other = b
other