Use colors.
This commit is contained in:
parent
ae5736f21b
commit
054906472f
1 changed files with 13 additions and 10 deletions
|
@ -33,7 +33,7 @@ func NewRuspa(inode *INode, collect chan StatusReport) *Ruspa {
|
|||
|
||||
// Scava starts a worker on the given INode.
|
||||
func (w *Ruspa) Scava(done chan StatusReport) {
|
||||
Console.Debugln("Scava: ", w.INode.Path)
|
||||
Console.Debugln(Gray("Scava: ", w.INode.Path))
|
||||
children, err := ls(w.INode.Path)
|
||||
if err != nil {
|
||||
w.Send <- StatusReport{path: w.INode.Path, err: err}
|
||||
|
@ -47,10 +47,10 @@ func (w *Ruspa) Scava(done chan StatusReport) {
|
|||
w.INode.Children.Append(childINode)
|
||||
switch {
|
||||
case kind == FileType:
|
||||
Console.Debugln("[file]", w.INode.Path, " ~> ", childINode.Path)
|
||||
Console.Debugln(Gray("[file]", w.INode.Path, " ~> ", childINode.Path))
|
||||
w.Send <- StatusReport{path: childPath, size: size}
|
||||
case kind == DirType:
|
||||
Console.Debugln("[dir]", w.INode.Path, " ~> ", childINode.Path)
|
||||
Console.Debugln(Gray("[dir]", w.INode.Path, " ~> ", childINode.Path))
|
||||
cw := NewRuspa(childINode, w.Recv)
|
||||
w.Opened[childPath] = cw
|
||||
go cw.Scava(w.Done)
|
||||
|
@ -71,17 +71,17 @@ func (w *Ruspa) Ammucchia(done chan StatusReport) {
|
|||
select {
|
||||
case report := <-w.Recv:
|
||||
if report.err != nil {
|
||||
Console.Debugln(Red(report.err))
|
||||
Console.Debugln(Gray(Red(report.err)))
|
||||
}
|
||||
if report.err == nil {
|
||||
w.INode.Size += report.size
|
||||
}
|
||||
case leaf := <-w.Done:
|
||||
Console.Debugln("Done:", leaf.path)
|
||||
Console.Debugln(Gray("Done:", leaf.path))
|
||||
delete(w.Opened, leaf.path)
|
||||
}
|
||||
}
|
||||
Console.Debugln(w.INode.Path, ": Completed. Exiting...")
|
||||
Console.Debugln(Gray(w.INode.Path, ": Completed. Exiting..."))
|
||||
done <- StatusReport{path: w.INode.Path, size: w.INode.Size}
|
||||
}
|
||||
|
||||
|
@ -98,22 +98,25 @@ func (i *INode) Pesa(done chan StatusReport) chan StatusReport {
|
|||
// NastroConvogliatore starts a Pesa on a given path and displays
|
||||
// the current value of the size.
|
||||
func NastroConvogliatore(path string) {
|
||||
var size int64
|
||||
pathINode, err := INodeFromPath(path)
|
||||
if err != nil {
|
||||
Console.Fatalln("Failed creating inode:", err)
|
||||
}
|
||||
Console.Debugln("Starting Pesa on path:", path)
|
||||
Console.Debugln(Gray("Starting Pesa on path:", path))
|
||||
done := make(chan StatusReport)
|
||||
result := pathINode.Pesa(done)
|
||||
writer := uilive.New()
|
||||
writer.Start()
|
||||
fmt.Fprintf(writer, "%s\n", Green("Starting..."))
|
||||
size = 0
|
||||
for {
|
||||
select {
|
||||
case res := <-result:
|
||||
fmt.Fprintf(writer, "%s: %d\n", res.path, res.size)
|
||||
case res := <-done:
|
||||
fmt.Fprintf(writer, "%s: %d\n", res.path, res.size)
|
||||
size += res.size
|
||||
fmt.Fprintf(writer, "%s: %d\n%s: %d\n", res.path, res.size, path, size)
|
||||
case <-done:
|
||||
fmt.Fprintf(writer, "%s: %d\n", path, pathINode.Size)
|
||||
writer.Stop()
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue