首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用XMonad显示MPD卷

如何用XMonad显示MPD卷
EN

Stack Overflow用户
提问于 2013-02-26 14:17:17
回答 1查看 690关注 0票数 0

我正在尝试使用haskell-libmpd读取XMonad中的MPD卷。而独立代码:

代码语言:javascript
复制
-- current darcs as of 2010-12-31
{-# LANGUAGE
     DeriveDataTypeable,
     FlexibleContexts,
     FlexibleInstances,
     MultiParamTypeClasses,
     NoMonomorphismRestriction,
     PatternGuards,
     ScopedTypeVariables,
     TypeSynonymInstances,
     UndecidableInstances,
     OverloadedStrings
     #-}
{-# OPTIONS_GHC -W -fwarn-unused-imports -fno-warn-missing-signatures #-}

import Control.Applicative
import Control.Monad
import Control.Monad.Instances ()
import Control.Monad.Writer
import Control.Monad.Trans (liftIO)
import Data.List
import Data.Int
import Data.Maybe
import Data.Either
import Data.Either.Utils
import Data.Traversable(traverse)
import qualified Data.Map as M
import System.IO
import System.Environment (getArgs)
import System.Process
import Prelude
import Text.Regex.Posix
import qualified Network.MPD as MPD
import qualified Network.MPD.Commands.Extensions as MPD
import Data.Array
import System.Cmd

int2str :: (Show a, Num a, Ord a) => a -> String
int2str x = if x < 10 then '0':sx else sx where sx = show x

parseMPD :: MPD.Response MPD.Status -> [[String]]
parseMPD (Left e) = return $ show e:repeat ""
parseMPD (Right st) = do
     return [vol, "%"]
     where
          vol = int2str $ MPD.stVolume st
--          song = MPD.withMPD MPD.currentSong 


main = do
     x <- MPD.withMPD $ MPD.status
     let a = unwords (foldr1 (++) (parseMPD x))
     rawSystem "notify-send" ["MPD Volume", a]

使用XMonad配置中的相同代码正确编译

代码语言:javascript
复制
int2str :: (Show a, Num a, Ord a) => a -> String
int2str x = if x < 10 then '0':sx else sx where sx = show x

parseMPD :: MPD.Response MPD.Status -> [[String]]
parseMPD (Left e) = return $ show e:repeat ""
parseMPD (Right st) = do
     return [vol, "%"]
     where
          vol = int2str $ MPD.stVolume st

volume :: MonadIO m => m()
volume = do
    x <- MPD.withMPD $ MPD.status
    let a = unwords (foldr1 (++) (parseMPD x))
    safeSpawn "notify-send" ["MPD Volume", a]

导致错误:

代码语言:javascript
复制
 xmonad.hs:182:14:
     Could not deduce (m ~ IO)
     from the context (MonadIO m)
       bound by the type signature for volume :: MonadIO m => m ()
       at xmonad.hs:180:11-26
       `m' is a rigid type variable bound by
           the type signature for volume :: MonadIO m => m ()
           at xmonad.hs:180:11
     Expected type: m (MPD.Response MPD.Status)
       Actual type: IO (MPD.Response MPD.Status)
     In a stmt of a 'do' block: x <- MPD.withMPD $ MPD.status
     In the expression:
       do { x <- MPD.withMPD $ MPD.status;
            let a = unwords (foldr1 (++) (parseMPD x));
            safeSpawn "notify-send" ["MPD Volume", a] }
     In an equation for `volume':
         volume
           = do { x <- MPD.withMPD $ MPD.status;
                  let a = ...;
                  safeSpawn "notify-send" ["MPD Volume", ....] }

如何在不运行外部应用的情况下获取MPD音量?

EN

回答 1

Stack Overflow用户

发布于 2013-02-26 20:52:24

回答:你没有在你的xmonad配置中使用相同的代码,你这个骗子!您为volume添加了绑定。不过,不用担心,它应该很容易修复:您可以使用liftIO将任何IO a操作转换为MonadIO m => m a操作

代码语言:javascript
复制
volume :: MonadIO m => m()
volume = do
    x <- liftIO . MPD.withMPD $ MPD.status
    let a = unwords (foldr1 (++) (parseMPD x))
    safeSpawn "notify-send" ["MPD Volume", a]

顺便说一句,您以后可能会对XMonad.Prompt.MPD感兴趣。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15082615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档