Skip to content

Commit 14e8932

Browse files
authored
Merge pull request #1234 from wakatime/docs/max-category
Docs for max categories and allow zero value
2 parents ae49e68 + 3651e7e commit 14e8932

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

USAGE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ exclude_unknown_project = false
3333
status_bar_enabled = true
3434
status_bar_coding_activity = true
3535
status_bar_hide_categories = false
36+
status_bar_max_categories = 0
3637
offline = true
3738
proxy = https://user:pass@localhost:8080
3839
no_ssl_verify = false
@@ -100,6 +101,7 @@ Notice how you have to include the exclude patterns from your main `~/.wakatime.
100101
| status_bar_enabled | Turns on wakatime status bar for certain editors. | _bool_ | `true` |
101102
| status_bar_coding_activity | Enables displaying Today's code stats in the status bar of some editors. When false, only the WakaTime icon is displayed in the status bar. | _bool_ | `true` |
102103
| status_bar_hide_categories | When `true`, --today only displays the total code stats, never displaying Categories in the output. | _bool_ | `false` |
104+
| status_bar_max_categories | When greater than zero, limits the number of categories displayed in the status bar. | _int_ | `0` |
103105
| offline | Enables saving code stats locally to ~/.wakatime/offline_heartbeats.bdb when offline, and syncing to the dashboard later when back online. | _bool_ | `true` |
104106
| proxy | Optional proxy configuration. Supports HTTPS, SOCKS and NTLM proxies. For ex: `https://user:pass@host:port`, `socks5://user:pass@host:port`, `domain\\user:pass` | _string_ | |
105107
| no_ssl_verify | Disables SSL certificate verification for HTTPS requests. By default, SSL certificates are verified. | _bool_ | `false` |

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/alecthomas/repr v0.4.0 // indirect
3636
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3737
github.com/fsnotify/fsnotify v1.9.0 // indirect
38-
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
38+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
3939
github.com/golang/mock v1.6.0 // indirect
4040
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4141
github.com/juju/errors v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ github.com/go-viper/encoding/ini v0.1.1 h1:MVWY7B2XNw7lnOqHutGRc97bF3rP7omOdgjdM
3232
github.com/go-viper/encoding/ini v0.1.1/go.mod h1:Pfi4M2V1eAGJVZ5q6FrkHPhtHED2YgLlXhvgMVrB+YQ=
3333
github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk=
3434
github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
35+
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
36+
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
3537
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
3638
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
3739
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=

pkg/params/params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ func LoadStatusBarParams(v *viper.Viper, order FlagReadOrder) (StatusBar, error)
824824
return StatusBar{}, fmt.Errorf("failed to parse today-max-categories: %s", err)
825825
}
826826

827-
if val < 1 {
827+
if val < 0 {
828828
return StatusBar{}, fmt.Errorf("today-max-categories must be a positive number, got %d", val)
829829
}
830830

pkg/params/params_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,46 @@ func TestLoadStatusBarParams_Output_Invalid(t *testing.T) {
29192919
assert.Equal(t, "failed to parse output: invalid output \"invalid\"", err.Error())
29202920
}
29212921

2922+
func TestLoadStatusBarParams_MaxCategories(t *testing.T) {
2923+
v := vipertools.MustNew()
2924+
v.Set("today-max-categories", 0)
2925+
2926+
params, err := paramspkg.LoadStatusBarParams(v, paramspkg.FlagReadOrderFlagPrecedence)
2927+
require.NoError(t, err)
2928+
2929+
assert.Equal(t, output.TextOutput, params.Output)
2930+
}
2931+
2932+
func TestLoadStatusBarParams_MaxCategoriesNegative(t *testing.T) {
2933+
v := vipertools.MustNew()
2934+
v.Set("today-max-categories", -1)
2935+
2936+
_, err := paramspkg.LoadStatusBarParams(v, paramspkg.FlagReadOrderFlagPrecedence)
2937+
require.Error(t, err)
2938+
2939+
assert.Equal(t, "today-max-categories must be a positive number, got -1", err.Error())
2940+
}
2941+
2942+
func TestLoadStatusBarParams_MaxCategoriesSetting(t *testing.T) {
2943+
v := vipertools.MustNew()
2944+
v.Set("settings.status_bar_max_categories", 1)
2945+
2946+
params, err := paramspkg.LoadStatusBarParams(v, paramspkg.FlagReadOrderFlagPrecedence)
2947+
require.NoError(t, err)
2948+
2949+
assert.Equal(t, output.TextOutput, params.Output)
2950+
}
2951+
2952+
func TestLoadStatusBarParams_MaxCategoriesNegativeSetting(t *testing.T) {
2953+
v := vipertools.MustNew()
2954+
v.Set("settings.status_bar_max_categories", -1)
2955+
2956+
_, err := paramspkg.LoadStatusBarParams(v, paramspkg.FlagReadOrderFlagPrecedence)
2957+
require.Error(t, err)
2958+
2959+
assert.Equal(t, "today-max-categories must be a positive number, got -1", err.Error())
2960+
}
2961+
29222962
func TestLoadHeartbeatParams_ExtraHeartbeats_StdinReadOnlyOnce(t *testing.T) {
29232963
r, w, err := os.Pipe()
29242964
require.NoError(t, err)

0 commit comments

Comments
 (0)