From 3630677c07768781376242f5c0919a6c9cb5d7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 1 Feb 2026 20:26:42 +0100 Subject: Use FormattedText for terminal prompt --- src/Erebos/TextFormat.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Erebos/TextFormat.hs') diff --git a/src/Erebos/TextFormat.hs b/src/Erebos/TextFormat.hs index 0bfad75..20973d9 100644 --- a/src/Erebos/TextFormat.hs +++ b/src/Erebos/TextFormat.hs @@ -1,16 +1,29 @@ module Erebos.TextFormat ( FormattedText, + plainText, renderPlainText, + formattedTextLength, ) where import Data.Text (Text) +import Data.Text qualified as T import Erebos.TextFormat.Types +plainText :: Text -> FormattedText +plainText = PlainText + + renderPlainText :: FormattedText -> Text renderPlainText = \case PlainText text -> text ConcatenatedText ftexts -> mconcat $ map renderPlainText ftexts FormattedText _ ftext -> renderPlainText ftext + +formattedTextLength :: FormattedText -> Int +formattedTextLength = \case + PlainText text -> T.length text + ConcatenatedText ftexts -> sum $ map formattedTextLength ftexts + FormattedText _ ftext -> formattedTextLength ftext -- cgit v1.2.3