packages feed

align-equal 0.1.0.1 → 0.1.1.0

raw patch · 4 files changed

+120/−44 lines, 4 filesdep +align-equal

Dependencies added: align-equal

Files

+ CHANGELOG.md view
@@ -0,0 +1,24 @@+# Changelog+All notable changes to the `align-equal` project will be documented in this file.++## [0.1.1.0] - 2025-03-27+- **Added**: Extracted core functions into a separate library module (`Data.Text.AlignEqual`).+  - Refactored original `Main.hs` into executable and library components.+  - Added `src/Data/Text/AlignEqual.hs` with core text alignment logic.+  - Updated `app/Main.hs` to import and use `Data.Text.AlignEqual`.+  - Adjusted `.cabal` file to include a new library section and dependencies.+- **Added**: Haddock documentation for `Data.Text.AlignEqual`.+  - Documented module purpose, `prefixLength`, `adjustLine`, and `adjustText` with descriptions, examples, and parameter annotations.+- **Added**: Included `CHANGELOG.md` in the package documentation via `extra-doc-files` in `.cabal`.+- **Maintained**: Compatibility with the existing executable.++## [0.1.0.1] - 2025-03-10+- **Fixed**: Relaxed `base` dependency constraint to `>=4.17 && <4.19`.+- **Fixed**: Removed duplicate `extra-doc-files` entry in `.cabal` file.+- **Added**: `README.md` with credit to Gabriella Gonzalez.+- **Added**: Source repository link to `hub.darcs.net` in `.cabal` file.++## [0.1.0.0] - 2025-03-10+- **Initial Release**: Basic functionality for aligning text with equal signs.+  - Implemented as a standalone executable in `Main.hs`.+  - Initial project setup with `.cabal` and `LICENSE` files.
align-equal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: align-equal-version: 0.1.0.1+version: 0.1.1.0 license: MIT license-file: LICENSE author: Joonkyu Park (based on original work by Gabriella Gonzalez)@@ -9,7 +9,10 @@ description: A utility to adjust text lines by padding spaces before '=' based on the longest prefix. category: Text maintainer: vpark45@gmail.com-extra-doc-files: README.md+bug-reports: https://hub.darcs.net/vincent/align-equal/issues+extra-doc-files:+  CHANGELOG.md+  README.md  source-repository head   type: darcs@@ -22,9 +25,20 @@   import: warnings   main-is: Main.hs   build-depends:+    align-equal,     base >=4.17 && <4.19,-    safe >=0.3.21 && <0.4,     text >=2.0.2 && <2.1,    hs-source-dirs: app+  default-language: Haskell2010++library+  import: warnings+  exposed-modules: Data.Text.AlignEqual+  build-depends:+    base >=4.17 && <4.19,+    safe >=0.3.21 && <0.4,+    text >=2.0.2 && <2.1,++  hs-source-dirs: src   default-language: Haskell2010
app/Main.hs view
@@ -1,46 +1,7 @@-{-# LANGUAGE OverloadedStrings #-}- module Main where -import           Data.Text    (Text)--import qualified Data.Text    as T-import qualified Data.Text.IO as TIO-import           Safe--prefixLength :: Text -> Int-prefixLength line = T.length prefix-  where-    (prefix, _) = T.breakOn "=" line--adjustLine :: Int -> Text -> Text-adjustLine desiredPrefixLength oldLine = newLine-  where-    (prefix, suffix) = T.breakOn "=" oldLine--    actualPrefixLength = T.length prefix--    additionalSpaces = desiredPrefixLength - actualPrefixLength--    spaces = T.replicate additionalSpaces " "--    newLine = T.concat [ prefix, spaces, suffix ]--adjustText :: Text -> Text-adjustText oldText = newText-  where-    oldLines = T.lines oldText--    prefixLengths = map prefixLength oldLines--    newLines =-      case maximumMay prefixLengths of-        Nothing ->-          []-        Just desiredPrefixLength ->-          map (adjustLine desiredPrefixLength) oldLines--    newText = T.unlines newLines+import           Data.Text.AlignEqual+import qualified Data.Text.IO         as TIO  main :: IO () main = TIO.interact adjustText
+ src/Data/Text/AlignEqual.hs view
@@ -0,0 +1,77 @@+{-# LANGUAGE OverloadedStrings #-}++-- | A module providing functions for text alignment and padding.+module Data.Text.AlignEqual where++import           Data.Text (Text)+import qualified Data.Text as T+import           Safe++-- | Calculates the number of characters preceding the first '=' sign in a text line.+--+-- >>> prefixLength "key=value"+-- 3+-- >>> prefixLength "a=b"+-- 1+-- >>> prefixLength "noequals"+-- 8+prefixLength+  :: Text+  -- ^ The input text line+  -> Int+  -- ^ The number of characters before the first '=' sign+prefixLength line = T.length prefix+  where+    (prefix, _) = T.breakOn "=" line++-- | Adjusts the prefix of a text line to a desired length by adding padding.+--+-- >>> adjustLine 5 "key=value"+-- "key  =value"+-- >>> adjustLine 3 "a=b"+-- "a  =b"+adjustLine+  :: Int+  -- ^ The desired prefix length+  -> Text+  -- ^ The text line to pad+  -> Text+  -- ^ The padded text line+adjustLine desiredPrefixLength oldLine = newLine+  where+    (prefix, suffix) = T.breakOn "=" oldLine++    actualPrefixLength = T.length prefix++    additionalSpaces = desiredPrefixLength - actualPrefixLength++    spaces = T.replicate additionalSpaces " "++    newLine = T.concat [ prefix, spaces, suffix ]++-- | Processes multi-line text to align all '=' signs across lines.+--   Adjusts the prefix length of each line to match the maximum prefix length.+--+-- >>> adjustText "key=value\na=b"+-- "key=value\na  =b"+-- >>> adjustText "x=y\nlong=var"+-- "x   =y\nlong=var"+adjustText+  :: Text+  -- ^ The input text (possibly multi-line)+  -> Text+  -- ^ The aligned text+adjustText oldText = newText+  where+    oldLines = T.lines oldText++    prefixLengths = map prefixLength oldLines++    newLines =+      case maximumMay prefixLengths of+        Nothing ->+          []+        Just desiredPrefixLength ->+          map (adjustLine desiredPrefixLength) oldLines++    newText = T.unlines newLines