From a2d987d58aabe0bf3e15315b2541ee6dfb309608 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 7 Mar 2026 13:35:55 +0100 Subject: add break --- src/Blessings.hs | 14 ++++++++++++++ src/Blessings/ByteString.hs | 1 + src/Blessings/ByteString/Lazy.hs | 1 + src/Blessings/Internal.hs | 1 + src/Blessings/String.hs | 1 + src/Blessings/String/WCWidth.hs | 1 + src/Blessings/Text.hs | 1 + src/Blessings/Text/WCWidth.hs | 1 + 8 files changed, 21 insertions(+) diff --git a/src/Blessings.hs b/src/Blessings.hs index 9602bf4..ebf14e2 100644 --- a/src/Blessings.hs +++ b/src/Blessings.hs @@ -433,6 +433,20 @@ instance (Eq a, Blessable a) => Blessable (Blessings a) where Empty -> (Empty, Empty) + break p = \case + Append t1 t2 -> + both normalizeHead $ + case Bless.break p t1 of + (t1l, t1r) + | t1r == mempty -> first (t1l<>) $ Bless.break p t2 + | otherwise -> (t1l, t1r <> t2) + Plain s -> + both (normalizeHead . Plain) $ Bless.break p s + SGR pm t -> + both (normalizeHead . SGR pm) $ Bless.break p t + Empty -> + (Empty, Empty) + intercalate i = \case [] -> mempty [t] -> t diff --git a/src/Blessings/ByteString.hs b/src/Blessings/ByteString.hs index 42139fa..6c4ed76 100644 --- a/src/Blessings/ByteString.hs +++ b/src/Blessings/ByteString.hs @@ -14,5 +14,6 @@ instance Blessable B.ByteString where drop = B.drop take = B.take splitAt = B.splitAt + break = B.break intercalate = B.intercalate fromWord8 = B.pack . show diff --git a/src/Blessings/ByteString/Lazy.hs b/src/Blessings/ByteString/Lazy.hs index c0f521c..79361b7 100644 --- a/src/Blessings/ByteString/Lazy.hs +++ b/src/Blessings/ByteString/Lazy.hs @@ -14,5 +14,6 @@ instance Blessable L.ByteString where drop = L.drop . fromIntegral take = L.take . fromIntegral splitAt = L.splitAt . fromIntegral + break = L.break intercalate = L.intercalate fromWord8 = L.pack . show diff --git a/src/Blessings/Internal.hs b/src/Blessings/Internal.hs index 38c9069..7e5aeb1 100644 --- a/src/Blessings/Internal.hs +++ b/src/Blessings/Internal.hs @@ -9,5 +9,6 @@ class (IsString a, Monoid a) => Blessable a where drop :: Int -> a -> a take :: Int -> a -> a splitAt :: Int -> a -> (a, a) + break :: (Char -> Bool) -> a -> (a, a) intercalate :: a -> [a] -> a fromWord8 :: Word8 -> a diff --git a/src/Blessings/String.hs b/src/Blessings/String.hs index bc3d8cc..fa0f939 100644 --- a/src/Blessings/String.hs +++ b/src/Blessings/String.hs @@ -15,5 +15,6 @@ instance Blessable String where drop = L.drop take = L.take splitAt = L.splitAt + break = L.break intercalate = L.intercalate fromWord8 = show diff --git a/src/Blessings/String/WCWidth.hs b/src/Blessings/String/WCWidth.hs index 2160f99..7935019 100644 --- a/src/Blessings/String/WCWidth.hs +++ b/src/Blessings/String/WCWidth.hs @@ -18,6 +18,7 @@ instance Blessable String where drop = drop' take = take' splitAt = splitAt' + break = List.break intercalate = List.intercalate fromWord8 = show diff --git a/src/Blessings/Text.hs b/src/Blessings/Text.hs index 236b5d0..4516d72 100644 --- a/src/Blessings/Text.hs +++ b/src/Blessings/Text.hs @@ -15,5 +15,6 @@ instance Blessable Text where drop = T.drop take = T.take splitAt = T.splitAt + break = T.break intercalate = T.intercalate fromWord8 = T.pack . show diff --git a/src/Blessings/Text/WCWidth.hs b/src/Blessings/Text/WCWidth.hs index 277e1a1..ccc0864 100644 --- a/src/Blessings/Text/WCWidth.hs +++ b/src/Blessings/Text/WCWidth.hs @@ -18,6 +18,7 @@ instance Blessable Text where drop = drop' take = take' splitAt = splitAt' + break = Text.break intercalate = Text.intercalate fromWord8 = Text.pack . show -- cgit v1.2.3