split more
[diohsc.git] / ClientState.hs
blob6833510495bf607937fbc44d40f65cd4924df9b9
1 -- This file is part of Diohsc
2 -- Copyright (C) 2020-23 Martin Bays <mbays@sdf.org>
3 --
4 -- This program is free software: you can redistribute it and/or modify
5 -- it under the terms of version 3 of the GNU General Public License as
6 -- published by the Free Software Foundation, or any later version.
7 --
8 -- You should have received a copy of the GNU General Public License
9 -- along with this program. If not, see http://www.gnu.org/licenses/.
11 module ClientState where
13 import Control.Monad.State (StateT, modify)
14 import Data.Hash (Hash)
15 import Text.Regex (Regex)
17 import qualified Data.Map as M
18 import qualified Data.Set as S
19 import qualified Data.Text.Lazy as T
21 import ActiveIdentities
22 import Alias
23 import qualified BStack
24 import CommandLine
25 import History
26 import Marks
27 import Queue
28 import Request
29 import TextGemini (PreOpt (..))
31 data ClientConfig = ClientConfig
32 { clientConfDefaultAction :: (String, [CommandArg])
33 , clientConfProxies :: M.Map String Host
34 , clientConfGeminators :: [(String,(Regex,String))]
35 , clientConfRenderFilter :: Maybe String
36 , clientConfPreOpt :: PreOpt
37 , clientConfLinkDescFirst :: Bool
38 , clientConfMaxLogLen :: Int
39 , clientConfMaxWrapWidth :: Int
40 , clientConfNoConfirm :: Bool
41 , clientConfVerboseConnection :: Bool
44 defaultClientConfig :: ClientConfig
45 defaultClientConfig = ClientConfig ("page", []) M.empty [] Nothing PreOptPre False 1000 80 False False
47 data ClientState = ClientState
48 { clientCurrent :: Maybe HistoryItem
49 , clientJumpBack :: Maybe HistoryItem
50 , clientLog :: BStack.BStack T.Text
51 , clientVisited :: S.Set Hash
52 , clientQueues :: QueueMap
53 , clientActiveIdentities :: ActiveIdentities
54 , clientMarks :: Marks
55 , clientSessionMarks :: M.Map Int HistoryItem
56 , clientAliases :: Aliases
57 , clientConfig :: ClientConfig
60 type ClientM = StateT ClientState IO
62 type CommandAction = HistoryItem -> ClientM ()
64 emptyClientState :: ClientState
65 emptyClientState = ClientState Nothing Nothing BStack.empty S.empty M.empty M.empty emptyMarks M.empty defaultAliases defaultClientConfig
67 modifyCConf :: (ClientConfig -> ClientConfig) -> ClientM ()
68 modifyCConf f = modify $ \s -> s { clientConfig = f $ clientConfig s }
70 modifyQueues :: (QueueMap -> QueueMap) -> ClientM ()
71 modifyQueues f = modify $ \s -> s { clientQueues = f $ clientQueues s }