aboutsummaryrefslogtreecommitdiff
path: root/src/Lazymail/State.hs
blob: fb640a655f45f6bcce17f14f08f9299bb9f48f5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{- Lazymail state, and operations on it.
 -
 - Copyright 2013 Raúl Benencia <rul@kalgan.cc>
 -
 - Licensed under the GNU GPL version 3 or higher
 -
 -}

module Lazymail.State where

import Codec.MIME.Type(MIMEValue, nullMIMEValue)
import UI.NCurses(ColorID(..), defaultColorID)
import System.FilePath

import Lazymail.Types

initialState = LazymailState {
    mode          = MaildirMode
  , basePath      = ""
  , screenRows    = 0
  , screenColumns = 0
  , currentRow    = 0
  , columnPadding = 0
  , exitRequested = False
  , statusBar     = True
  , maildirState  = initialMaildirState
  , indexState    = initialIndexState
  , composeState  = initialComposeState
  , emailState    = initialEmailState
  , inputState    = initialInputState
  , colorStyle    = initialColorStyle
}

initialMaildirState = MaildirState {
    selectedRowMD   = 0
  , selectedMD      = ""
  , detectedMDs     = []
  , scrollRowMD     = 0
  , scrollBufferMD  = []
  , triggerUpdateMD = False
}

initialIndexState = IndexState {
    selectedRowIn      = 0
  , selectedEmailPath  = ""
  , selectedEmails     = []
  , scrollRowIn        = 0
  , currentInLen       = 0
  , scrollBufferIn     = []
  , triggerUpdateIn    = False
}

initialEmailState = EmailState {
    scrollRowEm    = 0
  , bodyStartRow  = 0
  , emailLines     = []
  , currentEmail   = nullMIMEValue
}

initialComposeState = ComposeState {
    composeFields = initialComposeFields
  , bodyFileName  = Nothing
  , bodyReady     = False
}

initialComposeFields = ComposeFields {
    fromField    = Nothing
  , toField      = Nothing
  , ccField      = Nothing
  , bccField     = Nothing
  , subjectField = Nothing
  , replyToField = Nothing
}

initialColorStyle = ColorStyle {
    baseColorID      = defaultColorID
  , selectionColorID = defaultColorID
  , statusBarColorID = defaultColorID
  , headerColorID    = defaultColorID
  , newEmailColorID  = defaultColorID
}

initialInputState    =  InputState {
    inputRequested   = False
  , prompt           = Nothing
  , currentInput     = ""
  , postInputActions = return ()
}

scrColsAsInteger st = toInteger $ screenColumns st
scrRowsAsInteger st = toInteger $ screenRows st
curRowAsInteger  st = toInteger $ currentRow st
colPadAsInteger  st = toInteger $ columnPadding st

selectedRow st = case (mode st) of
      MaildirMode -> selectedRowMD . maildirState $ st
      IndexMode   -> selectedRowIn . indexState   $ st
nihil fit ex nihilo