Skip to content

Commit f13d3e3

Browse files
committed
Remove border labels; Add open/close note view
1 parent 8b74790 commit f13d3e3

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

ff-brick/Main.hs

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Brick (
3030
(<=>),
3131
)
3232
import Brick qualified
33-
import Brick.Widgets.Border (borderWithLabel)
33+
import Brick.Widgets.Border (border)
3434
import Brick.Widgets.Border.Style (borderStyleFromChar, unicode)
3535
import Brick.Widgets.List (
3636
List,
@@ -52,15 +52,15 @@ import GHC.Generics (Generic)
5252
import Graphics.Vty (
5353
Event (EvKey),
5454
Key (KChar, KEnter, KEsc),
55+
Modifier (MCtrl),
5556
black,
5657
defAttr,
5758
white,
5859
)
59-
import Lens.Micro.Mtl (preuse, (.=))
60+
import Lens.Micro.Mtl (preuse, use, (.=))
6061
import RON.Storage.FS (runStorage)
6162
import RON.Storage.FS qualified as StorageFS
6263

63-
import Data.Maybe (isJust, isNothing)
6464
import FF (fromRgaM, getDataDir, loadAllNotes, noDataDirectoryMessage)
6565
import FF.Config (loadConfig)
6666
import FF.Types (
@@ -144,39 +144,38 @@ withBorderIf cond =
144144
appDraw :: Model -> [Widget]
145145
appDraw Model{visibleNotes, openNoteM} = [mainWidget <=> keysHelpLine]
146146
where
147-
agendaIsFocused = isNothing openNoteM
148-
noteIsFocused = isJust openNoteM
147+
focusedWidget =
148+
case openNoteM of
149+
Nothing -> NoteList
150+
Just _ -> OpenNoteViewport
149151

150-
mainWidget = hBox $ agenda : toList openNoteWidget
152+
mainWidget = hBox $ noteList : toList openNoteWidget
151153

152-
agenda =
153-
borderWithLabel
154-
(txt " Agenda ")
154+
noteList =
155+
border
155156
( renderList renderListItem True visibleNotes
156157
& withVScrollBars OnRight
157158
)
158-
& withBorderIf agendaIsFocused
159+
& withBorderIf (focusedWidget == NoteList)
159160

160161
openNoteWidget = do
161162
Entity{entityVal = Note{note_text}} <- openNoteM
162163
let noteText = Text.pack $ filter (/= '\r') $ fromRgaM note_text
163164
Just $
164-
borderWithLabel
165-
(txt " Note ")
165+
border
166166
( viewport
167167
OpenNoteViewport
168168
Both
169169
(txt {- TODO txtWrap? -} noteText)
170170
& withHScrollBars OnBottom
171171
& withVScrollBars OnRight
172172
)
173-
& withBorderStyle
174-
(if noteIsFocused then unicode else borderStyleFromChar ' ')
173+
& withBorderIf (focusedWidget == OpenNoteViewport)
175174

176175
keysHelpLine =
177-
withAttr highlightAttr (txt "Esc")
176+
withAttr highlightAttr (txt "^q")
178177
<+> txt " "
179-
<+> withAttr highlightAttr (txt "q")
178+
<+> withAttr highlightAttr (txt "Esc")
180179
<+> txt " exit "
181180
<+> withAttr highlightAttr (txt "Enter")
182181
<+> txt " open"
@@ -190,14 +189,29 @@ appHandleEvent = \case
190189
_ -> pure ()
191190

192191
appHandleVtyEvent :: Event -> EventM ()
193-
appHandleVtyEvent = \case
194-
EvKey KEsc [] -> halt
195-
EvKey (KChar 'q') [] -> halt
196-
EvKey KEnter [] -> do
197-
-- open selected note
198-
selectedNoteM <- preuse $ #visibleNotes . listSelectedElementL
199-
#openNoteM .= selectedNoteM
200-
e -> zoom #visibleNotes $ handleListEvent e
192+
appHandleVtyEvent event = do
193+
openNoteM <- use #openNoteM
194+
let focusedWidget =
195+
case openNoteM of
196+
Nothing -> NoteList
197+
Just _ -> OpenNoteViewport
198+
case focusedWidget of
199+
NoteList ->
200+
case event of
201+
EvKey KEsc [] -> halt
202+
EvKey (KChar 'q') [MCtrl] -> halt
203+
EvKey KEnter [] -> do
204+
-- open selected note
205+
selectedNoteM <-
206+
preuse $ #visibleNotes . listSelectedElementL
207+
#openNoteM .= selectedNoteM
208+
e -> zoom #visibleNotes $ handleListEvent e
209+
OpenNoteViewport ->
210+
case event of
211+
EvKey KEsc [] ->
212+
-- close note view
213+
#openNoteM .= Nothing
214+
_ -> pure () -- e -> zoom (#openNoteM . _Just) $ handleViewport e
201215

202216
renderListItem :: Bool -> EntityDoc Note -> Widget
203217
renderListItem _isSelected Entity{entityVal} = txt $ noteTitle entityVal

0 commit comments

Comments
 (0)