{-# Language OverloadedStrings #-}
{-|
Module      : Client.Commands.Toggles
Description : View modality command implementations
Copyright   : (c) Eric Mertens, 2016-2020
License     : ISC
Maintainer  : emertens@gmail.com
-}

module Client.Commands.Toggles (togglesCommands) where

import           Client.Commands.TabCompletion
import           Client.Commands.Types
import           Client.Configuration
import           Client.State
import           Control.Lens

togglesCommands :: CommandSection
togglesCommands :: CommandSection
togglesCommands = Text -> [Command] -> CommandSection
CommandSection Text
"View toggles"

  [ NonEmpty Text
-> Args ClientState () -> Text -> CommandImpl () -> Command
forall a.
NonEmpty Text
-> Args ClientState a -> Text -> CommandImpl a -> Command
Command
      (Text -> NonEmpty Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"toggle-detail")
      (() -> Args ClientState ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
      Text
"Toggle detailed message view.\n"
    (CommandImpl () -> Command) -> CommandImpl () -> Command
forall a b. (a -> b) -> a -> b
$ ClientCommand ()
-> (Bool -> ClientCommand String) -> CommandImpl ()
forall a.
ClientCommand a -> (Bool -> ClientCommand String) -> CommandImpl a
ClientCommand ClientCommand ()
cmdToggleDetail Bool -> ClientCommand String
noClientTab

  , NonEmpty Text
-> Args ClientState () -> Text -> CommandImpl () -> Command
forall a.
NonEmpty Text
-> Args ClientState a -> Text -> CommandImpl a -> Command
Command
      (Text -> NonEmpty Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"toggle-activity-bar")
      (() -> Args ClientState ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
      Text
"Toggle detailed detailed activity information in status bar.\n"
    (CommandImpl () -> Command) -> CommandImpl () -> Command
forall a b. (a -> b) -> a -> b
$ ClientCommand ()
-> (Bool -> ClientCommand String) -> CommandImpl ()
forall a.
ClientCommand a -> (Bool -> ClientCommand String) -> CommandImpl a
ClientCommand ClientCommand ()
cmdToggleActivityBar Bool -> ClientCommand String
noClientTab

  , NonEmpty Text
-> Args ClientState () -> Text -> CommandImpl () -> Command
forall a.
NonEmpty Text
-> Args ClientState a -> Text -> CommandImpl a -> Command
Command
      (Text -> NonEmpty Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"toggle-show-ping")
      (() -> Args ClientState ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
      Text
"Toggle visibility of ping round-trip time.\n"
    (CommandImpl () -> Command) -> CommandImpl () -> Command
forall a b. (a -> b) -> a -> b
$ ClientCommand ()
-> (Bool -> ClientCommand String) -> CommandImpl ()
forall a.
ClientCommand a -> (Bool -> ClientCommand String) -> CommandImpl a
ClientCommand ClientCommand ()
cmdToggleShowPing Bool -> ClientCommand String
noClientTab

  , NonEmpty Text
-> Args ClientState () -> Text -> CommandImpl () -> Command
forall a.
NonEmpty Text
-> Args ClientState a -> Text -> CommandImpl a -> Command
Command
      (Text -> NonEmpty Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"toggle-metadata")
      (() -> Args ClientState ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
      Text
"Toggle visibility of metadata in chat windows.\n"
    (CommandImpl () -> Command) -> CommandImpl () -> Command
forall a b. (a -> b) -> a -> b
$ ClientCommand ()
-> (Bool -> ClientCommand String) -> CommandImpl ()
forall a.
ClientCommand a -> (Bool -> ClientCommand String) -> CommandImpl a
ClientCommand ClientCommand ()
cmdToggleMetadata Bool -> ClientCommand String
noClientTab

  , NonEmpty Text
-> Args ClientState () -> Text -> CommandImpl () -> Command
forall a.
NonEmpty Text
-> Args ClientState a -> Text -> CommandImpl a -> Command
Command
      (Text -> NonEmpty Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"toggle-layout")
      (() -> Args ClientState ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
      Text
"Toggle multi-window layout mode.\n"
    (CommandImpl () -> Command) -> CommandImpl () -> Command
forall a b. (a -> b) -> a -> b
$ ClientCommand ()
-> (Bool -> ClientCommand String) -> CommandImpl ()
forall a.
ClientCommand a -> (Bool -> ClientCommand String) -> CommandImpl a
ClientCommand ClientCommand ()
cmdToggleLayout Bool -> ClientCommand String
noClientTab

  , NonEmpty Text
-> Args ClientState () -> Text -> CommandImpl () -> Command
forall a.
NonEmpty Text
-> Args ClientState a -> Text -> CommandImpl a -> Command
Command
      (Text -> NonEmpty Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"toggle-editor")
      (() -> Args ClientState ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
      Text
"Toggle between single-line and multi-line editor mode.\n"
    (CommandImpl () -> Command) -> CommandImpl () -> Command
forall a b. (a -> b) -> a -> b
$ ClientCommand ()
-> (Bool -> ClientCommand String) -> CommandImpl ()
forall a.
ClientCommand a -> (Bool -> ClientCommand String) -> CommandImpl a
ClientCommand ClientCommand ()
cmdToggleEditor Bool -> ClientCommand String
noClientTab

  , NonEmpty Text
-> Args ClientState () -> Text -> CommandImpl () -> Command
forall a.
NonEmpty Text
-> Args ClientState a -> Text -> CommandImpl a -> Command
Command
      (Text -> NonEmpty Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"toggle-edit-lock")
      (() -> Args ClientState ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
      Text
"Toggle editor lock mode. When editor is locked pressing Enter is disabled.\n"
    (CommandImpl () -> Command) -> CommandImpl () -> Command
forall a b. (a -> b) -> a -> b
$ ClientCommand ()
-> (Bool -> ClientCommand String) -> CommandImpl ()
forall a.
ClientCommand a -> (Bool -> ClientCommand String) -> CommandImpl a
ClientCommand ClientCommand ()
cmdToggleEditLock Bool -> ClientCommand String
noClientTab
  ]

cmdToggleDetail :: ClientCommand ()
cmdToggleDetail :: ClientCommand ()
cmdToggleDetail ClientState
st ()
_ = ClientState -> IO CommandResult
forall (m :: * -> *). Monad m => ClientState -> m CommandResult
commandSuccess (ASetter ClientState ClientState Bool Bool
-> (Bool -> Bool) -> ClientState -> ClientState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter ClientState ClientState Bool Bool
Lens' ClientState Bool
clientDetailView Bool -> Bool
not ClientState
st)

cmdToggleActivityBar :: ClientCommand ()
cmdToggleActivityBar :: ClientCommand ()
cmdToggleActivityBar ClientState
st ()
_ = ClientState -> IO CommandResult
forall (m :: * -> *). Monad m => ClientState -> m CommandResult
commandSuccess (ASetter ClientState ClientState Bool Bool
-> (Bool -> Bool) -> ClientState -> ClientState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter ClientState ClientState Bool Bool
Lens' ClientState Bool
clientActivityBar Bool -> Bool
not ClientState
st)

cmdToggleShowPing :: ClientCommand ()
cmdToggleShowPing :: ClientCommand ()
cmdToggleShowPing ClientState
st ()
_ = ClientState -> IO CommandResult
forall (m :: * -> *). Monad m => ClientState -> m CommandResult
commandSuccess (ASetter ClientState ClientState Bool Bool
-> (Bool -> Bool) -> ClientState -> ClientState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter ClientState ClientState Bool Bool
Lens' ClientState Bool
clientShowPing Bool -> Bool
not ClientState
st)

cmdToggleMetadata :: ClientCommand ()
cmdToggleMetadata :: ClientCommand ()
cmdToggleMetadata ClientState
st ()
_ = ClientState -> IO CommandResult
forall (m :: * -> *). Monad m => ClientState -> m CommandResult
commandSuccess (ClientState -> ClientState
clientToggleHideMeta ClientState
st)

cmdToggleLayout :: ClientCommand ()
cmdToggleLayout :: ClientCommand ()
cmdToggleLayout ClientState
st ()
_ = ClientState -> IO CommandResult
forall (m :: * -> *). Monad m => ClientState -> m CommandResult
commandSuccess (ASetter ClientState ClientState Int Int
-> Int -> ClientState -> ClientState
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter ClientState ClientState Int Int
Lens' ClientState Int
clientScroll Int
0 (ASetter ClientState ClientState LayoutMode LayoutMode
-> (LayoutMode -> LayoutMode) -> ClientState -> ClientState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter ClientState ClientState LayoutMode LayoutMode
Lens' ClientState LayoutMode
clientLayout LayoutMode -> LayoutMode
aux ClientState
st))
  where
    aux :: LayoutMode -> LayoutMode
aux LayoutMode
OneColumn = LayoutMode
TwoColumn
    aux LayoutMode
TwoColumn = LayoutMode
OneColumn

cmdToggleEditor :: ClientCommand ()
cmdToggleEditor :: ClientCommand ()
cmdToggleEditor ClientState
st ()
_ = ClientState -> IO CommandResult
forall (m :: * -> *). Monad m => ClientState -> m CommandResult
commandSuccess (ASetter ClientState ClientState EditMode EditMode
-> (EditMode -> EditMode) -> ClientState -> ClientState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter ClientState ClientState EditMode EditMode
Lens' ClientState EditMode
clientEditMode EditMode -> EditMode
aux ClientState
st)
  where
    aux :: EditMode -> EditMode
aux EditMode
SingleLineEditor = EditMode
MultiLineEditor
    aux EditMode
MultiLineEditor = EditMode
SingleLineEditor

cmdToggleEditLock :: ClientCommand ()
cmdToggleEditLock :: ClientCommand ()
cmdToggleEditLock ClientState
st ()
_ = ClientState -> IO CommandResult
forall (m :: * -> *). Monad m => ClientState -> m CommandResult
commandSuccess (ASetter ClientState ClientState Bool Bool
-> (Bool -> Bool) -> ClientState -> ClientState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter ClientState ClientState Bool Bool
Lens' ClientState Bool
clientEditLock Bool -> Bool
not ClientState
st)