Elegant, emoji-based loading spinners to make your Haskell CLI applications more beautiful.
Go to file
2022-03-23 11:30:04 +03:00
examples/Spin init 2019-06-22 20:18:50 +01:00
scripts init 2019-06-22 20:18:50 +01:00
src/Spin Flush buffer after writing 2022-03-23 11:30:04 +03:00
.gitignore init 2019-06-22 20:18:50 +01:00
LICENSE init 2019-06-22 20:18:50 +01:00
README.md init 2019-06-22 20:18:50 +01:00
Setup.hs init 2019-06-22 20:18:50 +01:00
spin.cabal init 2019-06-22 20:18:50 +01:00
stack.yaml Flush buffer after writing 2022-03-23 11:30:04 +03:00
stack.yaml.lock Flush buffer after writing 2022-03-23 11:30:04 +03:00

spin

Elegant, emoji-based loading spinners to make your Haskell CLI applications more beautiful.

asciicast

Install

cabal install spin

Usage

1. Import the required modules

import Spin.Functions
import Spin.Specs
import Spin.Types

2. Select a spinner

Spinners are defined in Specs.hs. The code is pretty self-explanatory: Each spinner is defined via a "spec", which includes the individual frames that should be rendered, as well as the interval between them.

Alternatively you can define your own, custom spinners:

myCustomSpec :: Spec
myCustomSpec = Spec
  { specName = "myCustomSpec"
  , specInterval = 80
  , specFrames =
    [ "⠈"
    , "⠉"
    , "⠋"
    , "⠓"
    , "⠒"
    ]
  }

3. Start your spinner

withSpinner pongSpec $ \up -> do
  up $ \c -> c
    { configMessage = "a very long running operation"
    }

The up function can be used in order to customize the behavior while the spinner is active. Wrapping your long-running IO action into withSpinner ensures things are properly cleaned up and the cursor state restored upon exiting the program.

The above example uses the pongSpec.

Here is a complete, runnable example:

module YourProgram
  ( main
  ) where

import Control.Concurrent

import Spin.Functions
import Spin.Specs
import Spin.Types

main :: IO ()
main = do
  withSpinner pongSpec $ \up -> do
    up $ \c -> c
      { configMessage = "a very long running operation"
      }
    -- do stuff
    threadDelay $ 1000 * 100 * 3
  putStrLn "done!"

Prior Works of Art

This library is heavily inspired by ora, a similar library written for JavaScript. spin uses the same set of loading spinners, which are also available separately as part of the cli-spinners package.

License

MIT