module Chiasma.Data.SessionParams where

import Path (Abs, Dir, Path)

import Chiasma.Class.CmdArgs (CmdArgs (cmdArgs), arg, envVars, flag1, identOption, optionWith)
import Chiasma.Data.Ident (Ident)
import Chiasma.Data.SessionGroupId (SessionGroupId (unSessionGroupId))
import Chiasma.Path (pathText)

data SessionParams =
  SessionParams {
    SessionParams -> Bool
attach :: Bool,
    SessionParams -> Bool
defaultSize :: Bool,
    SessionParams -> Bool
detach :: Bool,
    SessionParams -> Bool
exitClient :: Bool,
    SessionParams -> Bool
printInfo :: Bool,
    SessionParams -> Maybe (Path Abs Dir)
cwd :: Maybe (Path Abs Dir),
    SessionParams -> Map Text Text
environment :: Map Text Text,
    SessionParams -> Maybe Ident
name :: Maybe Ident,
    SessionParams -> Maybe Ident
windowName :: Maybe Ident,
    SessionParams -> Maybe SessionGroupId
target :: Maybe SessionGroupId,
    SessionParams -> Maybe Int
width :: Maybe Int,
    SessionParams -> Maybe Int
height :: Maybe Int,
    SessionParams -> Maybe Text
command :: Maybe Text
  }
  deriving stock (SessionParams -> SessionParams -> Bool
(SessionParams -> SessionParams -> Bool)
-> (SessionParams -> SessionParams -> Bool) -> Eq SessionParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SessionParams -> SessionParams -> Bool
== :: SessionParams -> SessionParams -> Bool
$c/= :: SessionParams -> SessionParams -> Bool
/= :: SessionParams -> SessionParams -> Bool
Eq, Int -> SessionParams -> ShowS
[SessionParams] -> ShowS
SessionParams -> String
(Int -> SessionParams -> ShowS)
-> (SessionParams -> String)
-> ([SessionParams] -> ShowS)
-> Show SessionParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SessionParams -> ShowS
showsPrec :: Int -> SessionParams -> ShowS
$cshow :: SessionParams -> String
show :: SessionParams -> String
$cshowList :: [SessionParams] -> ShowS
showList :: [SessionParams] -> ShowS
Show)

instance Default SessionParams where
  def :: SessionParams
def =
    SessionParams {
      $sel:attach:SessionParams :: Bool
attach = Bool
False,
      $sel:defaultSize:SessionParams :: Bool
defaultSize = Bool
False,
      $sel:detach:SessionParams :: Bool
detach = Bool
False,
      $sel:exitClient:SessionParams :: Bool
exitClient = Bool
False,
      $sel:printInfo:SessionParams :: Bool
printInfo = Bool
True,
      $sel:cwd:SessionParams :: Maybe (Path Abs Dir)
cwd = Maybe (Path Abs Dir)
forall a. Maybe a
Nothing,
      $sel:environment:SessionParams :: Map Text Text
environment = Map Text Text
forall a. Monoid a => a
mempty,
      $sel:name:SessionParams :: Maybe Ident
name = Maybe Ident
forall a. Maybe a
Nothing,
      $sel:windowName:SessionParams :: Maybe Ident
windowName = Maybe Ident
forall a. Maybe a
Nothing,
      $sel:target:SessionParams :: Maybe SessionGroupId
target = Maybe SessionGroupId
forall a. Maybe a
Nothing,
      $sel:width:SessionParams :: Maybe Int
width = Maybe Int
forall a. Maybe a
Nothing,
      $sel:height:SessionParams :: Maybe Int
height = Maybe Int
forall a. Maybe a
Nothing,
      $sel:command:SessionParams :: Maybe Text
command = Maybe Text
forall a. Maybe a
Nothing
    }

instance CmdArgs SessionParams where
  cmdArgs :: SessionParams -> [Text]
cmdArgs SessionParams {Bool
Maybe Int
Maybe Text
Maybe (Path Abs Dir)
Maybe Ident
Maybe SessionGroupId
Map Text Text
$sel:attach:SessionParams :: SessionParams -> Bool
$sel:defaultSize:SessionParams :: SessionParams -> Bool
$sel:detach:SessionParams :: SessionParams -> Bool
$sel:exitClient:SessionParams :: SessionParams -> Bool
$sel:printInfo:SessionParams :: SessionParams -> Bool
$sel:cwd:SessionParams :: SessionParams -> Maybe (Path Abs Dir)
$sel:environment:SessionParams :: SessionParams -> Map Text Text
$sel:name:SessionParams :: SessionParams -> Maybe Ident
$sel:windowName:SessionParams :: SessionParams -> Maybe Ident
$sel:target:SessionParams :: SessionParams -> Maybe SessionGroupId
$sel:width:SessionParams :: SessionParams -> Maybe Int
$sel:height:SessionParams :: SessionParams -> Maybe Int
$sel:command:SessionParams :: SessionParams -> Maybe Text
attach :: Bool
defaultSize :: Bool
detach :: Bool
exitClient :: Bool
printInfo :: Bool
cwd :: Maybe (Path Abs Dir)
environment :: Map Text Text
name :: Maybe Ident
windowName :: Maybe Ident
target :: Maybe SessionGroupId
width :: Maybe Int
height :: Maybe Int
command :: Maybe Text
..} =
    Text -> Bool -> [Text]
flag1 Text
"-A" Bool
attach
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> Bool -> [Text]
flag1 Text
"-d" Bool
defaultSize
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> Bool -> [Text]
flag1 Text
"-D" Bool
detach
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Map Text Text -> [Text]
envVars Map Text Text
environment
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> Bool -> [Text]
flag1 Text
"-P" Bool
printInfo
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> Bool -> [Text]
flag1 Text
"-X" Bool
exitClient
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> (Path Abs Dir -> Text) -> Maybe (Path Abs Dir) -> [Text]
forall a. Text -> (a -> Text) -> Maybe a -> [Text]
optionWith Text
"-c" Path Abs Dir -> Text
forall b t. Path b t -> Text
pathText Maybe (Path Abs Dir)
cwd
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> Maybe Ident -> [Text]
identOption Text
"-n" Maybe Ident
windowName
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> Maybe Ident -> [Text]
identOption Text
"-s" Maybe Ident
name
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> (SessionGroupId -> Text) -> Maybe SessionGroupId -> [Text]
forall a. Text -> (a -> Text) -> Maybe a -> [Text]
optionWith Text
"-t" (.unSessionGroupId) Maybe SessionGroupId
target
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> (Int -> Text) -> Maybe Int -> [Text]
forall a. Text -> (a -> Text) -> Maybe a -> [Text]
optionWith Text
"-x" Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Maybe Int
width
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Text -> (Int -> Text) -> Maybe Int -> [Text]
forall a. Text -> (a -> Text) -> Maybe a -> [Text]
optionWith Text
"-y" Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Maybe Int
height
    [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
    Maybe Text -> [Text]
arg Maybe Text
command