misfortune: fortune-mod clone

[ console, game, library, mit, program, public-domain ] [ Propose Tags ]

fortune-mod clone, in library and executable form.


[Skip to Readme]

Modules

[Index]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.1.1.1, 0.1.1.2, 0.1.2, 0.1.2.1
Dependencies base (>=3 && <5), bytestring, cereal, directory, filepath, knob, monad-loops, random-fu (>=0.2.2 && <0.3), regex-base, regex-pcre, semigroups, text, utf8-string, vector [details]
License LicenseRef-PublicDomain
Author James Cook <mokus@deepbondi.net>
Maintainer James Cook <mokus@deepbondi.net>
Revised Revision 1 made by Bodigrim at 2022-02-24T00:52:24Z
Category Console, Game
Home page https://github.com/mokus0/misfortune
Source repo head: git clone https://github.com/mokus0/misfortune.git
Uploaded by JamesCook at 2015-06-19T20:10:23Z
Distributions Arch:0.1.2.1, Debian:0.1.1.2, LTSHaskell:0.1.2.1, NixOS:0.1.2.1, Stackage:0.1.2.1
Reverse Dependencies 3 direct, 0 indirect [details]
Executables misfortune-strfile, misfortune
Downloads 6052 total (46 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-06-19 [all 1 reports]

Readme for misfortune-0.1.1.2

[back to package description]

misfortune Build Status

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).

Usage

Most of the command-line flags from fortune work with misfortune as well. To just print a fortune, run:

misfortune

To index a new fortune file (or update the index on an existing one), run:

misfortune-strfile path/to/file

To use the fortune API in your Haskell programs:

import Data.Fortune
import qualified Data.Text as T

main = do
    f <- openFortuneFile "pangrams" '%' True
    
    appendFortune f (T.pack "The quick brown fox jumps over the lazy dog.")
    appendFortune f (T.pack "Quick blowing zephyrs vex daft Jim.")
    
    closeFortuneFile f
    
    putStrLn =<< randomFortune ["pangrams"]

This example will create or append to a file "pangrams" in the working directory, and create or update the corresponding index file "pangrams.dat". It then closes that file and requests a random fortune from all databases named "pangrams" in the search path - so it will either print one of the two just written or one found in another "pangrams" file. Every eligible fortune is equally likely.

Installation

Get the current release from Hackage:

cabal install misfortune

Or build the latest version from git:

git clone https://github.com/mokus0/misfortune.git
cd misfortune
cabal install