diff --git a/CHANGELOG.md b/CHANGELOG.md index 139a9ae3..9fd17678 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/ek.go b/ek.go index 0cef8289..6f94e1e2 100644 --- a/ek.go +++ b/ek.go @@ -20,7 +20,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "12.78.0" +const VERSION = "12.79.0" // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/fmtutil/panel/panel.go b/fmtutil/panel/panel.go index 48257233..2e4f72d5 100644 --- a/fmtutil/panel/panel.go +++ b/fmtutil/panel/panel.go @@ -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 @@ -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) @@ -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) {