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] - } -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 0189edd3..519e0eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## Changelog +### [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 + + ### [13.2.0](https://kaos.sh/ek/13.2.0) - `[errutil]` Added method `Wrap` 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/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/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() 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 c13916aa..55d04d32 100644 --- a/terminal/input/input.go +++ b/terminal/input/input.go @@ -42,33 +42,36 @@ 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 mask 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 tmux int8 +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() } } } @@ -167,7 +177,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) @@ -245,18 +256,28 @@ func readUserInput(title string, nonEmpty, private bool) (string, error) { break } + if NewLine { + fmtc.NewLine() + } + 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 } 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 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"