packages feed

clisparkline (empty) → 0.1.0.0

raw patch · 6 files changed

+178/−0 lines, 6 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2019 Siddharth Bhat++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,18 @@+# clisparkline++Sparklines are tiny charts to visually present data, like so: `_▁▂▃▄▅▆▇█`++`clisparklines` is a tiny haskell library to print sparklines on the CLI.++##### Example program++```hs+import System.Console.Sparkline+main = putStrLn . series2spark $ [0, 1, 2, 3, 2, 1]+```++##### Output++```+_▂▅█▅▂+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ clisparkline.cabal view
@@ -0,0 +1,99 @@+cabal-version:       >=1.10++-- Initial package description 'clisparkline.cabal' generated by 'cabal+-- init'.  For further documentation, see+-- http://haskell.org/cabal/users-guide/++-- The name of the package.+name:                clisparkline++-- The package version.  See the Haskell package versioning policy (PVP)+-- for standards guiding when and how versions should be incremented.+-- https://pvp.haskell.org+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             0.1.0.0++-- A short (one-line) description of the package.+-- synopsis:++-- A longer description of the package.+-- description:++-- A URL where users can report bugs.+-- bug-reports:++-- The license under which the package is released.+license:             MIT++-- The file containing the license text.+license-file:        LICENSE++-- The package author(s).+author:              Siddharth Bhat++-- An email address to which users can send suggestions, bug reports, and+-- patches.+maintainer:          siddu.druid@gmail.com++-- A copyright notice.+-- copyright:++category:            Graphics++synopsis: Tiny library to pretty print sparklines onto the CLI++description: Print sparklines into the CLI. Example usage:+    > import System.Console.Sparkline+    > main = putStrLn . series2spark $ [0, 1, 2, 3, 2, 1]+    output is:+    > _▂▅█▅▂++build-type:          Simple++-- Extra files to be distributed with the package, such as examples or a+-- README.+extra-source-files:  README.md+                   +++library+  -- Modules exported by the library.+  exposed-modules:     System.Console.Sparkline++  -- Modules included in this library but not exported.+  -- other-modules:++  -- LANGUAGE extensions used by modules in this package.+  -- other-extensions:++  -- Other library packages from which modules are imported.+  build-depends:       base >=4.12 && <4.13++  -- Directories containing source files.+  hs-source-dirs:      lib++  -- Base language which the package is written in.+  default-language:    Haskell2010+++test-suite clisparkline-test+  -- Base language which the package is written in.+  default-language:    Haskell2010++  -- The interface type and version of the test suite.+  type:                exitcode-stdio-1.0++  -- The directory where the test specifications are found.+  hs-source-dirs:      test++  -- The entrypoint to the test suite.+  main-is:             MyLibTest.hs++  -- Test dependencies.+  build-depends:       base >=4.12 && <4.13++source-repository head+    type: git+    location: https://github.com/bollu/clisparkline.git
+ lib/System/Console/Sparkline.hs view
@@ -0,0 +1,35 @@+{-|+Module      : Sparkline+Description : generate string-sparklines to render to CLI from data+Copyright   : (c) Siddharth Bhat, 2019+License     : MIT+Maintainer  : siddu.druid@gmail.com++@series2sparkline@ allows one to convert a list of+@RealFloat@ into a string.++@seriesPrintSparkline@ prints a sparkline to stdout.+-}+module System.Console.Sparkline where++-- | Characters in the sparkline+sparkchars :: String+sparkchars = "_▁▂▃▄▅▆▇█"++-- | Convert an int to a sparkline character+num2sparkchar :: RealFrac a => a -- ^ Max value+  -> a -- ^ Current value+  -> Char+num2sparkchar maxv curv =+   sparkchars !!+     (floor $ (curv / maxv) * (fromIntegral (length sparkchars - 1)))++-- | Convert a series into a sparkline string+series2sparkline :: RealFrac a => [a] -> String+series2sparkline vs =+  let maxv = if null vs then 0 else maximum vs+  in map (num2sparkchar maxv) vs++-- | Print a series to stdout.+seriesPrintSparkline :: RealFrac a => [a] -> IO ()+seriesPrintSparkline = putStrLn . series2sparkline
+ test/MyLibTest.hs view
@@ -0,0 +1,4 @@+module Main (main) where++main :: IO ()+main = putStrLn "Test suite not yet implemented."