mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-27 13:57:46 +00:00
@@ -109,6 +109,8 @@ type Progress interface {
|
|||||||
Printf(msg string, a ...interface{})
|
Printf(msg string, a ...interface{})
|
||||||
// ColoredPrintf does printf in colored way + newline
|
// ColoredPrintf does printf in colored way + newline
|
||||||
ColoredPrintf(msg string, a ...interface{})
|
ColoredPrintf(msg string, a ...interface{})
|
||||||
|
// PrintfStdErr does printf but in safe manner to stderr
|
||||||
|
PrintfStdErr(msg string, a ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloader is parallel HTTP fetcher
|
// Downloader is parallel HTTP fetcher
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package console
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/cheggaaa/pb"
|
"github.com/cheggaaa/pb"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
codePrint = iota
|
codePrint = iota
|
||||||
|
codePrintStdErr
|
||||||
codeProgress
|
codeProgress
|
||||||
codeHideProgress
|
codeHideProgress
|
||||||
codeStop
|
codeStop
|
||||||
@@ -127,6 +129,11 @@ func (p *Progress) Printf(msg string, a ...interface{}) {
|
|||||||
p.queue <- printTask{code: codePrint, message: fmt.Sprintf(msg, a...)}
|
p.queue <- printTask{code: codePrint, message: fmt.Sprintf(msg, a...)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrintfStdErr does printf but in safe manner to stderr
|
||||||
|
func (p *Progress) PrintfStdErr(msg string, a ...interface{}) {
|
||||||
|
p.queue <- printTask{code: codePrintStdErr, message: fmt.Sprintf(msg, a...)}
|
||||||
|
}
|
||||||
|
|
||||||
// ColoredPrintf does printf in colored way + newline
|
// ColoredPrintf does printf in colored way + newline
|
||||||
func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
|
func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
|
||||||
if RunningOnTerminal() {
|
if RunningOnTerminal() {
|
||||||
@@ -182,6 +189,12 @@ func (p *Progress) worker() {
|
|||||||
p.barShown = false
|
p.barShown = false
|
||||||
}
|
}
|
||||||
fmt.Print(task.message)
|
fmt.Print(task.message)
|
||||||
|
case codePrintStdErr:
|
||||||
|
if p.barShown {
|
||||||
|
fmt.Print("\r\033[2K")
|
||||||
|
p.barShown = false
|
||||||
|
}
|
||||||
|
fmt.Fprint(os.Stderr, task.message)
|
||||||
case codeProgress:
|
case codeProgress:
|
||||||
if hasBar {
|
if hasBar {
|
||||||
fmt.Print("\r" + task.message)
|
fmt.Print("\r" + task.message)
|
||||||
|
|||||||
+1
-1
@@ -262,7 +262,7 @@ func (context *AptlyContext) _database() (database.Storage, error) {
|
|||||||
delay = time.Second
|
delay = time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
context._progress().Printf("Unable to open database, sleeping %s, attempts left %d...\n", delay, tries)
|
context._progress().PrintfStdErr("Unable to open database, sleeping %s, attempts left %d...\n", delay, tries)
|
||||||
time.Sleep(delay)
|
time.Sleep(delay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user