From c1ff403387064ff0027b9e762cc6f6a8fa20c8d9 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 7 Dec 2023 03:58:21 +0100 Subject: chore: move remaining `History.*` modules outside of `History` --- app/Git/CommitHash.hs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/Git/CommitHash.hs (limited to 'app/Git') diff --git a/app/Git/CommitHash.hs b/app/Git/CommitHash.hs new file mode 100644 index 0000000..db7a478 --- /dev/null +++ b/app/Git/CommitHash.hs @@ -0,0 +1,37 @@ +module Git.CommitHash + ( CommitHash (..), + toShortText, + toText, + ) +where + +import Data.Binary (Binary) +import Data.Maybe (fromMaybe) +import Data.Text qualified as T +import GHC.Generics (Generic) +import Render qualified as P + +data CommitHash + = WorkingTree + | Commit T.Text + deriving (Eq, Show, Binary, Generic) + +toShortText :: CommitHash -> Maybe T.Text +toShortText = fmap (T.take 7) . toText + +toText :: CommitHash -> Maybe T.Text +toText WorkingTree = Nothing +toText (Commit hash) = Just hash + +instance P.Render CommitHash where + render = P.render . P.Detailed + +instance P.Render (P.Detailed CommitHash) where + render (P.Detailed commitHash) = + P.styled [P.color P.Yellow] $ + P.render (fromMaybe "" (toText commitHash)) + +instance P.Render (P.Summarized CommitHash) where + render (P.Summarized commitHash) = + P.styled [P.color P.Yellow] $ + P.render (fromMaybe "" (toShortText commitHash)) -- cgit v1.2.3