Skip to content

Commit 0bb0d83

Browse files
authored
Add --no-style option and fix output styling on Windows
* Add download link for Windows * Add option to deactivate output colors/styling * Initialise console on windows for proper ANSI support * Remove obsolete section on terminal support on Windows * Sort imports * Fix syntax * Update changelog with v2.2 changes
1 parent f912175 commit 0bb0d83

File tree

15 files changed

+64
-5
lines changed

15 files changed

+64
-5
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
2525
- [**MacOS**](https://github.com/jotaen/klog/releases/download/${{ github.event.inputs.release_id }}/klog-mac.zip)
2626
- [**Linux**](https://github.com/jotaen/klog/releases/download/${{ github.event.inputs.release_id }}/klog-linux.zip)
27+
- [**Windows**](https://github.com/jotaen/klog/releases/download/${{ github.event.inputs.release_id }}/klog-windows.zip)
2728
2829
You find the install instructions in the [README](https://github.com/jotaen/klog).
2930
Consult the [Changelog](https://github.com/jotaen/klog/blob/main/CHANGELOG.md) to learn what’s new.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog (command line tool)
22

3+
## v2.2
4+
- **[ FEATURE ]** Provide `--no-style` option to disable output
5+
formatting (i.e. no colours, underlined, bold, etc.)
6+
- **[ FIX ]** Make sure that output formatting works on Windows
7+
across all Terminals.
8+
39
## v2.1
410
- **[ FEATURE ]** Provide native Windows binary
511

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ In order to not miss any updates you can either subscribe to the release notific
2727
1. [**Download**](https://www.github.com/jotaen/klog/releases) and unzip
2828
2. Copy to path, e.g. to `C:\Windows\System32` (might require admin privileges)
2929

30-
klog works well with [Windows Terminal](https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701),
31-
support for other terminals might be limited.
32-
3330
By the way, as an alternative you can also use the Linux binary on the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
3431

3532
## Contribute

src/app/cli/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ type Create struct {
1212
Template string `name:"template" hidden help:"The name of the template to instantiate"`
1313
ShouldTotal Duration `name:"should" help:"A should total property"`
1414
lib.AtDateArgs
15+
lib.NoStyleArgs
1516
lib.OutputFileArgs
1617
}
1718

1819
func (opt *Create) Run(ctx app.Context) error {
20+
opt.NoStyleArgs.SetGlobalState()
1921
date := opt.AtDate(ctx.Now())
2022
lines, err := func() ([]parsing.Text, error) {
2123
if opt.Template != "" {

src/app/cli/lib/common_args.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package lib
22

33
import (
44
. "klog"
5+
"klog/parser"
56
"klog/service"
7+
"os"
68
gotime "time"
79
)
810

@@ -108,6 +110,16 @@ func (args *WarnArgs) ToString(now gotime.Time, records []Record) string {
108110
return PrettifyWarnings(ws)
109111
}
110112

113+
type NoStyleArgs struct {
114+
NoStyle bool `name:"no-style" help:"Do not style or color the values"`
115+
}
116+
117+
func (args *NoStyleArgs) SetGlobalState() {
118+
if args.NoStyle || os.Getenv("NO_COLOR") != "" {
119+
Styler = parser.DefaultSerialiser
120+
}
121+
}
122+
111123
type SortArgs struct {
112124
Sort string `name:"sort" help:"Sort output by date (ASC or DESC)" enum:"ASC,DESC,"`
113125
}

src/app/cli/now.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ type Now struct {
1717
lib.DiffArgs
1818
Follow bool `name:"follow" short:"f" help:"Keep shell open and follow changes"`
1919
lib.WarnArgs
20+
lib.NoStyleArgs
2021
lib.InputFilesArgs
2122
}
2223

2324
func (opt *Now) Run(ctx app.Context) error {
25+
opt.NoStyleArgs.SetGlobalState()
2426
h := func() error { return handle(opt, ctx) }
2527
if opt.Follow {
2628
return withRepeat(ctx, h)

src/app/cli/print.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ type Print struct {
1010
lib.FilterArgs
1111
lib.SortArgs
1212
lib.WarnArgs
13+
lib.NoStyleArgs
1314
lib.InputFilesArgs
1415
}
1516

1617
func (opt *Print) Run(ctx app.Context) error {
18+
opt.NoStyleArgs.SetGlobalState()
1719
records, err := ctx.ReadInputs(opt.File...)
1820
if err != nil {
1921
return err

src/app/cli/report.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ type Report struct {
1515
lib.WarnArgs
1616
Fill bool `name:"fill" short:"f" help:"Show all consecutive days, even if there is no record"`
1717
lib.NowArgs
18+
lib.NoStyleArgs
1819
lib.InputFilesArgs
1920
}
2021

2122
func (opt *Report) Run(ctx app.Context) error {
23+
opt.NoStyleArgs.SetGlobalState()
2224
records, err := ctx.ReadInputs(opt.File...)
2325
if err != nil {
2426
return err

src/app/cli/start.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import (
1010
type Start struct {
1111
lib.AtTimeArgs
1212
lib.AtDateArgs
13+
lib.NoStyleArgs
1314
lib.OutputFileArgs
1415
}
1516

1617
func (opt *Start) Run(ctx app.Context) error {
18+
opt.NoStyleArgs.SetGlobalState()
1719
date := opt.AtDate(ctx.Now())
1820
time := opt.AtTime(ctx.Now())
1921
return applyReconciler(

src/app/cli/stop.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import (
1010
type Stop struct {
1111
lib.AtTimeArgs
1212
lib.AtDateArgs
13+
lib.NoStyleArgs
1314
lib.OutputFileArgs
1415
}
1516

1617
func (opt *Stop) Run(ctx app.Context) error {
18+
opt.NoStyleArgs.SetGlobalState()
1719
date := opt.AtDate(ctx.Now())
1820
time := opt.AtTime(ctx.Now())
1921
return applyReconciler(

0 commit comments

Comments
 (0)