From 0e60ede97e61f713e5cdad07f50ed26d10498613 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 23 Jul 2024 23:39:54 +0300 Subject: [PATCH 1/7] [sliceutil] Methods 'Copy', 'IsEqual', 'Index', 'Contains', and 'Deduplicate' marked as deprecated --- CHANGELOG.md | 4 ++++ sliceutil/sliceutil.go | 10 ++++++++++ version.go | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0189edd3..bfd2ef36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### [13.2.1](https://kaos.sh/ek/13.2.1) + +- `[sliceutil]` Methods `Copy`, `IsEqual`, `Index`, `Contains`, and `Deduplicate` marked as deprecated + ### [13.2.0](https://kaos.sh/ek/13.2.0) - `[errutil]` Added method `Wrap` diff --git a/sliceutil/sliceutil.go b/sliceutil/sliceutil.go index 0bdc468d..08a8934a 100644 --- a/sliceutil/sliceutil.go +++ b/sliceutil/sliceutil.go @@ -15,6 +15,8 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // Copy creates copy of given slice +// +// Deprecated: Use method slices.Clone instead func Copy[K comparable](slice []K) []K { if len(slice) == 0 { return nil @@ -27,6 +29,8 @@ func Copy[K comparable](slice []K) []K { } // IsEqual compares two slices and returns true if the slices are equal +// +// Deprecated: Use method slices.Equal instead func IsEqual[K comparable](s1, s2 []K) bool { switch { case s1 == nil && s2 == nil: @@ -105,6 +109,8 @@ func ErrorToString(data []error) []string { } // Index returns index of given item in a slice or -1 otherwise +// +// Deprecated: Use method slices.Index instead func Index[K comparable](slice []K, item K) int { if len(slice) == 0 { return -1 @@ -120,6 +126,8 @@ func Index[K comparable](slice []K, item K) int { } // Contains checks if string slice contains some value +// +// Deprecated: Use method slices.Contains instead func Contains[K comparable](slice []K, value K) bool { return Index(slice, value) != -1 } @@ -151,6 +159,8 @@ LOOP: // Deduplicate removes duplicates from slice. // Slice must be sorted before deduplication. +// +// Deprecated: Use method slices.Compact instead func Deduplicate[K comparable](slice []K) []K { var n int diff --git a/version.go b/version.go index d4e66f61..a28a3a3c 100644 --- a/version.go +++ b/version.go @@ -8,4 +8,4 @@ package ek // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "13.2.0" +const VERSION = "13.2.1" From 3cd122b2946ac306a1b3c5cf5a3e10b1e53e0975 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 24 Jul 2024 00:35:17 +0300 Subject: [PATCH 2/7] [terminal/input] Improve TMUX support --- CHANGELOG.md | 2 ++ terminal/input/input.go | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd2ef36..006a28e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ### [13.2.1](https://kaos.sh/ek/13.2.1) - `[sliceutil]` Methods `Copy`, `IsEqual`, `Index`, `Contains`, and `Deduplicate` marked as deprecated +- `[terminal/input]` Improved TMUX support + ### [13.2.0](https://kaos.sh/ek/13.2.0) diff --git a/terminal/input/input.go b/terminal/input/input.go index c13916aa..20335bc6 100644 --- a/terminal/input/input.go +++ b/terminal/input/input.go @@ -68,7 +68,7 @@ var AlwaysYes = false // ////////////////////////////////////////////////////////////////////////////////// // -var tmux int8 +var oldTMUXFlag int8 // ////////////////////////////////////////////////////////////////////////////////// // @@ -167,7 +167,8 @@ func getMask(message string) string { length := utf8.RuneCountInString(message) if !HideLength { - if isTmuxSession() { + // Check for old versions of TMUX with rendering problems + if isOldTMUXSession() { masking = strings.Repeat("*", length) } else { masking = strings.Repeat(MaskSymbol, length) @@ -248,15 +249,21 @@ func readUserInput(title string, nonEmpty, private bool) (string, error) { return input, err } -// isTmuxSession returns true if we work in tmux session -func isTmuxSession() bool { - if tmux == 0 { +// isOldTMUXSession returns true if we work in tmux session and version is older than 3.x +func isOldTMUXSession() bool { + if oldTMUXFlag == 0 { if os.Getenv("TMUX") == "" { - tmux = -1 + oldTMUXFlag = -1 } else { - tmux = 1 + version := os.Getenv("TERM_PROGRAM_VERSION") + + if len(version) > 0 && (version[0] == '1' || version[0] == '2') { + oldTMUXFlag = 1 + } else { + oldTMUXFlag = -1 + } } } - return tmux == 1 + return oldTMUXFlag == 1 } From 6c143981279bcc194104db537b48d11a5d0558c5 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 24 Jul 2024 00:53:05 +0300 Subject: [PATCH 3/7] Replace deprecated methods --- fmtutil/panel/panel.go | 4 ++-- support/network/network.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fmtutil/panel/panel.go b/fmtutil/panel/panel.go index b10aea89..7b2d7208 100644 --- a/fmtutil/panel/panel.go +++ b/fmtutil/panel/panel.go @@ -10,12 +10,12 @@ package panel import ( "bytes" + "slices" "strings" "github.com/essentialkaos/ek/v13/fmtc" "github.com/essentialkaos/ek/v13/fmtutil" "github.com/essentialkaos/ek/v13/mathutil" - "github.com/essentialkaos/ek/v13/sliceutil" "github.com/essentialkaos/ek/v13/strutil" ) @@ -119,7 +119,7 @@ func (o Options) Has(option Option) bool { return false } - return sliceutil.Contains(o, option) + return slices.Contains(o, option) } // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/support/network/network.go b/support/network/network.go index d862b5b6..636e8bbf 100644 --- a/support/network/network.go +++ b/support/network/network.go @@ -13,9 +13,9 @@ package network import ( "os" + "slices" "github.com/essentialkaos/ek/v13/netutil" - "github.com/essentialkaos/ek/v13/sliceutil" "github.com/essentialkaos/ek/v13/sortutil" "github.com/essentialkaos/ek/v13/support" @@ -33,8 +33,8 @@ func Collect(ipResolverURL ...string) *support.NetworkInfo { sortutil.StringsNatural(info.IPv4) sortutil.StringsNatural(info.IPv6) - info.IPv4 = sliceutil.Deduplicate(info.IPv4) - info.IPv6 = sliceutil.Deduplicate(info.IPv6) + info.IPv4 = slices.Compact(info.IPv4) + info.IPv6 = slices.Compact(info.IPv6) info.Hostname, _ = os.Hostname() From 006ff2a767dd3938e29679dc4260be5c434238fb Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 24 Jul 2024 01:23:04 +0300 Subject: [PATCH 4/7] [terminal/input] Add flag --- CHANGELOG.md | 1 + terminal/input/example_test.go | 1 + terminal/input/input.go | 32 +++++++++++++++++++++++--------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 006a28e7..519e0eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### [13.2.1](https://kaos.sh/ek/13.2.1) +- `[terminal/input]` Added `NewLine` flag - `[sliceutil]` Methods `Copy`, `IsEqual`, `Index`, `Contains`, and `Deduplicate` marked as deprecated - `[terminal/input]` Improved TMUX support diff --git a/terminal/input/example_test.go b/terminal/input/example_test.go index 51caf1ea..3db31def 100644 --- a/terminal/input/example_test.go +++ b/terminal/input/example_test.go @@ -41,6 +41,7 @@ func ExampleReadPassword() { Prompt = "› " MaskSymbol = "•" MaskSymbolColorTag = "{s}" + NewLine = true // User must enter the password password, err := ReadPassword("Please enter password", true) diff --git a/terminal/input/input.go b/terminal/input/input.go index 20335bc6..57b01735 100644 --- a/terminal/input/input.go +++ b/terminal/input/input.go @@ -42,30 +42,33 @@ var ErrKillSignal = linenoise.ErrKillSignal // ////////////////////////////////////////////////////////////////////////////////// // -// Prompt is prompt string +// Prompt is a prompt string var Prompt = "> " -// MaskSymbol is symbol used for masking passwords +// MaskSymbol is a symbol used to maks passwords var MaskSymbol = "*" -// HideLength is flag for hiding password length +// HideLength is a flag to hide the password length var HideLength = false -// HidePassword is flag for hiding password while typing -// Because of using the low-level linenoise method for this feature, we can not use a -// custom masking symbol, so it always will be an asterisk (*). +// HidePassword is a flag to hide the password while typing. +// Because we are using the low-level linenoise method for this feature, we cannot +// use a custom masking symbol, so it will always be an asterisk (*). var HidePassword = false -// MaskSymbolColorTag is fmtc color tag used for MaskSymbol output +// MaskSymbolColorTag is an fmtc color tag used for MaskSymbol output var MaskSymbolColorTag = "" -// TitleColorTag is fmtc color tag used for input titles +// TitleColorTag is an fmtc color tag used for input titles var TitleColorTag = "{s}" // AlwaysYes is a flag, if set ReadAnswer will always return true (useful for working // with option for forced actions) var AlwaysYes = false +// NewLine is a flag for extra new line after inputs +var NewLine = false + // ////////////////////////////////////////////////////////////////////////////////// // var oldTMUXFlag int8 @@ -89,7 +92,13 @@ func ReadAnswer(title string, defaultAnswers ...string) (bool, error) { if title != "" { fmtc.Println(TitleColorTag + getAnswerTitle(title, defaultAnswer) + "{!}") } + fmtc.Println(Prompt + "y") + + if NewLine { + fmtc.NewLine() + } + return true, nil } @@ -112,7 +121,8 @@ func ReadAnswer(title string, defaultAnswers ...string) (bool, error) { case "N": return false, nil default: - terminal.Warn("\nPlease enter Y or N\n") + terminal.Warn("Please enter Y or N") + fmtc.NewLine() } } } @@ -246,6 +256,10 @@ func readUserInput(title string, nonEmpty, private bool) (string, error) { break } + if NewLine { + fmtc.NewLine() + } + return input, err } From 3df776abd78f1c3b94fe7b0cc2a3f443e1dacdd2 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 24 Jul 2024 02:08:37 +0300 Subject: [PATCH 5/7] [terminal/input] Add 'NewLine' flag --- terminal/input/input_windows.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/terminal/input/input_windows.go b/terminal/input/input_windows.go index eceb46d0..02600b1d 100644 --- a/terminal/input/input_windows.go +++ b/terminal/input/input_windows.go @@ -43,6 +43,9 @@ var HidePassword = false // with option for forced actions) var AlwaysYes = false +// ❗ NewLine is a flag for extra new line after inputs +var NewLine = false + // ////////////////////////////////////////////////////////////////////////////////// // // ❗ Read reads user input From e4ac3911af8fac66c6ce7ae37b4c385b9e4079ee Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 24 Jul 2024 11:12:12 +0300 Subject: [PATCH 6/7] [terminal/input] Fix typo --- terminal/input/input.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal/input/input.go b/terminal/input/input.go index 57b01735..55d04d32 100644 --- a/terminal/input/input.go +++ b/terminal/input/input.go @@ -45,7 +45,7 @@ var ErrKillSignal = linenoise.ErrKillSignal // Prompt is a prompt string var Prompt = "> " -// MaskSymbol is a symbol used to maks passwords +// MaskSymbol is a symbol used to mask passwords var MaskSymbol = "*" // HideLength is a flag to hide the password length From 455bbb01557173c0ebe397aae43f5facde91cab9 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 24 Jul 2024 11:20:01 +0300 Subject: [PATCH 7/7] Remove codebeat --- .codebeatsettings | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .codebeatsettings diff --git a/.codebeatsettings b/.codebeatsettings deleted file mode 100644 index e06ac696..00000000 --- a/.codebeatsettings +++ /dev/null @@ -1,11 +0,0 @@ -{ - "GOLANG": { - "ABC": [25, 50, 75, 100], - "CYCLO": [30, 50, 75, 100], - "TOO_MANY_IVARS": [12, 16, 20, 24], - "TOO_MANY_FUNCTIONS": [50, 70, 90, 120], - "LOC": [35, 50, 75, 100], - "TOTAL_COMPLEXITY": [100, 180, 280, 400], - "TOTAL_LOC": [500, 750, 1000, 2000] - } -}