Skip to content

Commit

Permalink
[terminal] Improve panel rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Jul 17, 2023
1 parent d5f6d41 commit e535779
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

### 12.71.0

* `[terminal]` Added panel size configuration feature
* `[terminal]` Improved panel rendering for messages with newlines

### 12.70.0

* `[terminal]` Added flag `HidePassword` for masking passwords while typing
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.70.0"
const VERSION = "12.71.0"

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

Expand Down
21 changes: 17 additions & 4 deletions terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package terminal
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"bytes"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -74,6 +75,9 @@ var (
InfoPrefix = ""
)

// PanelWidth is panel width (≥ 40)
var PanelWidth = 88

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

var tmux int8
Expand Down Expand Up @@ -196,10 +200,19 @@ func InfoPanel(title, message string) {
func Panel(label, colorTag, title, message string) {
fmtc.Printf(colorTag+"{@*} %s {!} "+colorTag+"%s{!}\n", label, title)

fmtc.Print(fmtutil.Wrap(
fmtc.Sprint(message),
fmtc.Sprint(colorTag+"┃{!} "), 88,
) + "\n")
buf := bytes.NewBufferString(
fmtutil.Wrap(fmtc.Sprint(message), "", mathutil.Max(38, PanelWidth-2)) + "\n",
)

for {
line, err := buf.ReadString('\n')

if err != nil {
break
}

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

// AddHistory adds line to input history
Expand Down

0 comments on commit e535779

Please sign in to comment.