Skip to content

Commit 8a51e72

Browse files
committed
Better editor search reporting; Better tags data definition
1 parent 481d7cc commit 8a51e72

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

ff-core/lib/FF.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import System.Random (StdGen, mkStdGen, randoms, split)
8181

8282
import FF.Config (Config (Config), ConfigUI (ConfigUI), dataDir, shuffle)
8383
import FF.Options (Assign (Clear, Set), Edit (..), New (..), Tags (..),
84-
assignToMaybe)
84+
TagsRequest (..), assignToMaybe)
8585
import FF.Types (Contact (..), ContactId, ContactSample, Entity (..), EntityDoc,
8686
EntityView, Limit, ModeMap, Note (..), NoteId, NoteSample,
8787
NoteStatus (..), Sample (..), Status (..), Tag (..),
@@ -211,15 +211,15 @@ filterWikis = filter $ (Just Wiki ==) . note_status . entityVal
211211

212212
data NoteFilter = NoteFilter
213213
{ status :: Status
214-
, tags :: Tags
214+
, tags :: TagsRequest
215215
, textPredicate :: Text -> Bool
216216
}
217217

218218
defaultNoteFilter :: NoteFilter
219219
defaultNoteFilter =
220220
NoteFilter
221221
{ status = Active
222-
, tags = Tags{require = Set.empty, exclude = Set.empty}
222+
, tags = EmptyTagsRequest
223223
, textPredicate = const True
224224
}
225225

@@ -268,9 +268,10 @@ viewTaskSamples
268268

269269
tagPredicate =
270270
case tagFilter of
271-
Tags{require, exclude} ->
271+
EmptyTagsRequest -> const True
272+
TagsContain Tags{require, exclude} ->
272273
\ts -> require `isSubsetOf` ts && exclude `disjoint` ts
273-
NoTags -> null
274+
TagsAbsent -> null
274275

275276
noteViewPredicate Entity{entityVal = NoteView{tags}} =
276277
tagPredicate $ Set.fromList $ toList tags
@@ -442,7 +443,7 @@ cmdSearch ::
442443
Maybe Limit ->
443444
-- | today
444445
Day ->
445-
Tags ->
446+
TagsRequest ->
446447
m (ModeMap NoteSample, NoteSample, ContactSample)
447448
cmdSearch substr status ui limit today tags =
448449
do

ff-core/lib/FF/CLI.hs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
module FF.CLI where
1212

13-
import Control.Applicative (empty)
1413
import Control.Concurrent (threadDelay)
1514
import Control.Concurrent.Async (race)
1615
import Control.Monad (forever, guard, when)
@@ -96,7 +95,7 @@ import FF.Options (
9695
Options (..),
9796
Search (..),
9897
Shuffle (..),
99-
Tags (Tags),
98+
TagsRequest (EmptyTagsRequest),
10099
Track (..),
101100
parseOptions,
102101
)
@@ -373,7 +372,7 @@ cmdTrack Track{dryRun, address, limit} today brief
373372
| dryRun =
374373
liftIO do
375374
samples <- run $ getOpenIssueSamples address limit today
376-
pprint $ prettyTaskSections brief (Tags mempty mempty) samples
375+
pprint $ prettyTaskSections brief EmptyTagsRequest samples
377376
| otherwise = do
378377
notes <- liftIO $ run $ getIssueViews address limit
379378
updateTrackedNotes notes
@@ -469,7 +468,7 @@ pprint doc = liftIO do
469468
fromEither :: Either a a -> a
470469
fromEither = either id id
471470

472-
jprint :: (ToJSON a, MonadIO io) => a -> io ()
471+
jprint :: (MonadIO io, ToJSON a) => a -> io ()
473472
jprint = liftIO . BSL.putStrLn . JSON.encodePretty
474473

475474
jprintObject :: (MonadIO io) => [JSON.Pair] -> io ()
@@ -500,7 +499,7 @@ runExternalEditor textOld = do
500499
assertExecutableFromConfig = do
501500
cfg <- loadConfig
502501
case externalEditor cfg of
503-
Nothing -> empty
502+
Nothing -> fail "Empty config parameter 'externalEditor'"
504503
Just editor ->
505504
assertExecutableWithArgs
506505
"config parameter 'externalEditor'"
@@ -512,11 +511,6 @@ runExternalEditor textOld = do
512511

513512
assertExecutableWithArgs source cmd = do
514513
case ShellWords.parse cmd of
515-
Left err -> do
516-
hPutStrLn stderr $
517-
"bad editor command in " <> source <> ": " <> err
518-
empty
519-
Right [] -> do
520-
hPutStrLn stderr $ "empty editor command in " <> source
521-
empty
514+
Left err -> fail $ "bad editor command in " <> source <> ": " <> err
515+
Right [] -> fail $ "empty editor command in " <> source
522516
Right (prog : args) -> assertExecutable prog $> prog :| args

ff-core/lib/FF/Options.hs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
{-# LANGUAGE DuplicateRecordFields #-}
44
{-# LANGUAGE ImportQualifiedPost #-}
55
{-# LANGUAGE LambdaCase #-}
6+
{-# LANGUAGE NamedFieldPuns #-}
67
{-# LANGUAGE OverloadedStrings #-}
8+
{-# LANGUAGE PatternSynonyms #-}
79
{-# LANGUAGE RecordWildCards #-}
810
{-# LANGUAGE ScopedTypeVariables #-}
911
{-# LANGUAGE TypeApplications #-}
12+
{-# LANGUAGE ViewPatterns #-}
1013

1114
module FF.Options (
1215
ActionOptions (..),
@@ -23,6 +26,7 @@ module FF.Options (
2326
Search (..),
2427
Shuffle (..),
2528
Tags (..),
29+
TagsRequest (EmptyTagsRequest, ..),
2630
Track (..),
2731
assignToMaybe,
2832
parseOptions,
@@ -136,9 +140,21 @@ assignToMaybe = \case
136140
Clear -> Nothing
137141
Set x -> Just x
138142

139-
data Agenda = Agenda {limit :: Maybe Limit, tags :: Tags}
143+
data Agenda = Agenda {limit :: Maybe Limit, tags :: TagsRequest}
140144

141-
data Tags = Tags {require, exclude :: Set Text} | NoTags
145+
data Tags = Tags {require, exclude :: Set Text}
146+
deriving (Eq)
147+
148+
data TagsRequest = TagsContain Tags | TagsAbsent
149+
deriving (Eq)
150+
151+
emptyTagsRequest :: TagsRequest
152+
emptyTagsRequest = TagsContain Tags{require = mempty, exclude = mempty}
153+
154+
pattern EmptyTagsRequest :: TagsRequest
155+
pattern EmptyTagsRequest <- ((emptyTagsRequest ==) -> True)
156+
where
157+
EmptyTagsRequest = emptyTagsRequest
142158

143159
data Edit = Edit
144160
{ ids :: NonEmpty NoteId
@@ -166,7 +182,7 @@ data Search = Search
166182
, inContacts :: Bool
167183
, status :: Status
168184
, limit :: Maybe Limit
169-
, tags :: Tags
185+
, tags :: TagsRequest
170186
}
171187

172188
parseOptions :: Maybe StorageFS.Handle -> IO Options
@@ -263,10 +279,14 @@ parser h = do
263279
briefOption =
264280
switch $ long "brief" <> short 'b' <> help "List only note titles and ids"
265281

266-
agenda = Agenda <$> optional limitOption <*> filterTags
282+
agenda = Agenda <$> optional limitOption <*> filterByTags
283+
284+
filterByTags = filterByTagsAbsent <|> filterByTagsContain
267285

268-
filterTags =
269-
filterByNoTags <|> (Tags <$> filterRequireTags <*> filterExcludeTags)
286+
filterByTagsContain = do
287+
require <- filterRequireTags
288+
exclude <- filterExcludeTags
289+
pure $ TagsContain Tags{require, exclude}
270290

271291
track = Track <$> dryRunOption <*> optional repo <*> optional limitOption
272292

@@ -325,7 +345,7 @@ parser h = do
325345
<*> searchC
326346
<*> searchA
327347
<*> optional limitOption
328-
<*> filterTags
348+
<*> filterByTags
329349

330350
searchT = switch $ long "tasks" <> short 't' <> help "Search among tasks"
331351

@@ -350,8 +370,8 @@ parser h = do
350370
strOption $
351371
long "tag" <> metavar "TAG" <> help "Filter by tag"
352372

353-
filterByNoTags =
354-
flag' NoTags $
373+
filterByTagsAbsent =
374+
flag' TagsAbsent $
355375
long "no-tag"
356376
<> short 'n'
357377
<> help "Filter items that have no tags"

ff-core/lib/FF/UI.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Data.Text (Text)
2929
import qualified Data.Text as Text
3030
import Data.Time (Day)
3131
import FF (fromRgaM)
32-
import FF.Options (Tags (..))
32+
import FF.Options (Tags (..), TagsRequest (TagsContain, TagsAbsent))
3333
import FF.Types (
3434
Contact (..),
3535
ContactSample,
@@ -102,7 +102,7 @@ prettyTasksWikisContacts ::
102102
-- | does search include contacts
103103
Bool ->
104104
-- | requested tags
105-
Tags ->
105+
TagsRequest ->
106106
Doc AnsiStyle
107107
prettyTasksWikisContacts
108108
isBrief
@@ -210,15 +210,15 @@ title =
210210
prettyTaskSections ::
211211
Bool ->
212212
-- | requested tags
213-
Tags ->
213+
TagsRequest ->
214214
ModeMap NoteSample ->
215215
Doc AnsiStyle
216216
prettyTaskSections isBrief tags samples =
217217
case tags of
218-
Tags{require, exclude}
218+
TagsContain Tags{require, exclude}
219219
| null require && null exclude -> tasks
220220
| otherwise -> tagHeader require exclude tasks
221-
NoTags -> noTagHeader tasks
221+
TagsAbsent -> noTagHeader tasks
222222
where
223223
noTagHeader = withHeader "Items without tags: "
224224

0 commit comments

Comments
 (0)