mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
better ui handling with spinner
This commit is contained in:
parent
8afc75f1fc
commit
d860fe1e9e
4 changed files with 13 additions and 12 deletions
2
go.mod
2
go.mod
|
@ -12,7 +12,7 @@ require (
|
||||||
github.com/schollz/pake v1.0.2
|
github.com/schollz/pake v1.0.2
|
||||||
github.com/schollz/peerdiscovery v1.2.1
|
github.com/schollz/peerdiscovery v1.2.1
|
||||||
github.com/schollz/progressbar/v2 v2.5.3
|
github.com/schollz/progressbar/v2 v2.5.3
|
||||||
github.com/schollz/spinner v0.0.0-20180922205015-b33181242d11
|
github.com/schollz/spinner v0.0.0-20180922210718-ea497ee41258
|
||||||
github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937
|
github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937
|
||||||
github.com/urfave/cli v1.20.0
|
github.com/urfave/cli v1.20.0
|
||||||
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b
|
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b
|
||||||
|
|
|
@ -156,6 +156,7 @@ func (c *Croc) sendReceive(websocketAddress, fname, codephrase string, isSender
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
|
||||||
// Cleanly close the connection by sending a close message and then
|
// Cleanly close the connection by sending a close message and then
|
||||||
// waiting (with timeout) for the server to close the connection.
|
// waiting (with timeout) for the server to close the connection.
|
||||||
|
|
|
@ -33,10 +33,9 @@ func Receive(isLocal bool, done chan struct{}, c *websocket.Conn, codephrase str
|
||||||
logger.SetLogLevel(DebugLevel)
|
logger.SetLogLevel(DebugLevel)
|
||||||
err := receive(isLocal, c, codephrase, noPrompt, useStdout)
|
err := receive(isLocal, c, codephrase, noPrompt, useStdout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.HasPrefix(err.Error(), "websocket: close 100") {
|
if !strings.HasPrefix(err.Error(), "websocket: close 100") {
|
||||||
return
|
fmt.Fprintf(os.Stderr, "\n"+err.Error())
|
||||||
}
|
}
|
||||||
log.Error(err)
|
|
||||||
}
|
}
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
}
|
}
|
||||||
|
@ -73,8 +72,8 @@ func receive(isLocal bool, c *websocket.Conn, codephrase string, noPrompt bool,
|
||||||
if messageType == websocket.PongMessage || messageType == websocket.PingMessage {
|
if messageType == websocket.PongMessage || messageType == websocket.PingMessage {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if messageType == websocket.TextMessage && bytes.Equal(messsage, "interrupt") {
|
if messageType == websocket.TextMessage && bytes.Equal(message, []byte("interrupt")) {
|
||||||
return errors.New("interrupted by other party")
|
return errors.New("\rinterrupted by other party")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("got %d: %s", messageType, message)
|
log.Debugf("got %d: %s", messageType, message)
|
||||||
|
@ -117,7 +116,7 @@ func receive(isLocal bool, c *websocket.Conn, codephrase string, noPrompt bool,
|
||||||
if fstats.IsDir {
|
if fstats.IsDir {
|
||||||
fileOrFolder = "folder"
|
fileOrFolder = "folder"
|
||||||
}
|
}
|
||||||
fmt.Fprintf(os.Stderr, "%s %s (%s) into: %s\n",
|
fmt.Fprintf(os.Stderr, "\r%s %s (%s) into: %s\n",
|
||||||
overwritingOrReceiving,
|
overwritingOrReceiving,
|
||||||
fileOrFolder,
|
fileOrFolder,
|
||||||
humanize.Bytes(uint64(fstats.Size)),
|
humanize.Bytes(uint64(fstats.Size)),
|
||||||
|
|
|
@ -33,10 +33,11 @@ func Send(isLocal bool, done chan struct{}, c *websocket.Conn, fname string, cod
|
||||||
log.Debugf("sending %s", fname)
|
log.Debugf("sending %s", fname)
|
||||||
err := send(isLocal, c, fname, codephrase, useCompression, useEncryption)
|
err := send(isLocal, c, fname, codephrase, useCompression, useEncryption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.HasPrefix(err.Error(), "websocket: close 100") {
|
if !strings.HasPrefix(err.Error(), "websocket: close 100") {
|
||||||
err = nil
|
fmt.Fprintf(os.Stderr, "\n"+err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +79,8 @@ func send(isLocal bool, c *websocket.Conn, fname string, codephrase string, useC
|
||||||
if messageType == websocket.PongMessage || messageType == websocket.PingMessage {
|
if messageType == websocket.PongMessage || messageType == websocket.PingMessage {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if messageType == websocket.TextMessage && bytes.Equal(messsage, "interrupt") {
|
if messageType == websocket.TextMessage && bytes.Equal(message, []byte("interrupt")) {
|
||||||
return errors.New("interrupted by other party")
|
return errors.New("\rinterrupted by other party")
|
||||||
}
|
}
|
||||||
log.Debugf("got %d: %s", messageType, message)
|
log.Debugf("got %d: %s", messageType, message)
|
||||||
switch step {
|
switch step {
|
||||||
|
@ -166,7 +167,7 @@ func send(isLocal bool, c *websocket.Conn, fname string, codephrase string, useC
|
||||||
return errors.New("recipient refused file")
|
return errors.New("recipient refused file")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "Sending...\n")
|
fmt.Fprintf(os.Stderr, "\rSending...\n")
|
||||||
// send file, compure hash simultaneously
|
// send file, compure hash simultaneously
|
||||||
buffer := make([]byte, 1024*1024*8)
|
buffer := make([]byte, 1024*1024*8)
|
||||||
bar := progressbar.NewOptions(
|
bar := progressbar.NewOptions(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue