module Chiasma.Data.Target where

import Chiasma.Class.CmdArgs (CmdArgs (cmdArgs))
import Chiasma.Data.TmuxId (PaneId, SessionId, WindowId, formatId)

data Target =
  Pane PaneId
  |
  Window WindowId
  |
  Session SessionId
  |
  Current
  deriving stock (Target -> Target -> Bool
(Target -> Target -> Bool)
-> (Target -> Target -> Bool) -> Eq Target
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Target -> Target -> Bool
$c/= :: Target -> Target -> Bool
== :: Target -> Target -> Bool
$c== :: Target -> Target -> Bool
Eq, Int -> Target -> ShowS
[Target] -> ShowS
Target -> String
(Int -> Target -> ShowS)
-> (Target -> String) -> ([Target] -> ShowS) -> Show Target
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Target] -> ShowS
$cshowList :: [Target] -> ShowS
show :: Target -> String
$cshow :: Target -> String
showsPrec :: Int -> Target -> ShowS
$cshowsPrec :: Int -> Target -> ShowS
Show)

formatTarget :: [Text] -> Target -> [Text]
formatTarget :: [Text] -> Target -> [Text]
formatTarget [Text]
pre = \case
    Pane PaneId
i -> [Text]
pre [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [PaneId -> Text
forall a. TmuxId a => a -> Text
formatId PaneId
i]
    Window WindowId
i -> [Text]
pre [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [WindowId -> Text
forall a. TmuxId a => a -> Text
formatId WindowId
i]
    Session SessionId
i -> [Text]
pre [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [SessionId -> Text
forall a. TmuxId a => a -> Text
formatId SessionId
i]
    Target
Current -> []

instance CmdArgs Target where
  cmdArgs :: Target -> [Text]
cmdArgs = \case
    Pane PaneId
i -> [Item [Text]
"-t", PaneId -> Text
forall a. TmuxId a => a -> Text
formatId PaneId
i]
    Window WindowId
i -> [Item [Text]
"-t", WindowId -> Text
forall a. TmuxId a => a -> Text
formatId WindowId
i]
    Session SessionId
i -> [Item [Text]
"-t", SessionId -> Text
forall a. TmuxId a => a -> Text
formatId SessionId
i]
    Target
Current -> []

instance Default Target where
  def :: Target
def =
    Target
Current