setup output
This commit is contained in:
40
deploy.go
40
deploy.go
@@ -21,6 +21,10 @@ const (
|
|||||||
defaultServiceDirTemplate = "/root/pb/{service}"
|
defaultServiceDirTemplate = "/root/pb/{service}"
|
||||||
defaultEnvFileTemplate = "/root/pb/{service}/.env"
|
defaultEnvFileTemplate = "/root/pb/{service}/.env"
|
||||||
totalSetupSteps = 5
|
totalSetupSteps = 5
|
||||||
|
remoteWindowSize = 10
|
||||||
|
remoteIndent = " "
|
||||||
|
remoteLineColor = "\033[96m"
|
||||||
|
remoteColorReset = "\033[0m"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pbToml struct {
|
type pbToml struct {
|
||||||
@@ -490,6 +494,7 @@ func filterEnvStream(r io.Reader, w io.Writer) error {
|
|||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
scanner.Buffer(make([]byte, 0, 64*1024), 2*1024*1024)
|
scanner.Buffer(make([]byte, 0, 64*1024), 2*1024*1024)
|
||||||
skipping := true
|
skipping := true
|
||||||
|
window := newRemoteWindow(w)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
if skipping && isEnvLine(line) {
|
if skipping && isEnvLine(line) {
|
||||||
@@ -498,7 +503,7 @@ func filterEnvStream(r io.Reader, w io.Writer) error {
|
|||||||
if skipping {
|
if skipping {
|
||||||
skipping = false
|
skipping = false
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintln(w, line); err != nil {
|
if err := window.add(line); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -508,6 +513,39 @@ func filterEnvStream(r io.Reader, w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type remoteWindow struct {
|
||||||
|
w io.Writer
|
||||||
|
lines []string
|
||||||
|
prevCount int
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRemoteWindow(w io.Writer) *remoteWindow {
|
||||||
|
return &remoteWindow{w: w}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rw *remoteWindow) add(line string) error {
|
||||||
|
rw.lines = append(rw.lines, line)
|
||||||
|
if len(rw.lines) > remoteWindowSize {
|
||||||
|
rw.lines = rw.lines[1:]
|
||||||
|
}
|
||||||
|
return rw.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rw *remoteWindow) flush() error {
|
||||||
|
if rw.prevCount > 0 {
|
||||||
|
if _, err := fmt.Fprintf(rw.w, "\033[%dA", rw.prevCount); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, line := range rw.lines {
|
||||||
|
if _, err := fmt.Fprintf(rw.w, "\033[2K\r%s%s%s%s\n", remoteLineColor, remoteIndent, line, remoteColorReset); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rw.prevCount = len(rw.lines)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func stripLeadingEnvLines(input string) string {
|
func stripLeadingEnvLines(input string) string {
|
||||||
scanner := bufio.NewScanner(strings.NewReader(input))
|
scanner := bufio.NewScanner(strings.NewReader(input))
|
||||||
scanner.Buffer(make([]byte, 0, 64*1024), 2*1024*1024)
|
scanner.Buffer(make([]byte, 0, 64*1024), 2*1024*1024)
|
||||||
|
|||||||
Reference in New Issue
Block a user