Skip to content

Commit b486905

Browse files
committed
Use Text as the default string type
1 parent a322bf9 commit b486905

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

ff-brick/Main.hs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE BlockArguments #-}
22
{-# LANGUAGE ImportQualifiedPost #-}
33
{-# LANGUAGE OverloadedLabels #-}
4+
{-# LANGUAGE OverloadedStrings #-}
45

56
import Brick (
67
AttrMap,
@@ -15,7 +16,7 @@ import Brick (
1516
halt,
1617
neverShowCursor,
1718
on,
18-
str,
19+
txt,
1920
viewport,
2021
withAttr,
2122
withHScrollBars,
@@ -39,6 +40,8 @@ import Control.Monad (void)
3940
import Data.Foldable (toList)
4041
import Data.Function ((&))
4142
import Data.Generics.Labels ()
43+
import Data.Text (Text)
44+
import Data.Text qualified as Text
4245
import Data.Vector qualified as Vector
4346
import GHC.Generics (Generic)
4447
import Graphics.Vty (
@@ -125,25 +128,25 @@ appDraw Model{notes, openNoteM} = [mainWidget <=> keysHelpLine]
125128

126129
agenda =
127130
borderWithLabel
128-
(str " Agenda ")
131+
(txt " Agenda ")
129132
(renderList renderListItem True notes & withVScrollBars OnRight)
130133

131134
openNoteWidget = do
132135
Entity{entityVal = Note{note_text}} <- openNoteM
133-
let text = fromRgaM note_text
134-
pure $
135-
borderWithLabel (str " Note ") $
136-
viewport OpenNoteViewport Both (str text)
136+
let noteText = Text.pack $ fromRgaM note_text
137+
Just $
138+
borderWithLabel (txt " Note ") $
139+
viewport OpenNoteViewport Both (txt noteText)
137140
& withVScrollBars OnRight
138141
& withHScrollBars OnBottom
139142

140143
keysHelpLine =
141-
withAttr highlightAttr (str "Esc")
142-
<+> str " "
143-
<+> withAttr highlightAttr (str "q")
144-
<+> str " exit "
145-
<+> withAttr highlightAttr (str "Enter")
146-
<+> str " open"
144+
withAttr highlightAttr (txt "Esc")
145+
<+> txt " "
146+
<+> withAttr highlightAttr (txt "q")
147+
<+> txt " exit "
148+
<+> withAttr highlightAttr (txt "Enter")
149+
<+> txt " open"
147150

148151
highlightAttr :: AttrName
149152
highlightAttr = attrName "highlight"
@@ -164,11 +167,14 @@ appHandleVtyEvent = \case
164167
e -> zoom #notes $ handleListEvent e
165168

166169
renderListItem :: Bool -> EntityDoc Note -> Widget
167-
renderListItem _isSelected Entity{entityVal} = str $ noteTitle entityVal
170+
renderListItem _isSelected Entity{entityVal} = txt $ noteTitle entityVal
168171

169-
noteTitle :: Note -> String
172+
noteTitle :: Note -> Text
170173
noteTitle Note{note_text} =
171-
case filter (not . null) $ lines $ fromRgaM note_text of
174+
case textLines of
172175
[] -> "..."
173176
[singleLine] -> singleLine
174177
firstLine : _ -> firstLine <> "..."
178+
where
179+
textLines =
180+
filter (not . Text.null) $ Text.lines $ Text.pack $ fromRgaM note_text

ff-brick/ff-brick.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ executable ff-brick
1111
generic-lens,
1212
microlens-mtl,
1313
ron-storage,
14+
text,
1415
vector,
1516
vty,
1617

0 commit comments

Comments
 (0)