Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package ghc-word-wrap for openSUSE:Factory checked in at 2021-10-12 21:49:11 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-word-wrap (Old) and /work/SRC/openSUSE:Factory/.ghc-word-wrap.new.2443 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-word-wrap" Tue Oct 12 21:49:11 2021 rev:5 rq:923804 version:0.5 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-word-wrap/ghc-word-wrap.changes 2020-12-22 11:49:13.297996191 +0100 +++ /work/SRC/openSUSE:Factory/.ghc-word-wrap.new.2443/ghc-word-wrap.changes 2021-10-12 21:50:26.691965476 +0200 @@ -1,0 +2,14 @@ +Mon Sep 27 13:51:39 UTC 2021 - [email protected] + +- Update word-wrap to version 0.5. + 0.5 + === + + API changes: + * Line-wrapping now supports optional "filling", i.e., placing prefix + strings at the start of wrapped lines. The behavior of filling is + configured by new `WrapSettings` fields: `fillStrategy` (what to + add to filled lines) and `fillScope` (which lines to affect with + filling). Thanks to Brent Yorgey for this work! + +------------------------------------------------------------------- Old: ---- word-wrap-0.4.1.tar.gz word-wrap.cabal New: ---- word-wrap-0.5.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-word-wrap.spec ++++++ --- /var/tmp/diff_new_pack.AvnVtR/_old 2021-10-12 21:50:27.171966164 +0200 +++ /var/tmp/diff_new_pack.AvnVtR/_new 2021-10-12 21:50:27.175966169 +0200 @@ -1,7 +1,7 @@ # # spec file for package ghc-word-wrap # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -19,13 +19,12 @@ %global pkg_name word-wrap %bcond_with tests Name: ghc-%{pkg_name} -Version: 0.4.1 +Version: 0.5 Release: 0 Summary: A library for word-wrapping License: BSD-3-Clause URL: https://hackage.haskell.org/package/%{pkg_name} Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz -Source1: https://hackage.haskell.org/package/%{pkg_name}-%{version}/revision/1.cabal#/%{pkg_name}.cabal BuildRequires: ghc-Cabal-devel BuildRequires: ghc-rpm-macros BuildRequires: ghc-text-devel @@ -49,7 +48,6 @@ %prep %autosetup -n %{pkg_name}-%{version} -cp -p %{SOURCE1} %{pkg_name}.cabal %build %ghc_lib_build ++++++ word-wrap-0.4.1.tar.gz -> word-wrap-0.5.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/word-wrap-0.4.1/CHANGELOG.md new/word-wrap-0.5/CHANGELOG.md --- old/word-wrap-0.4.1/CHANGELOG.md 2017-08-08 00:30:19.000000000 +0200 +++ new/word-wrap-0.5/CHANGELOG.md 2001-09-09 03:46:40.000000000 +0200 @@ -1,4 +1,14 @@ +0.5 +=== + +API changes: + * Line-wrapping now supports optional "filling", i.e., placing prefix + strings at the start of wrapped lines. The behavior of filling is + configured by new `WrapSettings` fields: `fillStrategy` (what to + add to filled lines) and `fillScope` (which lines to affect with + filling). Thanks to Brent Yorgey for this work! + 0.4.1 ===== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/word-wrap-0.4.1/src/Text/Wrap.hs new/word-wrap-0.5/src/Text/Wrap.hs --- old/word-wrap-0.4.1/src/Text/Wrap.hs 2017-08-08 00:30:19.000000000 +0200 +++ new/word-wrap-0.5/src/Text/Wrap.hs 2001-09-09 03:46:40.000000000 +0200 @@ -1,5 +1,7 @@ module Text.Wrap - ( WrapSettings(..) + ( FillStrategy(..) + , FillScope(..) + , WrapSettings(..) , defaultWrapSettings , wrapTextToLines @@ -11,6 +13,27 @@ import Data.Char (isSpace) import qualified Data.Text as T +-- | How should wrapped lines be filled (i.e. what kind of prefix +-- should be attached?) +data FillStrategy + = NoFill -- ^ Don't do any filling (default) + | FillIndent Int -- ^ Indent by this many spaces + | FillPrefix T.Text -- ^ Prepend this text + deriving (Eq, Show, Read) + +fillWidth :: FillStrategy -> Int +fillWidth NoFill = 0 +fillWidth (FillIndent n) = n +fillWidth (FillPrefix t) = T.length t + +-- | To which lines should the fill strategy be applied? +data FillScope + = FillAfterFirst -- ^ Apply any fill prefix only to lines after + -- the first line (default) + | FillAll -- ^ Apply any fill prefix to all lines, even + -- if there is only one line + deriving (Eq, Show, Read) + -- | Settings to control how wrapping is performed. data WrapSettings = WrapSettings { preserveIndentation :: Bool @@ -19,6 +42,12 @@ , breakLongWords :: Bool -- ^ Whether to break in the middle of the first word -- on a line when that word exceeds the wrapping width. + , fillStrategy :: FillStrategy + -- ^ What kind of prefix should be applied to lines + -- after wrapping? (default: none) + , fillScope :: FillScope + -- ^ To which lines should the fill strategy be applied? + -- (default: all but the first) } deriving (Eq, Show, Read) @@ -26,12 +55,35 @@ defaultWrapSettings = WrapSettings { preserveIndentation = False , breakLongWords = False + , fillStrategy = NoFill + , fillScope = FillAfterFirst } +-- | Apply a function to the portion of a list of lines indicated by +-- the 'FillScope'. +withScope :: FillScope -> (a -> a) -> [a] -> [a] +withScope FillAfterFirst = onTail +withScope FillAll = map + +-- | Map a function over the tail of a list. +onTail :: (a -> a) -> [a] -> [a] +onTail _ [] = [] +onTail f (a:as) = a : map f as + +-- | Apply the fill specified in the 'WrapSettings' to a list of lines. +applyFill :: WrapSettings -> [T.Text] -> [T.Text] +applyFill settings = + let scope = fillScope settings + in case fillStrategy settings of + NoFill -> id + FillIndent n -> withScope scope (T.append (T.replicate n (T.pack " "))) + FillPrefix t -> withScope scope (T.append t) + -- | Wrap text at the specified width. Newlines and whitespace in the --- input text are preserved. Returns the lines of text in wrapped form. --- New lines introduced due to wrapping will have leading whitespace --- stripped. +-- input text are preserved. Returns the lines of text in wrapped +-- form. New lines introduced due to wrapping will have leading +-- whitespace stripped prior to having any fill applied. Preserved +-- indentation is always placed before any fill. wrapTextToLines :: WrapSettings -> Int -> T.Text -> [T.Text] wrapTextToLines settings amt s = concat $ fmap (wrapLine settings amt) $ T.lines s @@ -73,20 +125,28 @@ -- ^ A single line of text. -> [T.Text] wrapLine settings limit t = - let go _ [] = [T.empty] + let restFillWidth = fillWidth (fillStrategy settings) + firstLineFillWidth = if fillScope settings == FillAll then restFillWidth else 0 + + firstLineLimit = limit - T.length indent - firstLineFillWidth + restLimit = limit - T.length indent - restFillWidth + + go _ [] = [T.empty] go _ [WS _] = [T.empty] - go lim ts = - let (firstLine, maybeRest) = breakTokens settings lim ts + go isFirstLine ts = + let lim = if isFirstLine then firstLineLimit else restLimit + (firstLine, maybeRest) = breakTokens settings lim ts firstLineText = T.stripEnd $ T.concat $ fmap tokenContent firstLine in case maybeRest of - Nothing -> [firstLineText] - Just rest -> firstLineText : go lim rest + Nothing -> [firstLineText] + Just rest -> firstLineText : go False rest (indent, modifiedText) = if preserveIndentation settings then let i = T.takeWhile isSpace t in (T.take (limit - 1) i, T.drop (T.length i) t) else (T.empty, t) - result = go (limit - T.length indent) (tokenize modifiedText) - in (indent <>) <$> result + + result = go True (tokenize modifiedText) + in map (indent <>) . applyFill settings $ result -- | Break a token sequence so that all tokens up to but not exceeding -- a length limit are included on the left, and if any remain on the diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/word-wrap-0.4.1/tests/Main.hs new/word-wrap-0.5/tests/Main.hs --- old/word-wrap-0.4.1/tests/Main.hs 2017-08-08 00:30:19.000000000 +0200 +++ new/word-wrap-0.5/tests/Main.hs 2001-09-09 03:46:40.000000000 +0200 @@ -64,3 +64,65 @@ } wrapTextToLines s 4 " foo bar" `shouldBe` [" f", " o", " o", " b", " a", " r"] + + it "indents all but the first line" $ do + let s = defaultWrapSettings { fillStrategy = FillIndent 2 } + wrapTextToLines s 8 "Hello there, World!" + `shouldBe` ["Hello", " there,", " World!"] + + it "indents all lines" $ do + let s = defaultWrapSettings { fillStrategy = FillIndent 2 + , fillScope = FillAll + } + wrapTextToLines s 8 "Hello there, World!" + `shouldBe` [" Hello", " there,", " World!"] + + it "fills all lines but the first with a prefix" $ do + let s = defaultWrapSettings { fillStrategy = FillPrefix "- " } + wrapTextToLines s 8 "Hello there, World!" + `shouldBe` ["Hello", "- there,", "- World!"] + + it "fills all lines with a prefix" $ do + let s = defaultWrapSettings { fillStrategy = FillPrefix "- " + , fillScope = FillAll + } + wrapTextToLines s 8 "Hello there, World!" + `shouldBe` ["- Hello", "- there,", "- World!"] + + it "takes fill width into account" $ do + let s = defaultWrapSettings { fillStrategy = FillPrefix "- " } + wrapTextToLines s 3 "a b c d" + `shouldBe` ["a b", "- c", "- d"] + + it "takes fill indent into account" $ do + let s = defaultWrapSettings { fillStrategy = FillIndent 2 } + wrapTextToLines s 3 "a b c d" + `shouldBe` ["a b", " c", " d"] + + it "takes fill width into account on all lines" $ do + let s = defaultWrapSettings { fillStrategy = FillPrefix "- " + , fillScope = FillAll + } + wrapTextToLines s 3 "a b c d" + `shouldBe` ["- a", "- b", "- c", "- d"] + + it "takes fill indent into account on all lines" $ do + let s = defaultWrapSettings { fillStrategy = FillIndent 2 + , fillScope = FillAll + } + wrapTextToLines s 3 "a b c d" + `shouldBe` [" a", " b", " c", " d"] + + it "places fill after preserved indent" $ do + let s = defaultWrapSettings { preserveIndentation = True + , fillStrategy = FillPrefix "- " + } + wrapTextToLines s 5 " a b c d" + `shouldBe` [" a b", " - c", " - d"] + + it "places fill indent after preserved indent" $ do + let s = defaultWrapSettings { preserveIndentation = True + , fillStrategy = FillIndent 2 + } + wrapTextToLines s 5 " a b c d" + `shouldBe` [" a b", " c", " d"] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/word-wrap-0.4.1/word-wrap.cabal new/word-wrap-0.5/word-wrap.cabal --- old/word-wrap-0.4.1/word-wrap.cabal 2017-08-08 00:30:19.000000000 +0200 +++ new/word-wrap-0.5/word-wrap.cabal 2001-09-09 03:46:40.000000000 +0200 @@ -1,5 +1,5 @@ name: word-wrap -version: 0.4.1 +version: 0.5 synopsis: A library for word-wrapping description: A library for wrapping long lines of text. license: BSD3 @@ -9,7 +9,7 @@ copyright: 2017 Jonathan Daugherty category: Text build-type: Simple -cabal-version: >=1.18 +cabal-version: 1.18 Homepage: https://github.com/jtdaugherty/word-wrap/ Bug-reports: https://github.com/jtdaugherty/word-wrap/issues @@ -28,7 +28,7 @@ hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall - build-depends: base < 5, + build-depends: base >= 4.8 && < 5, text benchmark word-wrap-benchmarks
