@@ -10,6 +10,7 @@ import Data.Hourglass
10
10
import Data.Text as T
11
11
import Data.ULID
12
12
import Data.Coerce
13
+ import Data.Yaml as Yaml
13
14
import Database.Beam hiding (char )
14
15
import Database.Beam.Sqlite
15
16
import Database.Beam.Schema.Tables
@@ -664,12 +665,152 @@ stopTasks conf connection ids = do
664
665
(show logMessages)
665
666
666
667
668
+ formatTaskForInfo
669
+ :: Config
670
+ -> DateTime
671
+ -> (TaskView , [TaskToTag ], [TaskToNote ])
672
+ -> Doc AnsiStyle
673
+ formatTaskForInfo conf now (taskV, tags, notes) =
674
+ let
675
+ mkGreen = annotate (color Green )
676
+ grayOut = annotate (colorDull Black )
677
+ stateHierarchy = getStateHierarchy now $ copyTimesToTask taskV
678
+ mbCreatedUtc = fmap
679
+ (pack . (timePrint $ utcFormat defaultConfig))
680
+ (ulidTextToDateTime $ TaskView. ulid taskV)
681
+ tagsPretty = tags
682
+ <&> (\ t -> (annotate (tagStyle conf) (pretty $ TaskToTag. tag t))
683
+ <++> (fromMaybe mempty $ fmap
684
+ (grayOut . pretty . pack . timePrint (utcFormat conf))
685
+ (ulidTextToDateTime $ TaskToTag. ulid t))
686
+ <++> (grayOut $ pretty $ TaskToTag. ulid t)
687
+ )
688
+ notesPretty = notes
689
+ <&> (\ n -> (fromMaybe mempty $ fmap
690
+ (grayOut . pretty . pack . timePrint (utcFormat conf))
691
+ (ulidTextToDateTime $ TaskToNote. ulid n))
692
+ <++> (grayOut $ pretty $ TaskToNote. ulid n) <> hardline
693
+ <> (indent 2 $ reflow $ TaskToNote. note n)
694
+ <> hardline
695
+ )
696
+
697
+ mbAwakeUtc = TaskView. awake_utc taskV
698
+ mbReadyUtc = TaskView. ready_utc taskV
699
+ mbWaitingUtc = TaskView. waiting_utc taskV
700
+ mbReviewUtc = TaskView. review_utc taskV
701
+ mbDueUtc = TaskView. due_utc taskV
702
+ mbClosedUtc = TaskView. closed_utc taskV
703
+ mbModifiedUtc = Just $ TaskView. modified_utc taskV
704
+
705
+ printIf :: Doc AnsiStyle -> Maybe Text -> Maybe (Doc AnsiStyle )
706
+ printIf name value = fmap
707
+ (\ v -> name <+> (annotate (dueStyle conf) $ pretty v) <> hardline)
708
+ value
709
+ in
710
+ hardline
711
+ <> annotate bold (reflow $ TaskView. body taskV) <> hardline
712
+ <> hardline
713
+ <> (if P. null tags
714
+ then mempty
715
+ else (hsep $ (tags <&> TaskToTag. tag) <$$> (formatTag conf)) <> hardline
716
+ <> hardline
717
+ )
718
+
719
+ <> (if P. null notes
720
+ then mempty
721
+ else (notes
722
+ <&> (\ n -> (fromMaybe mempty $ fmap
723
+ (grayOut . pretty . pack . timePrint (utcFormatShort conf))
724
+ (ulidTextToDateTime $ TaskToNote. ulid n))
725
+ <++> (align $ reflow $ TaskToNote. note n)
726
+ )
727
+ & vsep)
728
+ <> hardline
729
+ <> hardline
730
+ )
731
+
732
+ <> " State:" <+> mkGreen (pretty stateHierarchy) <> hardline
733
+ <> " Priority:" <+> annotate (priorityStyle conf)
734
+ (pretty $ TaskView. priority taskV) <> hardline
735
+ <> " ULID:" <+> grayOut (pretty $ TaskView. ulid taskV)
736
+ <> hardline
737
+
738
+ <> hardline
739
+
740
+ <> ((
741
+ (printIf " 🆕 Created " , mbCreatedUtc) :
742
+ (printIf " ☀️ Awake " , mbAwakeUtc) :
743
+ (printIf " 📅 Ready " , mbReadyUtc) :
744
+ (printIf " ⏳ Waiting " , mbWaitingUtc) :
745
+ (printIf " 🔎 Review " , mbReviewUtc) :
746
+ (printIf " 📅 Due " , mbDueUtc) :
747
+ (printIf " ✅ Done " , mbClosedUtc) :
748
+ (printIf " ✏️ Modified " , mbModifiedUtc) :
749
+ [] )
750
+ & sortBy (compare `on` snd )
751
+ <&> (\ tup -> (fst tup) (snd tup))
752
+ & catMaybes
753
+ & punctuate (pretty (" ⬇" :: Text ))
754
+ & vsep
755
+ )
756
+
757
+ <> hardline
758
+
759
+ <> (fromMaybe mempty $ (fmap
760
+ (\ value -> " Repetition Duration:" <+> (mkGreen $ pretty value)
761
+ <> hardline)
762
+ (TaskView. repetition_duration taskV)
763
+ ))
764
+
765
+ <> (fromMaybe mempty $ (fmap
766
+ (\ value -> " Recurrence Duration:" <+> (mkGreen $ pretty value)
767
+ <> hardline)
768
+ (TaskView. recurrence_duration taskV)
769
+ ))
770
+
771
+ <> (fromMaybe mempty $ (fmap
772
+ (\ value -> " Group Ulid:"
773
+ <+> (grayOut $ pretty value)
774
+ <> hardline)
775
+ (TaskView. group_ulid taskV)
776
+ ))
777
+
778
+ <> " User:" <+> (mkGreen $ pretty $ TaskView. user taskV) <> hardline
779
+
780
+ <> hardline
781
+
782
+ <> (fromMaybe mempty $ (fmap
783
+ (\ value -> " Metadata:" <> hardline
784
+ <> indent 2 (pretty $ decodeUtf8 $ Yaml. encode value)
785
+ <> hardline
786
+ )
787
+ (TaskView. metadata taskV)
788
+ ))
789
+
790
+ <> (if P. null tags
791
+ then mempty
792
+ else (annotate underlined " Tags Detailed:" ) <> hardline
793
+ <> hardline
794
+ <> vsep tagsPretty <> hardline
795
+ <> hardline
796
+ )
797
+
798
+ <> (if P. null notes
799
+ then mempty
800
+ else (annotate underlined " Notes Detailed:" ) <> hardline
801
+ <> hardline
802
+ <> vsep notesPretty <> hardline
803
+ )
804
+
805
+
667
806
infoTask :: Config -> Connection -> Text -> IO (Doc AnsiStyle )
668
807
infoTask conf connection idSubstr = do
669
808
execWithTask conf connection idSubstr $ \ task -> do
670
809
let
671
810
taskUlid@ (TaskUlid idText) = primaryKey task
672
811
812
+ now <- dateCurrent
813
+
673
814
runBeamSqlite connection $ do
674
815
(mbFullTask :: Maybe TaskView ) <- runSelectReturningOne $ select $
675
816
filter_ (\ tsk -> TaskView. ulid tsk ==. val_ idText) $
@@ -683,39 +824,36 @@ infoTask conf connection idSubstr = do
683
824
filter_ (\ theNote -> TaskToNote. task_ulid theNote ==. val_ taskUlid) $
684
825
all_ (_tldbTaskToNote taskLiteDb)
685
826
686
- let
687
- -- TODO: Colorize all YAML keys
688
- mkGreen = annotate (color Green )
689
- yamlList = (hang 2 ) . (" -" <+> )
690
- rmLastLine = unlines . P. reverse . P. drop 1 . P. reverse . lines . show
691
- formatTask fullTask =
692
- pretty fullTask <> hardline
693
- <> mkGreen " priority:"
694
- <+> (pretty $ TaskView. priority fullTask)
695
- <> hardline
696
- <> mkGreen " tags:\n "
697
- <> indent 2 (vsep $ fmap
698
- (yamlList . pretty . rmLastLine . pretty) tags)
699
- <> hardline
700
- <> mkGreen " notes:\n "
701
- <> indent 2 (vsep $ fmap
702
- (yamlList . pretty . rmLastLine . pretty) notes)
703
-
704
827
pure $ case mbFullTask of
705
828
Nothing -> pretty noTasksWarning
706
- Just fullTask -> formatTask fullTask
829
+ Just fullTask -> formatTaskForInfo conf now ( fullTask, tags, notes)
707
830
708
831
709
- nextTask :: Connection -> IO (Doc AnsiStyle )
710
- nextTask connection = do
711
- let
712
- stateNullQuery = " select * from `tasks_view` where state is NULL "
713
- orderByAndLimit = " order by `priority` desc limit 1"
714
- tasks <- query_ connection $ Query $ stateNullQuery <> orderByAndLimit
832
+ nextTask :: Config -> Connection -> IO (Doc AnsiStyle )
833
+ nextTask conf connection = do
834
+ now <- dateCurrent
835
+
836
+ runBeamSqlite connection $ do
837
+ (mbFullTask :: Maybe TaskView ) <- runSelectReturningOne $ select $
838
+ limit_ 1 $
839
+ orderBy_ (desc_ . TaskView. priority) $
840
+ filter_ (\ tsk -> TaskView. closed_utc tsk ==. val_ Nothing ) $
841
+ allFromView_ (_tldbTasksView taskLiteDb)
842
+
843
+ case mbFullTask of
844
+ Nothing -> pure $ pretty noTasksWarning
845
+ Just fullTask -> do
846
+ tags <- runSelectReturningList $ select $
847
+ filter_ (\ tag -> TaskToTag. task_ulid tag ==.
848
+ (val_ $ TaskUlid $ TaskView. ulid fullTask)) $
849
+ all_ (_tldbTaskToTag taskLiteDb)
850
+
851
+ notes <- runSelectReturningList $ select $
852
+ filter_ (\ theNote -> TaskToNote. task_ulid theNote ==.
853
+ (val_ $ TaskUlid $ TaskView. ulid fullTask)) $
854
+ all_ (_tldbTaskToNote taskLiteDb)
715
855
716
- pure $ case P. head (tasks :: [FullTask ]) of
717
- Nothing -> pretty noTasksWarning
718
- Just task -> pretty task
856
+ pure $ formatTaskForInfo conf now (fullTask, tags, notes)
719
857
720
858
721
859
findTask :: Connection -> Text -> IO (Doc AnsiStyle )
@@ -1098,6 +1236,13 @@ showAtPrecision numOfDigits number =
1098
1236
else " "
1099
1237
1100
1238
1239
+ formatTag :: Pretty a => Config -> a -> Doc AnsiStyle
1240
+ formatTag conf =
1241
+ annotate (tagStyle conf)
1242
+ . (annotate (color Black ) " +" <> )
1243
+ . pretty
1244
+
1245
+
1101
1246
formatTaskLine :: Config -> DateTime -> Int -> FullTask -> Doc AnsiStyle
1102
1247
formatTaskLine conf now taskUlidWidth task =
1103
1248
let
@@ -1107,9 +1252,6 @@ formatTaskLine conf now taskUlidWidth task =
1107
1252
(ulidTextToDateTime $ FullTask. ulid task)
1108
1253
body = FullTask. body task
1109
1254
tags = fromMaybe [] $ FullTask. tags task
1110
- formatTag = annotate (tagStyle conf)
1111
- . (annotate (color Black ) " +" <> )
1112
- . pretty
1113
1255
closedUtcMaybe = (FullTask. closed_utc task)
1114
1256
>>= parseUtc
1115
1257
<&> timePrint (utcFormat conf)
@@ -1151,7 +1293,7 @@ formatTaskLine conf now taskUlidWidth task =
1151
1293
else grayOutIfDone (reflow body)) :
1152
1294
annotate (dueStyle conf) (pretty dueUtcMaybe) :
1153
1295
annotate (closedStyle conf) (pretty closedUtcMaybe) :
1154
- hsep (tags <$$> formatTag) :
1296
+ hsep (tags <$$> ( formatTag conf) ) :
1155
1297
(if (not $ P. null $ FullTask. notes task) then " 📝" else " " ) :
1156
1298
[] )
1157
1299
in
0 commit comments