| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | package restore | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/restic/restic/internal/ui" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type textPrinter struct { | 
					
						
							|  |  |  | 	terminal term | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 12:01:03 +02:00
										 |  |  | func NewTextProgress(terminal term) ProgressPrinter { | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 	return &textPrinter{ | 
					
						
							|  |  |  | 		terminal: terminal, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | func (t *textPrinter) Update(p State, duration time.Duration) { | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 	timeLeft := ui.FormatDuration(duration) | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | 	formattedAllBytesWritten := ui.FormatBytes(p.AllBytesWritten) | 
					
						
							|  |  |  | 	formattedAllBytesTotal := ui.FormatBytes(p.AllBytesTotal) | 
					
						
							|  |  |  | 	allPercent := ui.FormatPercent(p.AllBytesWritten, p.AllBytesTotal) | 
					
						
							| 
									
										
										
										
											2023-09-20 10:58:11 +02:00
										 |  |  | 	progress := fmt.Sprintf("[%s] %s  %v files/dirs %s, total %v files/dirs %v", | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | 		timeLeft, allPercent, p.FilesFinished, formattedAllBytesWritten, p.FilesTotal, formattedAllBytesTotal) | 
					
						
							| 
									
										
										
										
											2024-05-31 14:12:06 +02:00
										 |  |  | 	if p.FilesSkipped > 0 { | 
					
						
							|  |  |  | 		progress += fmt.Sprintf(", skipped %v files/dirs %v", p.FilesSkipped, ui.FormatBytes(p.AllBytesSkipped)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	t.terminal.SetStatus([]string{progress}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | func (t *textPrinter) Finish(p State, duration time.Duration) { | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 	t.terminal.SetStatus([]string{}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	timeLeft := ui.FormatDuration(duration) | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | 	formattedAllBytesTotal := ui.FormatBytes(p.AllBytesTotal) | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var summary string | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | 	if p.FilesFinished == p.FilesTotal && p.AllBytesWritten == p.AllBytesTotal { | 
					
						
							|  |  |  | 		summary = fmt.Sprintf("Summary: Restored %d files/dirs (%s) in %s", p.FilesTotal, formattedAllBytesTotal, timeLeft) | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | 		formattedAllBytesWritten := ui.FormatBytes(p.AllBytesWritten) | 
					
						
							| 
									
										
										
										
											2023-09-20 10:58:11 +02:00
										 |  |  | 		summary = fmt.Sprintf("Summary: Restored %d / %d files/dirs (%s / %s) in %s", | 
					
						
							| 
									
										
										
										
											2024-05-31 13:43:57 +02:00
										 |  |  | 			p.FilesFinished, p.FilesTotal, formattedAllBytesWritten, formattedAllBytesTotal, timeLeft) | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-05-31 14:12:06 +02:00
										 |  |  | 	if p.FilesSkipped > 0 { | 
					
						
							|  |  |  | 		summary += fmt.Sprintf(", skipped %v files/dirs %v", p.FilesSkipped, ui.FormatBytes(p.AllBytesSkipped)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-05-01 11:19:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	t.terminal.Print(summary) | 
					
						
							|  |  |  | } |