align-equal (empty) → 0.1.0.0
raw patch · 4 files changed
+84/−0 lines, 4 filesdep +basedep +safedep +text
Dependencies added: base, safe, text
Files
- CHANGELOG.md +5/−0
- LICENSE +3/−0
- align-equal.cabal +30/−0
- app/Main.hs +46/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for align-equal++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,3 @@+Copyright (c) 2025 Joonkyu Park+Original code by Gabriella Gonzalez, licensed under Creative Commons Attribution 4.0 International.+Modifications licensed under the MIT License.
+ align-equal.cabal view
@@ -0,0 +1,30 @@+cabal-version: 3.0+name: align-equal+version: 0.1.0.0+license: MIT+license-file: LICENSE+author: Joonkyu Park (based on original work by Gabriella Gonzalez)+build-type: Simple+extra-doc-files: CHANGELOG.md+synopsis: Aligns text prefixes before '=' for consistent formatting+description: A utility to adjust text lines by padding spaces before '=' based on the longest prefix.+category: Text+maintainer: vpark45@gmail.com++source-repository head+ type: darcs+ location: https://hub.darcs.net/vincent/align-equal++common warnings+ ghc-options: -Wall++executable align-equal+ import: warnings+ main-is: Main.hs+ build-depends:+ base ^>=4.17.2.1,+ safe >=0.3.21 && <0.4,+ text >=2.0.2 && <2.1,++ hs-source-dirs: app+ default-language: Haskell2010
+ app/Main.hs view
@@ -0,0 +1,46 @@+{-# 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++main :: IO ()+main = TIO.interact adjustText