module Client.Commands.TabCompletion where
import Client.Commands.Types
import Client.Commands.WordCompletion
import Client.Message
import Client.State
import Client.State.Focus
import Client.State.Network
import Client.State.Window
import Client.State.Channel
import Control.Lens
import qualified Data.HashMap.Strict as HashMap
import Irc.Identifier
import Irc.UserInfo
noClientTab :: Bool -> ClientCommand String
noClientTab _ st _ = commandFailure st
noNetworkTab :: Bool -> NetworkCommand String
noNetworkTab _ _ st _ = commandFailure st
noChannelTab :: Bool -> ChannelCommand String
noChannelTab _ _ _ st _ = commandFailure st
simpleClientTab :: Bool -> ClientCommand String
simpleClientTab isReversed st _ =
nickTabCompletion isReversed st
simpleNetworkTab :: Bool -> NetworkCommand String
simpleNetworkTab isReversed _ st _ =
nickTabCompletion isReversed st
simpleChannelTab :: Bool -> ChannelCommand String
simpleChannelTab isReversed _ _ st _ =
nickTabCompletion isReversed st
simpleTabCompletion ::
Prefix a =>
WordCompletionMode ->
[a] ->
[a] ->
Bool ->
ClientState ->
IO CommandResult
simpleTabCompletion mode hints completions isReversed st =
case traverseOf clientTextBox tryCompletion st of
Nothing -> commandFailure st
Just st' -> commandSuccess st'
where
tryCompletion = wordComplete mode isReversed hints completions
nickTabCompletion :: Bool -> ClientState -> IO CommandResult
nickTabCompletion isReversed st =
simpleTabCompletion mode hint completions isReversed st
where
hint = activeNicks st
completions = currentCompletionList st
mode = currentNickCompletionMode st
activeNicks ::
ClientState ->
[Identifier]
activeNicks st =
case view clientFocus st of
focus@(ChannelFocus network channel) ->
toListOf
( clientWindows . ix focus
. winMessages . each
. wlSummary . folding summaryActor
. filtered isActive
. filtered isNotSelf ) st
where
isActive n = HashMap.member n userMap
self = preview ( clientConnection network . csNick ) st
isNotSelf n = case self of
Nothing -> True
Just s -> n /= s
userMap = view ( clientConnection network
. csChannels . ix channel
. chanUsers) st
_ -> []
where
summaryActor :: IrcSummary -> Maybe Identifier
summaryActor (ChatSummary who) = Just $! userNick who
summaryActor _ = Nothing