mirror of
https://github.com/openziti/zrok.git
synced 2025-06-25 12:12:32 +02:00
commit
395b522c3d
@ -2,16 +2,20 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/muesli/reflow/wordwrap"
|
"github.com/muesli/reflow/wordwrap"
|
||||||
"github.com/openziti/zrok/endpoints"
|
"github.com/openziti/zrok/endpoints"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const shareTuiBacklog = 256
|
const shareTuiBacklog = 256
|
||||||
|
|
||||||
|
var wordwrapCharacters = " -"
|
||||||
|
var wordwrapBreakpoints = map[rune]bool{' ': true, '-': true}
|
||||||
|
|
||||||
type shareModel struct {
|
type shareModel struct {
|
||||||
shrToken string
|
shrToken string
|
||||||
frontendDescriptions []string
|
frontendDescriptions []string
|
||||||
@ -144,6 +148,7 @@ func (m *shareModel) renderRequests() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
requestLines = wrap(requestLines, m.width-2)
|
||||||
maxRows := shareRequestsStyle.GetHeight()
|
maxRows := shareRequestsStyle.GetHeight()
|
||||||
startRow := 0
|
startRow := 0
|
||||||
if len(requestLines) > maxRows {
|
if len(requestLines) > maxRows {
|
||||||
@ -183,6 +188,7 @@ func (m *shareModel) renderLog() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
splitLines = wrap(splitLines, m.width-2)
|
||||||
maxRows := shareLogStyle.GetHeight()
|
maxRows := shareLogStyle.GetHeight()
|
||||||
startRow := 0
|
startRow := 0
|
||||||
if len(splitLines) > maxRows {
|
if len(splitLines) > maxRows {
|
||||||
@ -211,6 +217,38 @@ func (m *shareModel) Write(p []byte) (n int, err error) {
|
|||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wrap(lines []string, width int) []string {
|
||||||
|
ret := make([]string, 0)
|
||||||
|
for _, line := range lines {
|
||||||
|
if width <= 0 || len(line) <= width {
|
||||||
|
ret = append(ret, line)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for i := 0; i <= len(line); {
|
||||||
|
max := i + width
|
||||||
|
if max > len(line) {
|
||||||
|
max = len(line)
|
||||||
|
}
|
||||||
|
if line[i:max] == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
nextI := i + width
|
||||||
|
if max < len(line)-1 {
|
||||||
|
if !wordwrapBreakpoints[rune(line[max])] || !wordwrapBreakpoints[rune(line[max+1])] {
|
||||||
|
lastSpace := strings.LastIndexAny(line[:max], wordwrapCharacters)
|
||||||
|
if lastSpace > -1 {
|
||||||
|
max = lastSpace
|
||||||
|
nextI = lastSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = append(ret, strings.TrimSpace(line[i:max]))
|
||||||
|
i = nextI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
var shareHeaderStyle = lipgloss.NewStyle().
|
var shareHeaderStyle = lipgloss.NewStyle().
|
||||||
BorderStyle(lipgloss.RoundedBorder()).
|
BorderStyle(lipgloss.RoundedBorder()).
|
||||||
BorderForeground(lipgloss.Color("63")).
|
BorderForeground(lipgloss.Color("63")).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user