Skip to content
Snippets Groups Projects
Commit 77d878f6 authored by Jens Nolte's avatar Jens Nolte
Browse files

Add generic theme command

parent a6ed285b
No related branches found
No related tags found
No related merge requests found
...@@ -2,18 +2,25 @@ ...@@ -2,18 +2,25 @@
module QBar.Cli where module QBar.Cli where
import QBar.Theme
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Options.Applicative import Options.Applicative
data BarCommand = BarServer | DefaultTheme | RainbowTheme data BarCommand = BarServerCommand | SetThemeCommand Text
barCommandParser :: Parser BarCommand barCommandParser :: Parser BarCommand
barCommandParser = hsubparser barCommandParser = hsubparser (
( command "server" (info (pure BarServer) (progDesc "Start a new qbar server. Should be called by swaybar, i3bar or or another i3bar-protocol compatible host process.")) <> command "server" (info (pure BarServerCommand) (progDesc "Start a new qbar server. Should be called by swaybar, i3bar or or another i3bar-protocol compatible host process.")) <>
command "default" (info (pure DefaultTheme) (progDesc "Send a message to a running qbar server.")) <> command "theme" (info themeCommandParser (progDesc "Change the theme of the running qbar server.")) <>
command "rainbow" (info (pure RainbowTheme) (progDesc "Send a message to a running qbar server.")) command "default" (info (pure $ SetThemeCommand "default") (progDesc "Shortcut for 'qbar theme default'.")) <>
command "rainbow" (info (pure $ SetThemeCommand "rainbow") (progDesc "Shortcut for 'qbar theme rainbow'."))
) )
themeCommandParser :: Parser BarCommand
themeCommandParser = SetThemeCommand <$> strArgument (metavar "THEME" <> completeWith (map TL.unpack themeNames))
data MainOptions = MainOptions { data MainOptions = MainOptions {
verbose :: Bool, verbose :: Bool,
indicator :: Bool, indicator :: Bool,
......
...@@ -193,6 +193,5 @@ runBarServer defaultBarConfig options = runBarHost barServer (swayBarInput optio ...@@ -193,6 +193,5 @@ runBarServer defaultBarConfig options = runBarHost barServer (swayBarInput optio
runQBar :: BarIO () -> MainOptions -> IO () runQBar :: BarIO () -> MainOptions -> IO ()
runQBar barConfiguration options@MainOptions{barCommand} = runCommand barCommand runQBar barConfiguration options@MainOptions{barCommand} = runCommand barCommand
where where
runCommand BarServer = runBarServer barConfiguration options runCommand BarServerCommand = runBarServer barConfiguration options
runCommand DefaultTheme = sendIpc options $ SetTheme "default" runCommand (SetThemeCommand themeName) = sendIpc options $ SetTheme themeName
runCommand RainbowTheme = sendIpc options $ SetTheme "rainbow"
...@@ -9,6 +9,7 @@ import Control.Lens ((^.)) ...@@ -9,6 +9,7 @@ import Control.Lens ((^.))
import Control.Monad.State.Lazy (State, evalState, get, put) import Control.Monad.State.Lazy (State, evalState, get, put)
import Data.Colour.RGBSpace import Data.Colour.RGBSpace
import Data.Colour.RGBSpace.HSV (hsv) import Data.Colour.RGBSpace.HSV (hsv)
import qualified Data.HashMap.Lazy as HM
import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy as T
import Data.Time.Clock.POSIX (getPOSIXTime) import Data.Time.Clock.POSIX (getPOSIXTime)
import Pipes import Pipes
...@@ -50,10 +51,23 @@ isAnimated (AnimatedTheme _) = True ...@@ -50,10 +51,23 @@ isAnimated (AnimatedTheme _) = True
isAnimated _ = False isAnimated _ = False
themesList :: [(Text, Theme)]
themesList = [
("default", defaultTheme),
("rainbow", rainbowTheme)
]
themeNames :: [Text]
themeNames = map fst themesList
themes :: HM.HashMap Text Theme
themes = HM.fromList themesList
findTheme :: Text -> Either Text Theme findTheme :: Text -> Either Text Theme
findTheme "default" = Right defaultTheme findTheme themeName = maybe invalidThemeName Right $ HM.lookup themeName themes
findTheme "rainbow" = Right rainbowTheme where
findTheme name = Left $ "Invalid theme: " <> name invalidThemeName = Left $ "Invalid theme: " <> themeName
mkTheme :: SimplifiedTheme -> Theme mkTheme :: SimplifiedTheme -> Theme
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment