Skip to content

Commit

Permalink
[panel] Add indent customization
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 1, 2023
1 parent c712b4a commit 2989036
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 12.79.0

* `[panel]` Added indent customization

### 12.78.0

* `[barcode]` New package with methods to generate colored representation of unique data
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.78.0"
const VERSION = "12.79.0"

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

Expand Down
19 changes: 12 additions & 7 deletions fmtutil/panel/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var (
// Width is panel width (≥ 40) if option WRAP is set
var Width = 88

// Indent is indent from the left side of terminal
var Indent = 0

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

// minWidth is minimal panel width
Expand All @@ -83,24 +86,26 @@ func Info(title, message string, options ...Option) {
func Panel(label, colorTag, title, message string, options ...Option) {
var buf *bytes.Buffer

indent := strings.Repeat(" ", mathutil.Max(0, Indent))

if sliceutil.Contains(options, INDENT_OUTER) {
fmtc.NewLine()
}

if sliceutil.Contains(options, LABEL_POWERLINE) {
fmtc.Printf(colorTag+"{@*} %s {!}"+colorTag+"{!} "+colorTag+"%s{!}\n", label, title)
fmtc.Printf(colorTag+indent+"{@*} %s {!}"+colorTag+"{!} "+colorTag+"%s{!}\n", label, title)
} else {
fmtc.Printf(colorTag+"{@*} %s {!} "+colorTag+"%s{!}\n", label, title)
fmtc.Printf(colorTag+indent+"{@*} %s {!} "+colorTag+"%s{!}\n", label, title)
}

if sliceutil.Contains(options, INDENT_INNER) {
fmtc.Println(colorTag + "┃{!}")
fmtc.Println(colorTag + indent + "┃{!}")
}

switch {
case sliceutil.Contains(options, WRAP):
buf = bytes.NewBufferString(
fmtutil.Wrap(fmtc.Sprint(message), "", mathutil.Max(minWidth, Width-2)) + "\n",
fmtutil.Wrap(fmtc.Sprint(message), indent, mathutil.Max(minWidth, Width-2)) + "\n",
)
default:
buf = bytes.NewBufferString(message)
Expand All @@ -114,15 +119,15 @@ func Panel(label, colorTag, title, message string, options ...Option) {
break
}

fmtc.Print(colorTag + "┃{!} " + line)
fmtc.Print(colorTag + indent + "┃{!} " + line)
}

if sliceutil.Contains(options, INDENT_INNER) {
fmtc.Println(colorTag + "┃{!}")
fmtc.Println(colorTag + indent + "┃{!}")
}

if sliceutil.Contains(options, BOTTOM_LINE) {
fmtc.Println(colorTag + "┖" + strings.Repeat("─", mathutil.Max(minWidth, Width-1)))
fmtc.Println(colorTag + indent + "┖" + strings.Repeat("─", mathutil.Max(minWidth, Width-1)))
}

if sliceutil.Contains(options, INDENT_OUTER) {
Expand Down

0 comments on commit 2989036

Please sign in to comment.