1 -- This file is part of Diohsc
2 -- Copyright (C) 2020-23 Martin Bays <mbays@sdf.org>
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.
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 Text
.Regex
(Regex
)
16 import qualified Data
.Map
as M
17 import qualified Data
.Set
as S
18 import qualified Data
.Text
.Lazy
as T
20 import ActiveIdentities
22 import qualified BStack
28 import TextGemini
(PreOpt
(..))
30 data ClientConfig
= ClientConfig
31 { clientConfDefaultAction
:: (String, [CommandArg
])
32 , clientConfProxies
:: M
.Map
String Host
33 , clientConfGeminators
:: [(String,(Regex
,String))]
34 , clientConfRenderFilter
:: Maybe String
35 , clientConfPreOpt
:: PreOpt
36 , clientConfLinkDescFirst
:: Bool
37 , clientConfMaxLogLen
:: Int
38 , clientConfMaxWrapWidth
:: Int
39 , clientConfNoConfirm
:: Bool
40 , clientConfVerboseConnection
:: Bool
43 defaultClientConfig
:: ClientConfig
44 defaultClientConfig
= ClientConfig
("page", []) M
.empty [] Nothing PreOptPre
False 1000 80 False False
46 data ClientState
= ClientState
47 { clientCurrent
:: Maybe HistoryItem
48 , clientJumpBack
:: Maybe HistoryItem
49 , clientLog
:: BStack
.BStack T
.Text
50 , clientVisited
:: S
.Set
Int
51 , clientQueues
:: QueueMap
52 , clientActiveIdentities
:: ActiveIdentities
53 , clientMarks
:: Marks
54 , clientSessionMarks
:: M
.Map
Int HistoryItem
55 , clientAliases
:: Aliases
56 , clientConfig
:: ClientConfig
59 type ClientM
= StateT ClientState
IO
61 type CommandAction
= HistoryItem
-> ClientM
()
63 emptyClientState
:: ClientState
64 emptyClientState
= ClientState Nothing Nothing BStack
.empty S
.empty M
.empty M
.empty emptyMarks M
.empty defaultAliases defaultClientConfig
66 modifyCConf
:: (ClientConfig
-> ClientConfig
) -> ClientM
()
67 modifyCConf f
= modify
$ \s
-> s
{ clientConfig
= f
$ clientConfig s
}
69 modifyQueues
:: (QueueMap
-> QueueMap
) -> ClientM
()
70 modifyQueues f
= modify
$ \s
-> s
{ clientQueues
= f
$ clientQueues s
}