packages feed

gotta-go-fast 0.1.3.1 → 0.1.4.0

raw patch · 3 files changed

+31/−55 lines, 3 filesdep +textdep +word-wrapdep ~brick

Dependencies added: text, word-wrap

Dependency ranges changed: brick

Files

gotta-go-fast.cabal view
@@ -1,5 +1,5 @@ name:                gotta-go-fast-version:             0.1.3.1+version:             0.1.4.0 synopsis:            A command line utility for practicing typing description:   A command line utility for practicing typing and measuring your WPM and accuracy. See the project <https://github.com/hot-leaf-juice/gotta-go-fast/blob/master/README.md README> for details.@@ -17,11 +17,12 @@   hs-source-dirs:      src   other-modules:       GottaGoFast                      , UI-                     , FormatCode   main-is:             Main.hs   ghc-options:         -threaded   build-depends:       base >=4.9 && <4.11-                     , brick+                     , brick >= 0.21+                     , word-wrap >= 0.4.1+                     , text                      , cmdargs                      , directory                      , random
− src/FormatCode.hs
@@ -1,48 +0,0 @@-module FormatCode (toAscii, trimEmptyLines, wordWrap) where--import Data.Char (isAscii, isPrint)--toAscii :: Int -> String -> String-toAscii tabWidth = concatMap toAscii'-  where-    toAscii' c-      | c == '\t' = replicate tabWidth ' '-      | c == '‘' || c == '’' = "'"-      | c == '“' || c == '”' = "\""-      | c == '–' || c == '—' = "-"-      | c == '…' = "..."-      | isAscii c && (isPrint c || c == '\n') = [c]-      | otherwise = ""--trimEmptyLines :: String -> String-trimEmptyLines = (++ "\n") . f . f-  where-    f = reverse . dropWhile (== '\n')--getIndent :: String -> String-getIndent = takeWhile (== ' ')--ensureEndWithNewline :: String -> String-ensureEndWithNewline "" = "\n"-ensureEndWithNewline s-  | last s == '\n' = s-  | otherwise = s ++ "\n"---- TODO Replace this atrocity with a library function (which is currently--- buggy, need to submit a PR).-wordWrap :: Int -> String -> String-wordWrap n = result . foldl greedy ("", "", "", "") . ensureEndWithNewline-  where-    result (acc, _, _, _) = acc-    greedy (acc, l, s, w) '\n'-      | length (l ++ s ++ w) <= n = (acc ++ l ++ s ++ w ++ "\n", "", "", "")-      | otherwise = (acc ++ l ++ "\n" ++ getIndent l ++ w ++ "\n", "", "", "")-    greedy (acc, l, s, "") ' ' = (acc, l, s ++ " ", "")-    greedy (acc, l, s, w) ' '-      | length (l ++ s ++ w) <= n = (acc, l ++ s ++ w, " ", "")-      | otherwise = (acc ++ l ++ "\n", getIndent l ++ w, " ", "")-    greedy (acc, l, s, w) c-      | length (getIndent l ++ w) < n = (acc, l, s, w ++ [c])-      | l == "" = (acc ++ getIndent l ++ w ++ "\n", getIndent l, "", [c])-      | otherwise =-        (acc ++ l ++ "\n" ++ getIndent l ++ w ++ "\n", getIndent l, "", [c])
src/Main.hs view
@@ -2,15 +2,17 @@  module Main where -import Data.Word (Word8) import Control.Monad (filterM)+import Data.Word (Word8)+import Data.Char (isAscii, isPrint) import System.Console.CmdArgs   (Data, Typeable, args, cmdArgs, def, help, program, summary, typ, (&=)) import System.Directory (doesFileExist) import System.Random (randomRIO)+import Text.Wrap (wrapText, WrapSettings(..))+import qualified Data.Text as T  import UI (run)-import FormatCode (toAscii, trimEmptyLines, wordWrap)  data Config = Config   { height :: Int@@ -21,6 +23,23 @@   , fg_error :: Word8   } deriving (Show, Data, Typeable) +toAscii :: Int -> String -> String+toAscii tabWidth = concatMap toAscii'+  where+    toAscii' c+      | c == '\t' = replicate tabWidth ' '+      | c == '‘' || c == '’' = "'"+      | c == '“' || c == '”' = "\""+      | c == '–' || c == '—' = "-"+      | c == '…' = "..."+      | isAscii c && (isPrint c || c == '\n') = [c]+      | otherwise = ""++trimEmptyLines :: String -> String+trimEmptyLines = (++ "\n") . f . f+  where+    f = reverse . dropWhile (== '\n')+ config :: Config config = Config   { height = 20 &= typ "LINES" &=@@ -35,7 +54,7 @@     help "The ISO colour code for errors (default: 1)"   , files = def &= args &= typ "FILES"   }-  &= summary "Gotta Go Fast 0.1.3.1"+  &= summary "Gotta Go Fast 0.1.4.0"   &= help "Practice typing and measure your WPM and accuracy"   &= program "gotta-go-fast" @@ -46,7 +65,11 @@     where       ascii = toAscii (tab c) file       chop = unlines . take (height c) . lines-      wrap = wordWrap (width c)+      wrap = T.unpack . wrapText wrapSettings (width c) . T.pack+      wrapSettings = WrapSettings+        { preserveIndentation = True+        , breakLongWords = True+        }  main :: IO () main = do