Skip to content

Commit 9cbdaf5

Browse files
apragaad-si
andauthored
Add config field to select visible table columns and their order (#113)
* Add support for new `Age` column that shows the age of a task in a human readable fuzzy way --------- Co-authored-by: Adrian Sieber <[email protected]>
1 parent 53d5ae7 commit 9cbdaf5

File tree

8 files changed

+186
-120
lines changed

8 files changed

+186
-120
lines changed

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ WORKDIR /tasklite
66
COPY stack.yaml stack.yaml
77

88
COPY tasklite/README.md tasklite/README.md
9-
COPY tasklite/example-config.yaml tasklite/example-config.yaml
109
COPY tasklite/package.yaml tasklite/package.yaml
1110

1211
COPY tasklite-core/README.md tasklite-core/README.md
@@ -35,7 +34,7 @@ FROM haskell:9.8.4-slim-bullseye
3534
RUN apt-get update && \
3635
apt-get install -y libgmp10
3736
COPY --from=builder \
38-
/tasklite/tasklite/example-config.yaml \
37+
/tasklite-core/example-config.yaml \
3938
/root/.config/tasklite/config.yaml
4039
COPY --from=builder /root/.local/bin/tasklite /usr/local/bin/tasklite
4140

haskell.png

34.2 KB
Loading

tasklite-core/example-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
tableName: tasks
2+
3+
# Select columns and their order for the table view.
4+
# `body` should be the last column, as its width varies for each task.
5+
columns: [id, prio, openedUtc, age, body]
6+
27
idWidth: 4
38
idStyle: green
49
priorityStyle: magenta
@@ -8,6 +13,10 @@ bodyClosedStyle: black
813
closedStyle: dull black
914
dueStyle: yellow
1015
overdueStyle: red
16+
# Shows `Opened UTC` column per default.
17+
# Set this to `true` to show an `Age` column with a
18+
# human readable duration of the task's age.
19+
# useDuration: false
1120
tagStyle: blue
1221
utcFormat: YYYY-MM-DD H:MI:S
1322
#| FIXME: Blocked by https://github.com/vincenthz/hs-hourglass/issue

tasklite-core/source/Config.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,28 @@ addHookFilesToConfig config = do
227227
(config, [])
228228

229229

230+
data Column = IdCol | PrioCol | OpenedUTCCol | AgeCol | BodyCol | EmptyCol
231+
deriving (Eq, Show, Generic)
232+
233+
234+
instance ToJSON Column where
235+
toJSON IdCol = String "id"
236+
toJSON PrioCol = String "prio"
237+
toJSON OpenedUTCCol = String "openedUtc"
238+
toJSON AgeCol = String "age"
239+
toJSON BodyCol = String "body"
240+
toJSON EmptyCol = String ""
241+
instance FromJSON Column where
242+
parseJSON = withText "Column" $ \value -> do
243+
case value of
244+
"id" -> pure IdCol
245+
"prio" -> pure PrioCol
246+
"openedUtc" -> pure OpenedUTCCol
247+
"age" -> pure AgeCol
248+
"body" -> pure BodyCol
249+
_ -> pure EmptyCol
250+
251+
230252
data Config = Config
231253
{ tableName :: Text
232254
, idStyle :: AnsiStyle
@@ -240,6 +262,7 @@ data Config = Config
240262
, tagStyle :: AnsiStyle
241263
, utcFormat :: TimeFormatString
242264
, utcFormatShort :: TimeFormatString
265+
, columns :: [Column]
243266
, dataDir :: FilePath
244267
, dbName :: FilePath
245268
, dateWidth :: Int
@@ -271,6 +294,7 @@ instance FromJSON Config where
271294
utcFormat <- o .:? "utcFormat" .!= defaultConfig.utcFormat
272295
utcFormatShort <- o .:? "utcFormatShort" .!= defaultConfig.utcFormatShort
273296
dataDir <- o .:? "dataDir" .!= defaultConfig.dataDir
297+
columns <- o .:? "columns" .!= defaultConfig.columns
274298
dbName <- o .:? "dbName" .!= defaultConfig.dbName
275299
dateWidth <- o .:? "dateWidth" .!= defaultConfig.dateWidth
276300
bodyWidth <- o .:? "bodyWidth" .!= defaultConfig.bodyWidth
@@ -367,6 +391,7 @@ defaultConfig =
367391
, tagStyle = color Blue
368392
, utcFormat = toFormat ("YYYY-MM-DD H:MI:S" :: [Char])
369393
, utcFormatShort = toFormat ("YYYY-MM-DD H:MI" :: [Char])
394+
, columns = [IdCol, PrioCol, OpenedUTCCol, BodyCol]
370395
, dataDir = ""
371396
, dbName = "main.db"
372397
, dateWidth = 10

0 commit comments

Comments
 (0)