Skip to content

Commit ea06674

Browse files
committed
Only show list truncation warning if it was actually truncated
1 parent 383b573 commit ea06674

4 files changed

Lines changed: 58 additions & 20 deletions

File tree

tasklite-core/package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ tests:
112112
- neat-interpolation >= 0.5 && < 0.6
113113
- prettyprinter
114114
- prettyprinter-ansi-terminal
115+
- QuickCheck
115116
- sqlite-simple
116117
- tasklite-core
117118
- text

tasklite-core/source/Lib.hs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ headTasks conf now connection availableLinesMb = do
26632663
|]
26642664
[":taskCount" := taskCount]
26652665

2666-
formatTasksColor conf now (isJust availableLinesMb) tasks
2666+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
26672667

26682668

26692669
newTasks ::
@@ -2696,7 +2696,7 @@ newTasks conf now connection filterExp availableLinesMb = do
26962696
Just availableLines -> availableLines
26972697
]
26982698

2699-
formatTasksColor conf now (isJust availableLinesMb) tasks
2699+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
27002700
--
27012701
Just (filterExps, _) -> do
27022702
let
@@ -2718,7 +2718,7 @@ newTasks conf now connection filterExp availableLinesMb = do
27182718
query_
27192719
connection
27202720
(getFilterQuery filterExps (Just "ulid DESC") availableLinesMb)
2721-
formatTasksColor conf now (isJust availableLinesMb) tasks
2721+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
27222722

27232723

27242724
listOldTasks ::
@@ -2739,7 +2739,7 @@ listOldTasks conf now connection availableLinesMb = do
27392739
Just availableLines -> availableLines
27402740
]
27412741

2742-
formatTasksColor conf now (isJust availableLinesMb) tasks
2742+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
27432743

27442744

27452745
openTasks ::
@@ -2773,7 +2773,7 @@ openTasks conf now connection filterExpression availableLinesMb = do
27732773
Just availableLines -> availableLines
27742774
]
27752775

2776-
formatTasksColor conf now (isJust availableLinesMb) tasks
2776+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
27772777
--
27782778
Just (filterExps, _) -> do
27792779
let
@@ -2804,7 +2804,7 @@ openTasks conf now connection filterExpression availableLinesMb = do
28042804
availableLinesMb
28052805

28062806
tasks <- query_ connection sqlQuery
2807-
formatTasksColor conf now (isJust availableLinesMb) tasks
2807+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
28082808

28092809

28102810
modifiedTasks ::
@@ -2850,7 +2850,11 @@ modifiedTasks conf now connection listModifiedFlag availableLinesMb = do
28502850
AllItems -> tasks
28512851
ModifiedItemsOnly -> filterModified tasks
28522852

2853-
formatTasksColor conf now (isJust availableLinesMb) filteredTasks
2853+
formatTasksColor
2854+
conf
2855+
now
2856+
(wasListTruncated availableLinesMb filteredTasks)
2857+
filteredTasks
28542858

28552859

28562860
overdueTasks ::
@@ -2876,7 +2880,7 @@ overdueTasks conf now connection availableLinesMb = do
28762880
Just availableLines -> availableLines
28772881
]
28782882

2879-
formatTasksColor conf now (isJust availableLinesMb) tasks
2883+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
28802884

28812885

28822886
doneTasks :: Config -> DateTime -> Connection -> Maybe Int -> IO (Doc AnsiStyle)
@@ -2898,7 +2902,7 @@ doneTasks conf now connection availableLinesMb = do
28982902
Just availableLines -> availableLines
28992903
]
29002904

2901-
formatTasksColor conf now (isJust availableLinesMb) tasks
2905+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
29022906

29032907

29042908
obsoleteTasks ::
@@ -2921,7 +2925,7 @@ obsoleteTasks conf now connection availableLinesMb = do
29212925
Just availableLines -> availableLines
29222926
]
29232927

2924-
formatTasksColor conf now (isJust availableLinesMb) tasks
2928+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
29252929

29262930

29272931
deletableTasks ::
@@ -2943,7 +2947,7 @@ deletableTasks conf now connection availableLinesMb = do
29432947
Nothing -> -1 -- No limit
29442948
Just availableLines -> availableLines
29452949
]
2946-
formatTasksColor conf now (isJust availableLinesMb) tasks
2950+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
29472951

29482952

29492953
listRepeating ::
@@ -2964,7 +2968,7 @@ listRepeating conf now connection availableLinesMb = do
29642968
Just availableLines -> availableLines
29652969
]
29662970

2967-
formatTasksColor conf now (isJust availableLinesMb) tasks
2971+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
29682972

29692973

29702974
listRecurring ::
@@ -2985,7 +2989,7 @@ listRecurring conf now connection availableLinesMb = do
29852989
Just availableLines -> availableLines
29862990
]
29872991

2988-
formatTasksColor conf now (isJust availableLinesMb) tasks
2992+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
29892993

29902994

29912995
listReady ::
@@ -3015,7 +3019,7 @@ listReady conf now connection availableLinesMb = do
30153019
Just availableLines -> availableLines
30163020
]
30173021

3018-
formatTasksColor conf now (isJust availableLinesMb) tasks
3022+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
30193023

30203024

