Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: aaaf884c9a27
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 870d85080a70
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 24, 2015

  1. Clear progress bar on ipfs cat exit

    License: MIT
    Signed-off-by: rht <rhtbot@gmail.com>
    rht committed Jul 24, 2015
    Copy the full SHA
    818d3af View commit details

Commits on Jul 28, 2015

  1. Merge pull request #1516 from rht/progressbar

    Clear progress bar on `ipfs cat` exit
    jbenet committed Jul 28, 2015
    Copy the full SHA
    870d850 View commit details
Showing with 16 additions and 3 deletions.
  1. +1 −2 core/commands/add.go
  2. +15 −1 core/commands/cat.go
3 changes: 1 addition & 2 deletions core/commands/add.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"fmt"
"io"
"path"
"strings"

"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/cheggaaa/pb"

@@ -208,7 +207,7 @@ remains to be implemented.
if len(output.Hash) > 0 {
if showProgressBar {
// clear progress bar line before we print "added x" output
fmt.Fprintf(res.Stderr(), "\r%s\r", strings.Repeat(" ", terminalWidth))
fmt.Fprintf(res.Stderr(), "\033[2K\r")
}
if quiet {
fmt.Fprintf(res.Stdout(), "%s\n", output.Hash)
16 changes: 15 additions & 1 deletion core/commands/cat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"fmt"
"io"

cmds "github.com/ipfs/go-ipfs/commands"
@@ -14,6 +15,11 @@ import (

const progressBarMinSize = 1024 * 1024 * 8 // show progress bar for outputs > 8MiB

type clearlineReader struct {
io.Reader
out io.Writer
}

var CatCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Show IPFS object data",
@@ -54,7 +60,7 @@ it contains.
bar.Start()

reader := bar.NewProxyReader(res.Output().(io.Reader))
res.SetOutput(reader)
res.SetOutput(&clearlineReader{reader, res.Stderr()})
},
}

@@ -76,3 +82,11 @@ func cat(ctx context.Context, node *core.IpfsNode, paths []string) ([]io.Reader,
}
return readers, length, nil
}

func (r *clearlineReader) Read(p []byte) (n int, err error) {
n, err = r.Reader.Read(p)
if err == io.EOF {
fmt.Fprintf(r.out, "\033[2K\r") // clear progress bar line on EOF
}
return
}