Make sure to colorize diff types properly, also handle proper newlines
This commit is contained in:
+15
-1
@@ -194,6 +194,11 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
|
||||
totalBytes += cpURLs.SourceContent.Size
|
||||
totalObjects++
|
||||
case <-trapCh:
|
||||
// Print in new line and adjust to top so that we don't print over the ongoing scan bar
|
||||
if !globalQuietFlag && !globalJSONFlag {
|
||||
console.Printf("%c[2K\n", 27)
|
||||
console.Printf("%c[A", 27)
|
||||
}
|
||||
session.Close() // If we are interrupted during the URL scanning, we drop the session.
|
||||
session.Delete()
|
||||
os.Exit(0)
|
||||
@@ -247,10 +252,19 @@ func doCopyCmdSession(session *sessionV2) {
|
||||
if cpURLs.Error == nil {
|
||||
session.Header.LastCopied = cpURLs.SourceContent.Name
|
||||
} else {
|
||||
console.Println()
|
||||
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
|
||||
if !globalQuietFlag && !globalJSONFlag {
|
||||
console.Printf("%c[2K\n", 27)
|
||||
console.Printf("%c[A", 27)
|
||||
}
|
||||
errorIf(cpURLs.Error.Trace(), fmt.Sprintf("Failed to copy ‘%s’.", cpURLs.SourceContent.Name))
|
||||
}
|
||||
case <-trapCh: // Receive interrupt notification.
|
||||
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
|
||||
if !globalQuietFlag && !globalJSONFlag {
|
||||
console.Printf("%c[2K\n", 27)
|
||||
console.Printf("%c[A", 27)
|
||||
}
|
||||
session.Close()
|
||||
session.Info()
|
||||
os.Exit(0)
|
||||
|
||||
+4
-1
@@ -59,7 +59,10 @@ func mainDiff(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
"Diff": color.New(color.FgGreen, color.Bold),
|
||||
"DiffMessage": color.New(color.FgGreen, color.Bold),
|
||||
"DiffOnlyInFirst": color.New(color.FgRed, color.Bold),
|
||||
"DiffType": color.New(color.FgYellow, color.Bold),
|
||||
"DiffSize": color.New(color.FgMagenta, color.Bold),
|
||||
})
|
||||
|
||||
config := mustGetMcConfig()
|
||||
|
||||
@@ -58,15 +58,15 @@ func (d DiffMessage) String() string {
|
||||
msg := ""
|
||||
switch d.Diff {
|
||||
case "only-in-first":
|
||||
msg = "‘" + d.FirstURL + "’" + " and " + "‘" + d.SecondURL + "’" + " - only in first."
|
||||
msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffOnlyInFirst", " - only in first.")
|
||||
case "type":
|
||||
msg = "‘" + d.FirstURL + "’" + " and " + "‘" + d.SecondURL + "’" + " - differ in type."
|
||||
msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffType", " - differ in type.")
|
||||
case "size":
|
||||
msg = "‘" + d.FirstURL + "’" + " and " + "‘" + d.SecondURL + "’" + " - differ in size."
|
||||
msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffSize", " - differ in size.")
|
||||
default:
|
||||
fatalIf(errDummy.Trace(), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.")
|
||||
}
|
||||
return console.Colorize("Diff", msg)
|
||||
return msg
|
||||
}
|
||||
diffJSONBytes, err := json.Marshal(d)
|
||||
fatalIf(probe.NewError(err), "Unable to marshal diff message ‘"+d.FirstURL+"’, ‘"+d.SecondURL+"’ and ‘"+d.Diff+"’.")
|
||||
@@ -299,7 +299,8 @@ func dodiffRecursive(firstClnt, secondClnt client.Client, ch chan DiffMessage) {
|
||||
wg.Wait()
|
||||
doneCh <- struct{}{}
|
||||
if !globalQuietFlag && !globalJSONFlag {
|
||||
console.PrintC("\r" + "Finished." + "\n")
|
||||
console.Printf("%c[2K\n", 27)
|
||||
console.Printf("%c[A", 27)
|
||||
}
|
||||
|
||||
matchNameCh := make(chan string, 10000)
|
||||
|
||||
@@ -175,6 +175,11 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
|
||||
totalBytes += sURLs.SourceContent.Size
|
||||
totalObjects++
|
||||
case <-trapCh:
|
||||
// Print in new line and adjust to top so that we don't print over the ongoing scan bar
|
||||
if !globalQuietFlag && !globalJSONFlag {
|
||||
console.Printf("%c[2K\n", 27)
|
||||
console.Printf("%c[A", 27)
|
||||
}
|
||||
session.Close() // If we are interrupted during the URL scanning, we drop the session.
|
||||
session.Delete()
|
||||
os.Exit(0)
|
||||
@@ -228,9 +233,19 @@ func doMirrorCmdSession(session *sessionV2) {
|
||||
if sURLs.Error == nil {
|
||||
session.Header.LastCopied = sURLs.SourceContent.Name
|
||||
} else {
|
||||
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
|
||||
if !globalQuietFlag && !globalJSONFlag {
|
||||
console.Printf("%c[2K\n", 27)
|
||||
console.Printf("%c[A", 27)
|
||||
}
|
||||
errorIf(sURLs.Error.Trace(), "Failed to mirror.")
|
||||
}
|
||||
case <-trapCh: // Receive interrupt notification.
|
||||
// Print in new line and adjust to top so that we don't print over the ongoing progress bar
|
||||
if !globalQuietFlag && !globalJSONFlag {
|
||||
console.Printf("%c[2K\n", 27)
|
||||
console.Printf("%c[A", 27)
|
||||
}
|
||||
session.Close()
|
||||
session.Info()
|
||||
os.Exit(0)
|
||||
|
||||
Reference in New Issue
Block a user