Skip to content

Commit

Permalink
Merge pull request #490 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 13.2.1
  • Loading branch information
andyone authored Jul 24, 2024
2 parents fc5a6d0 + 455bbb0 commit ca3e455
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 34 deletions.
11 changes: 0 additions & 11 deletions .codebeatsettings

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 2 additions & 2 deletions fmtutil/panel/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -119,7 +119,7 @@ func (o Options) Has(option Option) bool {
return false
}

return sliceutil.Contains(o, option)
return slices.Contains(o, option)
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
10 changes: 10 additions & 0 deletions sliceutil/sliceutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions support/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand Down
1 change: 1 addition & 0 deletions terminal/input/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func ExampleReadPassword() {
Prompt = "› "
MaskSymbol = "•"
MaskSymbolColorTag = "{s}"
NewLine = true

// User must enter the password
password, err := ReadPassword("Please enter password", true)
Expand Down
55 changes: 38 additions & 17 deletions terminal/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

// ////////////////////////////////////////////////////////////////////////////////// //

Expand All @@ -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
}

Expand All @@ -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()
}
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions terminal/input/input_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ package ek
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "13.2.0"
const VERSION = "13.2.1"

0 comments on commit ca3e455

Please sign in to comment.