mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-08 23:39:04 +01:00
fix some status display alignment
This commit is contained in:
parent
acd2a68cfb
commit
48feaff054
@ -199,6 +199,9 @@ func times(str string, n int) (out string) {
|
||||
}
|
||||
|
||||
func rightPad(str string, length int, pad string) string {
|
||||
if len(str) > length {
|
||||
return str[:length]
|
||||
}
|
||||
return str + times(pad, length-len(str))
|
||||
}
|
||||
|
||||
@ -211,6 +214,9 @@ func (t *tui) drawBar(name string, status string, bytes int64, totalBytes int64)
|
||||
if totalBytes > 0 {
|
||||
length := 50
|
||||
completedLength := int(int64(length) * bytes / totalBytes)
|
||||
if completedLength > length {
|
||||
completedLength = length
|
||||
}
|
||||
|
||||
t.write("[")
|
||||
t.write(times("=", completedLength))
|
||||
@ -219,12 +225,25 @@ func (t *tui) drawBar(name string, status string, bytes int64, totalBytes int64)
|
||||
t.write("]")
|
||||
|
||||
t.write(" ")
|
||||
t.write(rightPad(ByteCountBinary(bytes) + "/" + ByteCountBinary(bytes), 16, " "))
|
||||
t.write(rightPad(ByteCountBinary(bytes) + "/" + ByteCountBinary(totalBytes), 20, " "))
|
||||
}
|
||||
|
||||
t.newline()
|
||||
}
|
||||
|
||||
func StringStepState(s fsrep.StepState) string {
|
||||
switch s {
|
||||
case fsrep.StepReplicationReady: return "Ready"
|
||||
case fsrep.StepReplicationRetry: return "Retry"
|
||||
case fsrep.StepMarkReplicatedReady: return "MarkReady"
|
||||
case fsrep.StepMarkReplicatedRetry: return "MarkRetry"
|
||||
case fsrep.StepPermanentError: return "PermanentError"
|
||||
case fsrep.StepCompleted: return "Completed"
|
||||
default:
|
||||
return fmt.Sprintf("UNKNOWN %d", s)
|
||||
}
|
||||
}
|
||||
|
||||
func printFilesystem(rep *fsrep.Report, t *tui, versions bool) {
|
||||
bytes := int64(0)
|
||||
totalBytes := int64(0)
|
||||
@ -246,7 +265,7 @@ func printFilesystem(rep *fsrep.Report, t *tui, versions bool) {
|
||||
}
|
||||
if versions && len(rep.Pending) > 0 {
|
||||
v := rep.Pending[0]
|
||||
t.drawBar(" " + v.To, v.Status, v.Bytes, v.ExpectedBytes)
|
||||
t.drawBar(" " + v.To, StringStepState(v.Status), v.Bytes, v.ExpectedBytes)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ type Receiver interface {
|
||||
|
||||
type StepReport struct {
|
||||
From, To string
|
||||
Status string
|
||||
Status StepState
|
||||
Problem string
|
||||
Bytes int64
|
||||
ExpectedBytes int64
|
||||
@ -498,7 +498,7 @@ func (s *ReplicationStep) Report() *StepReport {
|
||||
rep := StepReport{
|
||||
From: from,
|
||||
To: s.to.RelName(),
|
||||
Status: s.state.String(),
|
||||
Status: s.state,
|
||||
Bytes: bytes,
|
||||
ExpectedBytes: s.expectedSize,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user