From 18570c9cd096e441b0792f0facf49484ed42d44e Mon Sep 17 00:00:00 2001 From: will Date: Mon, 15 Nov 2021 21:21:41 +0000 Subject: [PATCH] feat(winreg): squashed commits --- docs/docs/contributing-segment.md | 2 +- src/segment_winreg.go | 14 ++++++++++---- src/segment_winreg_test.go | 8 ++++---- themes/schema.json | 28 +++++++++++++++++++++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/docs/docs/contributing-segment.md b/docs/docs/contributing-segment.md index fb020d2d..4c0a2cb7 100644 --- a/docs/docs/contributing-segment.md +++ b/docs/docs/contributing-segment.md @@ -27,7 +27,7 @@ const ( ) func (n *new) enabled() bool { - true + return true } func (n *new) string() string { diff --git a/src/segment_winreg.go b/src/segment_winreg.go index cfb4c575..9aeffff0 100644 --- a/src/segment_winreg.go +++ b/src/segment_winreg.go @@ -32,11 +32,17 @@ func (wr *winreg) enabled() bool { var err error wr.Value, err = wr.env.getWindowsRegistryKeyValue(registryPath, registryKey) - if len(fallback) > 0 && (err != nil || len(wr.Value) == 0) { - wr.Value = fallback - return true + + if err != nil { + if len(fallback) > 0 { + wr.Value = fallback + return true + } + + return false } - return err == nil && len(wr.Value) > 0 + + return true } func (wr *winreg) string() string { diff --git a/src/segment_winreg_test.go b/src/segment_winreg_test.go index f5189a4b..5b58ad8b 100644 --- a/src/segment_winreg_test.go +++ b/src/segment_winreg_test.go @@ -44,20 +44,20 @@ func TestRegQueryEnabled(t *testing.T) { ExpectedValue: "cortana", }, { - CaseDescription: "Fallback value on empty", + CaseDescription: "Empty string value (no error) should display empty string even in presence of fallback", Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion", Key: "InstallTime", Output: "", Fallback: "anaconda", ExpectedSuccess: true, - ExpectedValue: "anaconda", + ExpectedValue: "", }, { - CaseDescription: "Empty no fallback disabled", + CaseDescription: "Empty string value (no error) should display empty string", Path: "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion", Key: "InstallTime", Output: "", - ExpectedSuccess: false, + ExpectedSuccess: true, ExpectedValue: "", }, } diff --git a/themes/schema.json b/themes/schema.json index 030e762e..c1e3a93f 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -182,7 +182,7 @@ "angular", "php", "wifi", - "regquery" + "winreg" ] }, "style": { @@ -1725,6 +1725,32 @@ "title": "Registry Key", "description": "The key under he registry path to get (case insensitive). If left blank, will get the value of the (Default) key in the registry_path", "default": "" + }, + "query_fail_behaviour" : { + "type":"string", + "title": "Query failure behaviour", + "description": "What to do when the registry query fails", + "default":"hide_segment", + "enum": ["hide_segment", "display_fallback_string"] + }, + "query_fail_fallback_string": { + "type": "string", + "title": "Query Failure fallback string", + "description": "In the event of a failure to get the requested key, this string will be displayed in the segment if 'query_fail_behaviour' is set to 'display_fallback_string'", + "default": "" + }, + "query_fail_behaviour" : { + "type":"string", + "title": "Query failure behaviour", + "description": "What to do when the registry query fails", + "default":"hide_segment", + "enum": ["hide_segment", "display_fallback_string", "show_debug_info"] + }, + "query_fail_fallback_string": { + "type": "string", + "title": "Query Failure fallback string", + "description": "In the event of a failure to get the requested key, this string will be displayed in the segment if 'query_fail_behaviour' is set to 'display_fallback_string'", + "default": "" } } }