packages feed

gvti 0.3.1.0 → 0.4.0.0

raw patch · 5 files changed

+84/−32 lines, 5 filesdep +cli-argumentsPVP ok

version bump matches the API change (PVP)

Dependencies added: cli-arguments

API changes (from Hackage documentation)

- GVTI: process2 :: String -> String -> String -> String -> String -> String -> String -> IO ()
+ GVTI: process2 :: String -> String -> String -> String -> String -> String -> Maybe (Double, Double) -> String -> String -> IO ()

Files

ChangeLog.md view
@@ -28,3 +28,9 @@  * Third version revised A. Changed the name of the module Formatting to GVTI.Formatting to follow the semantics of the modules names. +## 0.4.0.0 -- 2023-05-11++* Fourth version. Added two new command line parameters and arguments to the function process2.+Updated the README.md file with the related information. Some code deduplication. Added devotion+to the project. Added cli-arguments as a new lightweight dependency for the project.+
GVTI.hs view
@@ -28,7 +28,8 @@ import System.Process (callCommand) import GHC.Arr import EndOfExe (showE)-import Data.Maybe (isJust,fromJust)+import Data.Maybe (isJust,fromJust,isNothing)+import Text.Read (readMaybe) import qualified Data.Foldable as F (foldr)  isSep :: Char -> Bool@@ -74,12 +75,12 @@ linesL1 :: String -> ([String],Int) linesL1 = linesL ([],-1) -processCells :: String -> Array Int [String] -> String-processCells xs arr = makeRecordGv xs . convertElemsToStringGv . filterNeeded . changeNeededCells $ arr+processCells :: String -> Maybe (Double, Double) -> String -> Array Int [String] -> String+processCells xs size ratio arr = makeRecordGv xs size ratio . convertElemsToStringGv . filterNeeded . changeNeededCells $ arr {-# INLINE processCells #-} -processCellsG :: String -> String -> String -> String-processCellsG delims xs = processCells xs . cells delims+processCellsG :: String -> String -> Maybe (Double, Double) -> String -> String -> String+processCellsG delims xs size ratio = processCells xs size ratio . cells delims {-# INLINE processCellsG #-}  -- | Do not change the lengths of element lists@@ -116,7 +117,7 @@ convertElemsToStringGv arr = (amap convertLineToStrGv arr, findAndMakeFilledWithClr arr)  convertLineToStrGv :: [String] -> String-convertLineToStrGv xss = "\"" ++ (let ys = concatMap (++"\"->\"") xss in take (length ys - 3) ys) ++ endOfLineGv+convertLineToStrGv xss = "\"" `mappend` (let ys = concatMap (`mappend`"\"->\"") xss in take (length ys - 3) ys) `mappend` endOfLineGv {-# INLINE convertLineToStrGv #-}  endOfLineGv :: String@@ -135,35 +136,48 @@ {-# INLINE lineWithAtSign #-}  beginsWithAtSign :: String -> Bool-beginsWithAtSign xs = if take 1 xs == "@" then True else take 2 xs == "\"@"+beginsWithAtSign xs + | take 1 xs == "@" = True + | otherwise = take 2 xs == "\"@" {-# INLINE beginsWithAtSign #-}  -- | Makes all needed additions and synthesizes into a single 'String' ready to be recorded to the .gv file.-makeRecordGv :: String -> (Array Int String, String) -> String-makeRecordGv xs (arr1,str2) = mconcat ["strict digraph 1 {", endOfLineGv, "overlap=false", endOfLineGv, "splines=",+makeRecordGv :: String -> Maybe (Double, Double) -> String -> (Array Int String, String) -> String+makeRecordGv xs size ratio (arr1,str2) = mconcat ["strict digraph 1 {", endOfLineGv, sizeF size endOfLineGv, ratioF ratio endOfLineGv, "overlap=false", endOfLineGv, "splines=",   case xs of { "0" -> "false" ; "1" -> "true" ; "2" -> "ortho" ; "3" -> "polyline" ; ~vvv -> "true" }, endOfLineGv,     mconcat (elems arr1 `mappend` [str2]), "}", endOfLineGv]+       where sizeF si@(Just (x,y)) ks = "size=\"" `mappend` show x `mappend` "," `mappend` show y `mappend` "\"" `mappend` ks+             sizeF _ _ = ""+             ratioF ks js +               | isNothing rRat = +                   if ks `elem` ["fill","compress","auto"] +                       then "ratio=" `mappend` ks `mappend` js+                       else ""+               | otherwise = "ratio=" `mappend` show (fromJust rRat) `mappend` js+                     where rRat = readMaybe ratio::Maybe Double {-# INLINE makeRecordGv #-}  -- | Processes the given text (the first 'String' argument). The second one is used to get a name of the command to be -- executed to obtain a visualization file. The third argument is used for the 'getFormat'. The fourth argument is the -- basic name for the created files (without prefixes and extensions), the fifth one is an option for GraphVize splines -- functionality. The sixth argument is used to specify whether to remove at-signs from the created files.-process2 :: String -> String -> String -> String -> String -> String -> String -> IO ()-process2 delims xxs yys bnames splines remAts text-  | length text > 0 = do+process2 :: String -> String -> String -> String -> String -> String -> Maybe (Double, Double) -> String -> String -> IO ()+process2 delims xxs yys bnames splines remAts sizes ratio text+ | null text = error "GVTI.process2: Empty text to be processed! "+ | otherwise = do       ts <- getCPUTime       [bnames1,splines1] <- proc2Params2 bnames splines-      if remAts == "y"-        then do-          let ys = filter (/='@') . processCellsG delims splines1 $ text in writeFile (show ts ++ "." ++ bnames1 ++ ".gv") ys-          putStrLn "The visualization will be created without the at-sign."-          processFile 'n' ts bnames1 xxs yys-        else do-          let ys = processCellsG delims splines1 text in writeFile ("at." ++ show ts ++ "." ++ bnames1 ++ ".gv") ys-          putStrLn "The visualization will be created with the at-sign preserved."-          processFile 'a' ts bnames1 xxs yys-  | otherwise = error "GVTI.process2: Empty text to be processed! "+      let ys = g (remAts == "y") . processCellsG delims splines1 sizes ratio $ text in writeFile (f (remAts == "y") (show ts `mappend` "." `mappend` bnames1 `mappend` ".gv")) ys+      putStrLn $ "The visualization will be created with" `mappend` (if remAts == "y" then "out" else "") `mappend` " the at-sign."+      processFile (if remAts == "y" +                       then 'n'+                       else 'a') ts bnames1 xxs yys+       where f bool ys+               | bool = ys+               | otherwise = "at." `mappend` ys+             g bool +               | bool = filter (/='@')+               | otherwise = id                 procCtrl :: Int -> IO String procCtrl 1 = putStrLn "Please, input the basic name of the visualization file!" >> getLine@@ -194,7 +208,7 @@       let temp = fromJust . showE . (\x -> case x of { "c" -> "circo" ; "d" -> "dot" ; "f" -> "fdp" ; "n" -> "neato" ;            "o" ->"osage" ; "p" -> "patchwork" ; "s" -> "sfdp" ; "t" -> "twopi" ; ~vv -> "sfdp" })           q = getFormat spec-      callCommand $ temp u ++ (if w == 'n' then " -T" ++ q ++ " " else " -T" ++ q ++ " at.") ++ show t ++ "." ++ zs ++ ".gv -O "+      callCommand $ temp u `mappend` (if w == 'n' then " -T" `mappend` q `mappend` " " else " -T" `mappend` q `mappend` " at.") `mappend` show t `mappend` "." `mappend` zs `mappend` ".gv -O "  proc2Params :: String -> String -> IO [String] proc2Params xxs yys@@ -231,13 +245,13 @@ {-# INLINE getFormat #-}  printFormF :: String -> IO ()-printFormF xs = putStrLn $ show xs ++ " -- for -T" ++ case xs of { "cm" -> "cmapx" ; "do" -> "dot" ; "fi" -> "fig" ;+printFormF xs = putStrLn $ show xs `mappend` " -- for -T" `mappend` case xs of { "cm" -> "cmapx" ; "do" -> "dot" ; "fi" -> "fig" ;    "gi" -> "gif" ; "im" -> "imap" ; "je" -> "jpeg" ; "jp" -> "jpg" ; "js" -> "json" ; "pd" -> "pdf" ; "pn" -> "png" ;-      "ps" -> "ps" ; "sv" -> "svg" ; "sz" -> "svgz" ; "xd" -> "xdot" ; ~vvv -> "svg" } ++ "\""+      "ps" -> "ps" ; "sv" -> "svg" ; "sz" -> "svgz" ; "xd" -> "xdot" ; ~vvv -> "svg" } `mappend` "\"" {-# INLINE printFormF #-}  printGraphFilter :: String -> IO ()-printGraphFilter xs = putStrLn $ show (take 1 xs) ++ " -- for " ++ case take 1 xs of { "c" -> "circo" ; "d" -> "dot" ;+printGraphFilter xs = putStrLn $ show (take 1 xs) `mappend` " -- for " `mappend` case take 1 xs of { "c" -> "circo" ; "d" -> "dot" ;   "f" -> "fdp" ; "n" -> "neato" ; "o" -> "osage" ; "p" -> "patchwork" ; "s" -> "sfdp" ; "t" -> "twopi" ;     ~vvv ->  "sfdp" } {-# INLINE printGraphFilter #-}
Main.hs view
@@ -24,11 +24,22 @@ import Data.List (isPrefixOf, lines, unlines) import Data.Char (isLetter, isDigit)  import GVTI.Formatting (formatLines)+import CLI.Arguments.Parsing+import CLI.Arguments+import CLI.Arguments.Get+import Data.Maybe (fromJust, isNothing)+import Text.Read (readMaybe)  main :: IO () main = do -  args00 <- getArgs-  let args = filter (/= "-g") args00+  args000 <- getArgs+  let (bs, args00) = takeBsR bSpecs args000+      sizesMaybe = getB "-i" bs+      sizes+        | length sizesMaybe == 2 = (\(x:y:_) -> if isNothing x || isNothing y then Nothing else Just (fromJust x, fromJust y)) . fmap (\js -> readMaybe js::Maybe Double) $ sizesMaybe+        | otherwise = Nothing+      ratio = concat . getB "-r" $ bs+      args = filter (/= "-g") args00       arg0 = concat . take 1 $ args       arggs = drop 1 args       xxs = take 1 . drop 2 . concat . filter ("-c" `isPrefixOf`) $ arggs@@ -47,5 +58,8 @@       let txt             | gvti = unlines  . formatLines (head delims) . filter (any (\x -> isLetter x || isDigit x)) . lines $ text2            | otherwise =  unlines . filter (any (\x -> isLetter x || isDigit x)) . lines $ text2-      process2 delims xxs yys bnames splines remAts txt+      process2 delims xxs yys bnames splines remAts sizes ratio txt     else error "Main: No file specified exists in the current directory! "  +++bSpecs = [("-i",2),("-r",1)]
README.markdown view
@@ -109,6 +109,15 @@ -y — (if present) means that the '@' signs will be removed from the created  files. +Since version 0.4.0.0 it also supports the following option for the command line +(they are not customizable in the interactive mode of the executable).++-i x y — (if present) specifies the maximum bounding box of drawing in inches.++-r ... - (if present) sets the aspect ratio to the value at the dots position here, +which may be a floating point number, or one of the keywords fill, +compress, or auto.+ They can be given in any combinations (if needed) or omitted. In the latter  one case the program will prompt you the needed information (but this is  not the case for a separator, which must be specified in such a way to be @@ -178,4 +187,13 @@  https://hackage.haskell.org/package/gvti-0.2.0.0/src/4895040000.example.neato.gv.svg ++ Devotion+ ========++Since the version 0.4.0.0 the author would like to devote this project to support the Foundation Gastrostars.+If you would like to share some financial support, please, contact the foundation+using the URL:++[Contact Foundation GASTROSTARS](https://gastrostars.nl/hou-mij-op-de-hoogte) 
gvti.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                gvti-version:             0.3.1.0+version:             0.4.0.0 synopsis:            GraphViz Tabular Interface description:         Introduces a new file extension .gvti and is a special tabular or line-based GraphViz subset interface. Is a fork of the now deprecated mmsyn4 package. homepage:            https://hackage.haskell.org/package/gvti@@ -20,7 +20,7 @@   exposed-modules:     GVTI, GVTI.Formatting   -- other-modules:   other-extensions:    BangPatterns, NoImplicitPrelude-  build-depends:       base >=4.13 && <5, directory >=1.3.4.0 && <2, process >=1.6.5.1 && <2, mmsyn3 ==0.2.0.0+  build-depends:       base >=4.13 && <5, directory >=1.3.4.0 && <2, process >=1.6.5.1 && <2, mmsyn3 ==0.2.0.0, cli-arguments ==0.7.0.0   -- hs-source-dirs:   default-language:    Haskell2010 @@ -28,6 +28,6 @@   main-is:             Main.hs   other-modules:       GVTI, GVTI.Formatting   other-extensions:    BangPatterns, NoImplicitPrelude-  build-depends:       base >=4.13 && <5, directory >=1.3.4.0 && <2, process >=1.6.5.1 && <2, mmsyn3 ==0.2.0.0+  build-depends:       base >=4.13 && <5, directory >=1.3.4.0 && <2, process >=1.6.5.1 && <2, mmsyn3 ==0.2.0.0, cli-arguments ==0.7.0.0   -- hs-source-dirs:   default-language:    Haskell2010