Skip to content

Commit

Permalink
Merge pull request #393 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.80.0
  • Loading branch information
andyone authored Oct 12, 2023
2 parents 8c351ba + 3154691 commit db9ac45
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog

### 12.80.0

* `[system]` Added ANSI color info to `OSInfo`
* `[system]` Added methods `OSInfo.ColoredPrettyName` and `OSInfo.ColoredName`
* `[strutil]` Improved usage examples

### 12.79.0

* `[panel]` Added indent customization
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.79.0"
const VERSION = "12.80.0"

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

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.18
require (
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/go-linenoise/v3 v3.4.0
golang.org/x/crypto v0.13.0
golang.org/x/sys v0.12.0
golang.org/x/crypto v0.14.0
golang.org/x/sys v0.13.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2 changes: 2 additions & 0 deletions strutil/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ func ExampleExclude() {

func ExampleLen() {
fmt.Println(Len("Пример 例子 例 მაგალითად"))
fmt.Println(Len("😚😘🥰"))

// Output:
// 21
// 3
}

func ExampleHead() {
Expand Down
27 changes: 27 additions & 0 deletions system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"bufio"
"os"
"strconv"
"strings"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -149,13 +150,34 @@ type OSInfo struct {
BugReportURL string `json:"bugreport_url"`
DocumentationURL string `json:"documentation_url"`
Logo string `json:"logo"`
ANSIColor string `json:"ansi_color"`
SupportURL string `json:"support_url"`
SupportProduct string `json:"support_product"`
SupportProductVersion string `json:"support_product_version"`
}

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

// ColoredPrettyName returns pretty name with applied color
func (i *OSInfo) ColoredPrettyName() string {
if !isValidANSIColor(i.ANSIColor) {
return i.PrettyName
}

return "\033[" + i.ANSIColor + "m" + i.PrettyName + "\033[0m"
}

// ColoredName returns name with applied color
func (i *OSInfo) ColoredName() string {
if !isValidANSIColor(i.ANSIColor) {
return i.Name
}

return "\033[" + i.ANSIColor + "m" + i.Name + "\033[0m"
}

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

// getFileScanner opens file and creates scanner for reading text files line by line
func getFileScanner(file string) (*bufio.Scanner, func() error, error) {
fd, err := os.OpenFile(file, os.O_RDONLY, 0)
Expand All @@ -180,3 +202,8 @@ func parseSize(v string) (uint64, error) {

return size * 1024, nil
}

// isValidANSIColor validates ansi color code
func isValidANSIColor(color string) bool {
return color != "" && strings.Trim(color, "0123456789;") == ""
}
2 changes: 2 additions & 0 deletions system/info_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func applyOSInfo(info *OSInfo, name, value string) {
info.DocumentationURL = value
case "LOGO":
info.Logo = value
case "ANSI_COLOR":
info.ANSIColor = value
}

switch {
Expand Down
8 changes: 8 additions & 0 deletions system/info_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=groovy
ANSI_COLOR="0;34"
VARIANT="Server"
VARIANT_ID="server"
PLATFORM_ID="platform:el8"
Expand Down Expand Up @@ -668,6 +669,13 @@ REDHAT_SUPPORT_PRODUCT_VERSION="7"
c.Assert(osInfo.Logo, Equals, "fedora-logo-icon")
c.Assert(osInfo.SupportProduct, Equals, "centos")
c.Assert(osInfo.SupportProductVersion, Equals, "7")
c.Assert(osInfo.ANSIColor, Equals, "0;34")

c.Assert(osInfo.ColoredPrettyName(), Equals, "\x1b[0;34mUbuntu 20.10\x1b[0m")
c.Assert(osInfo.ColoredName(), Equals, "\x1b[0;34mUbuntu\x1b[0m")
osInfo.ANSIColor = "ABCD"
c.Assert(osInfo.ColoredPrettyName(), Equals, "Ubuntu 20.10")
c.Assert(osInfo.ColoredName(), Equals, "Ubuntu")

c.Assert(getArchName("i386"), Equals, "386")
c.Assert(getArchName("i586"), Equals, "586")
Expand Down

0 comments on commit db9ac45

Please sign in to comment.