misfortune 0.1.1.2 → 0.1.2
raw patch · 8 files changed
+63/−45 lines, 8 filesdep +randomdep −semigroupsdep ~random-fudep ~utf8-stringnew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: random
Dependencies removed: semigroups
Dependency ranges changed: random-fu, utf8-string
API changes (from Hackage documentation)
- Data.Fortune: instance Bounded FortuneType
- Data.Fortune: instance Enum FortuneType
- Data.Fortune: instance Eq FortuneType
- Data.Fortune: instance Ord FortuneType
- Data.Fortune: instance Read FortuneType
- Data.Fortune: instance Show FortuneType
- Data.Fortune: stringBytes :: IndexEntry -> !Int
- Data.Fortune: stringChars :: IndexEntry -> !Int
- Data.Fortune: stringLines :: IndexEntry -> !Int
- Data.Fortune: stringOffset :: IndexEntry -> !Int
+ Data.Fortune: [stringBytes] :: IndexEntry -> !Int
+ Data.Fortune: [stringChars] :: IndexEntry -> !Int
+ Data.Fortune: [stringLines] :: IndexEntry -> !Int
+ Data.Fortune: [stringOffset] :: IndexEntry -> !Int
+ Data.Fortune: instance GHC.Classes.Eq Data.Fortune.FortuneType
+ Data.Fortune: instance GHC.Classes.Ord Data.Fortune.FortuneType
+ Data.Fortune: instance GHC.Enum.Bounded Data.Fortune.FortuneType
+ Data.Fortune: instance GHC.Enum.Enum Data.Fortune.FortuneType
+ Data.Fortune: instance GHC.Read.Read Data.Fortune.FortuneType
+ Data.Fortune: instance GHC.Show.Show Data.Fortune.FortuneType
- Data.Fortune: filterFortunes :: (Num a, Enum a) => (IndexEntry -> Bool) -> FortuneFile -> IO [a]
+ Data.Fortune: filterFortunes :: (Num b, Enum b) => (IndexEntry -> Bool) -> FortuneFile -> IO [b]
- Data.Fortune: filterFortunesM :: (Num a, Enum a) => (IndexEntry -> IO Bool) -> FortuneFile -> IO [a]
+ Data.Fortune: filterFortunesM :: (Num b, Enum b) => (IndexEntry -> IO Bool) -> FortuneFile -> IO [b]
- Data.Fortune: filterFortunesWithIndex :: (Num a, Enum a) => (a -> IndexEntry -> Bool) -> FortuneFile -> IO [a]
+ Data.Fortune: filterFortunesWithIndex :: (Num t, Enum t) => (t -> IndexEntry -> Bool) -> FortuneFile -> IO [t]
Files
- LICENSE +21/−0
- README.md +2/−2
- misfortune.cabal +32/−21
- src/Data/Fortune.hs +4/−3
- src/Data/Fortune/FortuneFile.hs +0/−1
- src/Data/Fortune/Index.hs +0/−2
- src/Fortune.hs +4/−3
- src/StrFile.hs +0/−13
+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2022 Naïm Favier++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
@@ -1,4 +1,4 @@-misfortune +misfortune =========== This is a fortune-mod clone. In addition to the features generally expected of a `fortune` program, this can be used as a Haskell library (`import Data.Fortune`) and also supports UTF-8 fortune files, configurable search paths, automatic merging of fortune databases with the same name (so you can have a local fortunes folder that just adds to existing fortune databases), filtering fortunes by line lengths, and a "print fortune matching regex" mode (instead of just "print all fortunes matching regex" mode).@@ -40,7 +40,7 @@ Or build the latest version from git: - git clone https://github.com/mokus0/misfortune.git+ git clone https://github.com/ncfavier/misfortune cd misfortune cabal install
misfortune.cabal view
@@ -1,19 +1,28 @@+cabal-version: 3.0 name: misfortune-version: 0.1.1.2+version: 0.1.2 stability: experimental -cabal-version: >= 1.6-build-type: Simple- author: James Cook <mokus@deepbondi.net>-maintainer: James Cook <mokus@deepbondi.net>-license: PublicDomain-homepage: https://github.com/mokus0/misfortune+maintainer: Naïm Favier <n@monade.li>+license: MIT+license-file: LICENSE+homepage: https://github.com/ncfavier/misfortune category: Console, Game synopsis: fortune-mod clone description: fortune-mod clone, in library and executable form. +tested-with: GHC == 7.0.4,+ GHC == 7.2.2,+ GHC == 7.4.2,+ GHC == 7.6.3,+ GHC == 7.8.4,+ GHC == 7.10.1,+ GHC == 7.11,+ GHC == 8.10.7,+ GHC == 9.0.2+ data-files: README.md README.fortune-mod.md README.lambdabot.md@@ -97,38 +106,40 @@ source-repository head type: git- location: https://github.com/mokus0/misfortune.git+ location: https://github.com/ncfavier/misfortune -Library+common main+ default-language: Haskell2010 hs-source-dirs: src ghc-options: -fwarn-unused-binds -fwarn-unused-imports- exposed-modules: Data.Fortune other-modules: Data.Fortune.FortuneFile Data.Fortune.Index Data.Fortune.Stats Paths_misfortune+ autogen-modules: Paths_misfortune build-depends: base >= 3 && < 5, bytestring, cereal, directory, filepath, knob,- random-fu >= 0.2.2,- semigroups,+ random,+ random-fu >= 0.3, text, utf8-string, vector+ if impl(ghc == 7.0.*)+ -- utf8-string-1.0.1 does not build on GHC 7.0.x+ build-depends: utf8-string == 1 -Executable misfortune- hs-source-dirs: src- ghc-options: -fwarn-unused-binds -fwarn-unused-imports+library+ import: main+ exposed-modules: Data.Fortune++executable misfortune+ import: main main-is: Fortune.hs+ other-modules: Data.Fortune build-depends: monad-loops, regex-base, regex-pcre--Executable misfortune-strfile- hs-source-dirs: src- ghc-options: -fwarn-unused-binds -fwarn-unused-imports- main-is: StrFile.hs-
src/Data/Fortune.hs view
@@ -48,7 +48,6 @@ import Data.Fortune.Index import qualified Data.Fortune.Stats as S -import Control.Applicative import Control.Exception import Control.Monad import Data.Char@@ -64,6 +63,7 @@ import System.Directory import System.Environment import System.FilePath+import System.Random.Stateful (newIOGenM, newStdGen) -- |The number of fortune strings in the index numFortunes :: S.FortuneStats -> Int@@ -233,9 +233,10 @@ -- random fortune from that file (unformly). randomFortuneFromRandomFile :: RVar FortuneFile -> IO String randomFortuneFromRandomFile file = do- f <- sample file+ gen <- newStdGen >>= newIOGenM+ f <- sampleFrom gen file n <- getNumFortunes f- i <- sample (uniform 0 (n-1))+ i <- sampleFrom gen (uniform 0 (n-1)) T.unpack <$> getFortune f i -- |Given a list of 'FortuneFile's, compute a distrubution over them weighted by the number
src/Data/Fortune/FortuneFile.hs view
@@ -15,7 +15,6 @@ , appendFortune ) where -import Control.Applicative import Control.Concurrent import Control.Exception import Control.Monad
src/Data/Fortune/Index.hs view
@@ -54,12 +54,10 @@ , rebuildStats ) where -import Control.Applicative import Control.Concurrent.MVar import Control.Exception import Control.Monad import qualified Data.ByteString as BS-import Data.Foldable (foldMap) import Data.Fortune.Stats import Data.Knob import Data.Maybe
src/Fortune.hs view
@@ -2,7 +2,6 @@ {-# LANGUAGE FlexibleContexts #-} module Main (main) where -import Control.Applicative import Control.Monad import Control.Monad.Loops import Data.Either@@ -21,6 +20,7 @@ import System.Exit import System.FilePath import System.IO+import System.Random.Stateful (newIOGenM, newStdGen) import Text.Printf import Text.Regex.Base import Text.Regex.PCRE@@ -200,6 +200,7 @@ fortunes <- filterM (filterFile args) (fortuneFiles args) dist <- getDist args fortunes+ gen <- newStdGen >>= newIOGenM when (numEvents dist == 0) $ do hPutStrLn stderr "No fortunes matched the filter criteria"@@ -225,8 +226,8 @@ , let pctStr = printf "(%.2f%%)" (100 * weight / totalWeight dist) :: String ] else do- (file, fortuneDist) <- sample dist- fortune <- sample fortuneDist+ (file, fortuneDist) <- sampleFrom gen dist+ fortune <- sampleFrom gen fortuneDist putStrLn . T.unpack =<< getFortune file fortune getDist :: Args -> [FortuneFile] -> IO (Categorical Float (FortuneFile, Categorical Float Int))
− src/StrFile.hs
@@ -1,13 +0,0 @@-module Main where--import Data.Fortune-import System.Environment--main = do- args <- getArgs- mapM_ index args--index file = do- fortune <- openFortuneFile '%' True file- rebuildIndex fortune-