Skip to content

Commit d909896

Browse files
committed
feat: dynamic width for reports
1 parent ce665ea commit d909896

File tree

4 files changed

+104
-96
lines changed

4 files changed

+104
-96
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ brews:
3232
directory: Formula
3333
license: MIT
3434
homepage: "https://github.com/dhth/hours"
35-
description: "A no-frills command-line app for tracking time on tasks"
35+
description: "A no-frills time tracking toolkit for the command line"
3636

3737
changelog:
3838
sort: asc

README.md

Lines changed: 65 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# hours
22

3-
✨ Overview
4-
---
3+
`hours` is a no-frills time tracking toolkit for the command line.
4+
5+
It's designed for users who want basic time tracking for their tasks/projects
6+
right in the terminal. With a simple and minimalistic UI, almost everything in
7+
`hours` can be achieved with one or two keypresses. It can also generate
8+
plaintext reports, summary statistics, and logs based on time tracked.
9+
10+
![Usage](https://tools.dhruvs.space/images/hours/hours.gif)
511

6-
`hours` is a no-frills command-line app for tracking time on tasks. It's
7-
designed for users who want basic time tracking for their tasks/projects, right
8-
in the terminal. With a simple and minimalistic UI, almost everything in `hours`
9-
can be achieved with one or two keypresses. It can also generate plaintext
10-
reports, summary statistics, and logs based on time tracked.
12+
[Link to Video][2]
1113

1214
🤔 Motivation
1315
---
@@ -22,6 +24,12 @@ precisely fit these needs, so I decided to build one for myself.
2224
💾 Install
2325
---
2426

27+
**homebrew**:
28+
29+
```sh
30+
brew install dhth/tap/hours
31+
```
32+
2533
**go**:
2634

2735
```sh
@@ -31,6 +39,8 @@ go install github.com/dhth/hours@latest
3139
⚡️ Usage
3240
---
3341

42+
### TUI
43+
3444
Open the TUI by simply running `hours`. The TUI lets you do the following:
3545

3646
- create/update tasks
@@ -39,125 +49,93 @@ Open the TUI by simply running `hours`. The TUI lets you do the following:
3949
- deactivate/activate a task
4050
- view historical task log entries
4151

52+
![Usage](https://tools.dhruvs.space/images/hours/tui-1.png)
53+
54+
![Usage](https://tools.dhruvs.space/images/hours/tui-2.png)
55+
56+
![Usage](https://tools.dhruvs.space/images/hours/tui-3.png)
57+
4258
Besides a TUI, `hours` also offers reports, statistics, and logs based on the
4359
time tracking you do. These can be viewed using the subcommands `report`,
4460
`stats`, and `log` respectively.
4561

4662
### Reports
4763

64+
```bash
65+
hours report [flags] [arg]
4866
```
49-
hours report -h
5067

5168
Output a report based on task log entries.
5269

5370
Reports show time spent on tasks per day in the time period you specify. These
54-
can also be aggregated (using -a) to consolidate all task entries and show the
71+
can also be aggregated (using `-a`) to consolidate all task entries and show the
5572
cumulative time spent on each task per day.
5673

5774
Accepts an argument, which can be one of the following:
5875

59-
today: for today's report
60-
yest: for yesterday's report
61-
3d: for a report on the last 3 days (default)
62-
week: for a report on the current week
63-
date: for a report for a specific date (eg. "2024/06/08")
64-
range: for a report for a date range (eg. "2024/06/08...2024/06/12")
76+
today: for today's report
77+
yest: for yesterday's report
78+
3d: for a report on the last 3 days (default)
79+
week: for a report on the current week
80+
date: for a report for a specific date (eg. "2024/06/08")
81+
range: for a report for a date range (eg. "2024/06/08...2024/06/12")
6582

66-
Note: If a task log continues past midnight in your local timezone, it
67-
will be reported on the day it ends.
83+
*Note: If a task log continues past midnight in your local timezone, it will be
84+
reported on the day it ends.*
6885

69-
Usage:
70-
hours report [flags]
86+
![Usage](https://tools.dhruvs.space/images/hours/report-1.png)
7187

72-
Flags:
73-
-a, --agg whether to aggregate data by task for each day in report
74-
-p, --plain whether to output report without any formatting
75-
```
88+
### Logs
7689

7790
```bash
78-
# see report from last 3 days
79-
hours report
80-
81-
# see aggregated time spent on tasks
82-
hours report -a
83-
84-
# see report for the 7 days
85-
hours report week
86-
87-
# see report for a specific date range
88-
hours report 2024/06/08...2024/06/12
89-
```
90-
91-
Statistics
92-
---
93-
91+
hours log [flags] [arg]
9492
```
95-
hours stats -h
9693

97-
Output statistics for tracked time.
94+
Output task log entries.
9895

9996
Accepts an argument, which can be one of the following:
10097

101-
today: show stats for today
102-
yest: show stats for yesterday
103-
3d: show stats for the last 3 days (default)
104-
week: show stats for the current week
105-
month: show stats for the current month
106-
date: show stats for a specific date (eg. "2024/06/08")
107-
range: show stats for a specific date range (eg. "2024/06/08...2024/06/12")
108-
all: show stats for all log entries
109-
110-
Note: If a task log continues past midnight in your local timezone, it'll
111-
be considered in the stats for the day it ends.
98+
today: for log entries from today
99+
yest: for log entries from yesterday
100+
3d: for log entries from the last 3 days (default)
101+
week: for log entries from the current week
102+
date: for log entries from a specific date (eg. "2024/06/08")
103+
range: for log entries from a specific date range (eg. "2024/06/08...2024/06/12")
112104

113-
Usage:
114-
hours stats [flags]
105+
*Note: If a task log continues past midnight in your local timezone, it'll
106+
appear in the log for the day it ends.*
115107

116-
Flags:
117-
-p, --plain whether to output stats without any formatting
118-
```
108+
![Usage](https://tools.dhruvs.space/images/hours/log-1.png)
119109

120-
### Logs
110+
Statistics
111+
---
121112

113+
```bash
114+
hours stats [flag] [arg]
122115
```
123-
hours log -h
124116

125-
Output task log entries.
117+
Output statistics for tracked time.
126118

127119
Accepts an argument, which can be one of the following:
128120

129-
today: for log entries from today
130-
yest: for log entries from yesterday
131-
3d: for log entries from the last 3 days (default)
132-
week: for log entries from the current week
133-
date: for log entries from a specific date (eg. "2024/06/08")
134-
range: for log entries from a specific date range (eg. "2024/06/08...2024/06/12")
135-
136-
Note: If a task log continues past midnight in your local timezone, it'll
137-
appear in the log for the day it ends.
138-
139-
Usage:
140-
hours log [flags]
141-
142-
Flags:
143-
-p, --plain whether to output log without any formatting
144-
```
121+
today: show stats for today
122+
yest: show stats for yesterday
123+
3d: show stats for the last 3 days (default)
124+
week: show stats for the current week
125+
month: show stats for the current month
126+
date: show stats for a specific date (eg. "2024/06/08")
127+
range: show stats for a specific date range (eg. "2024/06/08...2024/06/12")
128+
all: show stats for all log entries
145129

146-
```bash
147-
# see log entries from today
148-
hours log today
130+
*Note: If a task log continues past midnight in your local timezone, it'll
131+
be considered in the stats for the day it ends.*
149132

150-
# see log entries from a specific day
151-
hours log 2024/06/08
152-
153-
# see log entries from a specific date range
154-
hours log 2024/06/08...2024/06/12
155-
```
133+
![Usage](https://tools.dhruvs.space/images/hours/stats-1.png)
156134

157135
📋 TUI Reference Manual
158136
---
159137

160-
```
138+
```text
161139
"hours" has 5 panes:
162140
- Tasks List View Shows your tasks
163141
- Task Management View Allows you to create/update tasks
@@ -213,3 +191,4 @@ Acknowledgements
213191
`hours` is built using the TUI framework [bubbletea][1].
214192

215193
[1]: https://github.com/charmbracelet/bubbletea
194+
[2]: https://www.youtube.com/watch?v=o244r1nyxac

cmd/root.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ func die(msg string, args ...any) {
3131

3232
var rootCmd = &cobra.Command{
3333
Use: "hours",
34-
Short: "Track time on your tasks via a simple TUI.",
34+
Short: "\"hours\" is a no-frills time tracking toolkit for the command line",
35+
Long: `"hours" is a no-frills time tracking toolkit for the command line.
36+
37+
You can use "hours" to track time on your tasks, or view logs, reports, and
38+
summary statistics for your tracked time.
39+
`,
3540
PersistentPreRun: func(cmd *cobra.Command, args []string) {
3641
if dbPath == "" {
3742
die("dbpath cannot be empty")

internal/ui/report.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ func renderNDaysReport(db *sql.DB, writer io.Writer, start time.Time, numDays in
153153

154154
rs := getReportStyles(plain)
155155

156+
var summaryBudget int
157+
switch numDays {
158+
case 7:
159+
summaryBudget = 8
160+
case 6:
161+
summaryBudget = 10
162+
case 5:
163+
summaryBudget = 14
164+
default:
165+
summaryBudget = 16
166+
}
167+
156168
styleCache := make(map[string]lipgloss.Style)
157169
for rowIndex := 0; rowIndex < maxEntryForADay; rowIndex++ {
158170
row := make([]string, numDays)
@@ -166,8 +178,8 @@ func renderNDaysReport(db *sql.DB, writer io.Writer, start time.Time, numDays in
166178
timeSpentStr := humanizeDuration(tr.secsSpent)
167179

168180
if plain {
169-
row[colIndex] = fmt.Sprintf("%s %s",
170-
RightPadTrim(tr.taskSummary, 8, false),
181+
row[colIndex] = fmt.Sprintf("%s %s",
182+
RightPadTrim(tr.taskSummary, summaryBudget, false),
171183
timeSpentStr,
172184
)
173185
} else {
@@ -178,8 +190,8 @@ func renderNDaysReport(db *sql.DB, writer io.Writer, start time.Time, numDays in
178190
styleCache[tr.taskSummary] = reportStyle
179191
}
180192

181-
row[colIndex] = fmt.Sprintf("%s %s",
182-
reportStyle.Render(RightPadTrim(tr.taskSummary, 8, false)),
193+
row[colIndex] = fmt.Sprintf("%s %s",
194+
reportStyle.Render(RightPadTrim(tr.taskSummary, summaryBudget, false)),
183195
reportStyle.Render(timeSpentStr),
184196
)
185197
}
@@ -268,6 +280,18 @@ func renderNDaysReportAgg(db *sql.DB, writer io.Writer, start time.Time, numDays
268280

269281
rs := getReportStyles(plain)
270282

283+
var summaryBudget int
284+
switch numDays {
285+
case 7:
286+
summaryBudget = 8
287+
case 6:
288+
summaryBudget = 10
289+
case 5:
290+
summaryBudget = 14
291+
default:
292+
summaryBudget = 16
293+
}
294+
271295
styleCache := make(map[string]lipgloss.Style)
272296
for rowIndex := 0; rowIndex < maxEntryForADay; rowIndex++ {
273297
row := make([]string, numDays)
@@ -281,8 +305,8 @@ func renderNDaysReportAgg(db *sql.DB, writer io.Writer, start time.Time, numDays
281305
timeSpentStr := humanizeDuration(tr.secsSpent)
282306

283307
if plain {
284-
row[colIndex] = fmt.Sprintf("%s %s",
285-
RightPadTrim(tr.taskSummary, 8, false),
308+
row[colIndex] = fmt.Sprintf("%s %s",
309+
RightPadTrim(tr.taskSummary, summaryBudget, false),
286310
timeSpentStr,
287311
)
288312
} else {
@@ -292,8 +316,8 @@ func renderNDaysReportAgg(db *sql.DB, writer io.Writer, start time.Time, numDays
292316
styleCache[tr.taskSummary] = reportStyle
293317
}
294318

295-
row[colIndex] = fmt.Sprintf("%s %s",
296-
reportStyle.Render(RightPadTrim(tr.taskSummary, 8, false)),
319+
row[colIndex] = fmt.Sprintf("%s %s",
320+
reportStyle.Render(RightPadTrim(tr.taskSummary, summaryBudget, false)),
297321
reportStyle.Render(timeSpentStr),
298322
)
299323
}

0 commit comments

Comments
 (0)