30213025
listWaiting ::
@@ -3038,7 +3042,7 @@ listWaiting conf now connection availableLinesMb = do
30383042
Just availableLines -> availableLines
30393043
]
30403044

3041-
formatTasksColor conf now (isJust availableLinesMb) tasks
3045+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
30423046

30433047

30443048
listAll :: Config -> DateTime -> Connection -> Maybe Int -> IO (Doc AnsiStyle)
@@ -3057,7 +3061,7 @@ listAll conf now connection availableLinesMb = do
30573061
Just availableLines -> availableLines
30583062
]
30593063

3060-
formatTasksColor conf now (isJust availableLinesMb) tasks
3064+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
30613065

30623066

30633067
listNoTag :: Config -> DateTime -> Connection -> Maybe Int -> IO (Doc AnsiStyle)
@@ -3082,7 +3086,7 @@ listNoTag conf now connection availableLinesMb = do
30823086
Just availableLines -> availableLines
30833087
]
30843088

3085-
formatTasksColor conf now (isJust availableLinesMb) tasks
3089+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
30863090

30873091

30883092
getWithTag ::
@@ -3147,7 +3151,7 @@ listWithTag ::
31473151
Config -> DateTime -> Connection -> [Text] -> Maybe Int -> IO (Doc AnsiStyle)
31483152
listWithTag conf now connection tags availableLinesMb = do
31493153
tasks <- getWithTag connection Nothing availableLinesMb tags
3150-
formatTasksColor conf now (isJust availableLinesMb) tasks
3154+
formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
31513155

31523156

31533157
queryTasks ::
@@ -3172,7 +3176,11 @@ queryTasks conf now connection sqlQuery availableLinesMb = do
31723176
"SELECT * FROM tasks_view WHERE "
31733177
<> sqlQuery
31743178
<> T.pack limitClause
3175-
formatTasksColor conf now (isJust availableLinesMb && not endsWithLimit) tasks
3179+
formatTasksColor
3180+
conf
3181+
now
3182+
(wasListTruncated availableLinesMb tasks && not endsWithLimit)
3183+
tasks
31763184

31773185

31783186
runSql :: Config -> Text -> IO (Doc AnsiStyle)
@@ -3306,7 +3314,7 @@ runFilter conf now connection exps availableLinesMb = do
33063314
else
33073315
if P.length tasks <= 0
33083316
then pure "No tasks available for the given filter."
3309-
else formatTasksColor conf now (isJust availableLinesMb) tasks
3317+
else formatTasksColor conf now (wasListTruncated availableLinesMb tasks) tasks
33103318
_ -> dieWithError filterHelp
33113319

33123320

@@ -3395,6 +3403,12 @@ columnToDoc conf idColWidth = do
33953403
mempty
33963404

33973405

3406+
wasListTruncated :: Maybe Int -> [a] -> Bool
3407+
wasListTruncated availableLinesMb list = case availableLinesMb of
3408+
Nothing -> False
3409+
Just availableLines -> P.length list P.>= availableLines
3410+
3411+
33983412
formatTasks :: Config -> DateTime -> Bool -> [FullTask] -> Doc AnsiStyle
33993413
formatTasks conf now isTruncated tasks =
34003414
if P.length tasks == 0

tasklite-core/tasklite-core.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ test-suite tasklite-test
148148
ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wno-orphans -Wredundant-constraints -Wunused-packages
149149
build-depends:
150150
MissingH >=1.4 && <1.7
151+
, QuickCheck
151152
, aeson
152153
, base >=4.18 && <5
153154
, bytestring

tasklite-core/test/LibSpec.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import Test.Hspec (
3838
shouldStartWith,
3939
shouldThrow,
4040
)
41+
import Test.Hspec.QuickCheck (prop)
42+
import Test.QuickCheck (NonNegative (..))
4143

4244
import Config (defaultConfig)
4345
import Data.Hourglass (TimeFormat (..), timePrint)
@@ -69,6 +71,7 @@ import Lib (
6971
setReadyUtc,
7072
unrepeatTasks,
7173
updateTask,
74+
wasListTruncated,
7275
)
7376
import Note (Note)
7477
import Task (
@@ -682,3 +685,22 @@ spec = do
682685
(show cliOutput :: Text)
683686
`shouldBe` "\128165 Deleted note \"01hwcqk9nnwjypzw9kr646nqce\" \
684687
\of task \"01hs68z7mdg4ktpxbv0yfafznq\""
688+
689+
context "wasListTruncated" $ do
690+
prop "returns False when limit is Nothing" $
691+
\(list :: [P.Int]) ->
692+
wasListTruncated Nothing list `shouldBe` P.False
693+
694+
prop "returns False when list is shorter than limit" $
695+
\(NonNegative len) (NonNegative extra) ->
696+
let limit = len P.+ extra P.+ 1
697+
list = P.replicate len ()
698+
in wasListTruncated (Just limit) list `shouldBe` P.False
699+
700+
prop "returns True when list length >= limit" $
701+
\(NonNegative limit) (NonNegative extra) ->
702+
let list = P.replicate (limit P.+ extra) ()
703+
in wasListTruncated (Just limit) list `shouldBe` True
704+
705+
it "returns True for zero limit with empty list" $
706+
wasListTruncated (Just 0) ([] :: [()]) `shouldBe` True

0 commit comments

Comments
 (0)