~pvsr/mpd-status

77c9e93764539744f69afc43f9a13ff016e9b85e — Peter Rice 8 months ago ac4e0db
split main
3 files changed, 31 insertions(+), 24 deletions(-)

M I3blocks/Block.hs
A I3blocks/Main.hs
M mpd-status.cabal
M I3blocks/Block.hs => I3blocks/Block.hs +2 -22
@@ 1,34 1,14 @@
{-# LANGUAGE OverloadedStrings #-}

import Control.Concurrent (forkIO, killThread)
import Control.Monad (forever, (>=>))
module I3blocks.Block (block) where

import qualified Data.Map as M (lookup)
import Data.Maybe (fromMaybe)
import Data.Monoid ((<>))
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))

import Data.Aeson (decodeStrict)
import qualified Data.ByteString as B (getLine)
import qualified Data.Text as T (Text, pack)
import qualified Data.Text.IO as T (putStrLn)
import Network.MPD

import Operation
import I3blocks.Config

main :: IO ()
main = do
  hSetBuffering stdout LineBuffering
  forever $ do
    run block
    tid <- forkIO . forever . run $ idle [PlayerS] >> block
    b <- decodeStrict <$> B.getLine
    killThread tid
    withMPD . maybe (return ()) op $ b >>= buttonToOp

run :: MPD T.Text -> IO ()
run = withMPD >=> either print T.putStrLn

-- TODO color
-- colors set in i3blocks config are available in environment
-- with markup=pango: "<span color=\"#ff0000\">mpd stopped</span>"

A I3blocks/Main.hs => I3blocks/Main.hs +26 -0
@@ 0,0 1,26 @@
import Control.Concurrent (forkIO, killThread)
import Control.Monad (forever, (>=>))
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))

import Data.Aeson (decodeStrict)
import qualified Data.ByteString as B (getLine)
import qualified Data.Text as T (Text)
import qualified Data.Text.IO as T (putStrLn)
import Network.MPD

import Operation
import I3blocks.Block
import I3blocks.Config

main :: IO ()
main = do
  hSetBuffering stdout LineBuffering
  forever $ do
    run block
    tid <- forkIO . forever . run $ idle [PlayerS] >> block
    b <- decodeStrict <$> B.getLine
    killThread tid
    withMPD . maybe (return ()) op $ b >>= buttonToOp

run :: MPD T.Text -> IO ()
run = withMPD >=> either print T.putStrLn

M mpd-status.cabal => mpd-status.cabal +3 -2
@@ 21,8 21,9 @@ executable mpd-status
  default-extensions:  OverloadedStrings
  other-extensions:    LambdaCase
  ghc-options:         -Wall
  main-is:             I3blocks/Block.hs
  other-modules:       I3blocks.Click
  main-is:             I3blocks/Main.hs
  other-modules:       I3blocks.Block
                       I3blocks.Click
                       I3blocks.Config
                       Operation
                       Shuffle