Skip to content

Commit

Permalink
Merge pull request #398 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.83.2
  • Loading branch information
andyone authored Nov 1, 2023
2 parents 4e892dd + e0491e0 commit 9048834
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 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.83.2

* `[fmtutil/panel]` Improved panel rendering with disabled colors
* `[fmtc]` Fixed `IsTag` compatibility with sequence of tags (e.g. `{*}{_}{r}`)
* `[fmtc]` Fixed bug in `Clean` with writing reset escape sequence if there is no reset tag in the given string

### 12.83.1

* `[protip]` Disabling tips using environment variable (`PROTIP=0`)
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.83.1"
const VERSION = "12.83.2"

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

Expand Down
10 changes: 4 additions & 6 deletions fmtc/fmtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ func IsTrueColorSupported() bool {
return colorsTCSupported
}

// IsTag checks if the given value is valid color tag and can be encoded
// to escape sequence
// IsTag tests whether the given value is a valid color tag (or sequence
// of tags) and can be encoded into an escape sequence
func IsTag(tag string) bool {
if tag == "" {
return true // Empty value is valid color tag ¯\_(ツ)_/¯
Expand All @@ -355,9 +355,7 @@ func IsTag(tag string) bool {
return false
}

tag = tag[1 : len(tag)-1]

return isValidTag(tag)
return Clean(tag) == ""
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -542,7 +540,7 @@ func searchColors(text string, limit int, clean bool) string {
}
}

if !closed {
if !closed && !clean {
output.WriteString(_CODE_RESET)
}

Expand Down
1 change: 1 addition & 0 deletions fmtc/fmtc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (s *FormatSuite) TestIsTag(c *C) {
c.Assert(IsTag("{r}"), Equals, true)
c.Assert(IsTag("{r*}"), Equals, true)
c.Assert(IsTag("{#123}"), Equals, true)
c.Assert(IsTag("{*}{_}{#123}"), Equals, true)
c.Assert(IsTag("{%123}"), Equals, true)
c.Assert(IsTag("{*}"), Equals, true)
c.Assert(IsTag("{w-}"), Equals, true)
Expand Down
14 changes: 10 additions & 4 deletions fmtutil/panel/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,24 @@ func renderPanel(label, colorTag, title, message string, options Options) {
fmtc.NewLine()
}

if options.Has(LABEL_POWERLINE) {
fmtc.Printf(colorTag+indent+"{@*} %s {!}"+colorTag+"{!} "+colorTag+"%s{!}", label, title)
labelFormat := "{@*} %s {!}"

if fmtc.DisableColors {
labelFormat = "[%s]"
}

if options.Has(LABEL_POWERLINE) && !fmtc.DisableColors {
fmtc.Printf(colorTag+indent+labelFormat+colorTag+"{!} "+colorTag+"%s{!}", label, title)
} else {
fmtc.Printf(colorTag+indent+"{@*} %s {!} "+colorTag+"%s{!}", label, title)
fmtc.Printf(colorTag+indent+labelFormat+colorTag+" %s{!}", label, title)
}

if !options.Has(TOP_LINE) {
fmtc.NewLine()
} else {
lineSize := width - (strutil.LenVisual(label+title) + 4)

if options.Has(LABEL_POWERLINE) {
if options.Has(LABEL_POWERLINE) && !fmtc.DisableColors {
lineSize--
}

Expand Down
12 changes: 12 additions & 0 deletions fmtutil/panel/panel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package panel
import (
"testing"

"github.com/essentialkaos/ek/v12/fmtc"

. "github.com/essentialkaos/check"
)

Expand Down Expand Up @@ -37,6 +39,16 @@ func (s *PanelSuite) TestBasicInfoPanel(c *C) {
Info("Test info", "Message")
}

func (s *PanelSuite) TestNoColor(c *C) {
fmtc.DisableColors = true
Panel(
"使用上のヒント", "{m}", "Test with no colors",
`Lorem ipsum dolor sit amet.`,
WRAP, INDENT_OUTER, INDENT_INNER, TOP_LINE, BOTTOM_LINE, LABEL_POWERLINE,
)
fmtc.DisableColors = false
}

func (s *PanelSuite) TestPanelAllOptions(c *C) {
Width = 60
Indent = 2
Expand Down

0 comments on commit 9048834

Please sign in to comment.