1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

better ui

This commit is contained in:
Zack Scholl 2019-04-11 12:57:02 -07:00
parent 6ef44b8cb3
commit 0cfd3888b8
2 changed files with 10 additions and 1 deletions

View file

@ -2,8 +2,10 @@ package receiver
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
"os" "os"
"path/filepath"
"time" "time"
"github.com/mattn/go-colorable" "github.com/mattn/go-colorable"
@ -168,6 +170,8 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
}() }()
firstByte := true firstByte := true
_, fname := filepath.Split(pathToFile)
fname = fmt.Sprintf("%10s", fname)
var bar *progressbar.ProgressBar var bar *progressbar.ProgressBar
// Consume the message channel, until done // Consume the message channel, until done
// Does not stop on error // Does not stop on error
@ -194,6 +198,8 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
if firstByte { if firstByte {
bar = progressbar.NewOptions64( bar = progressbar.NewOptions64(
fileSize, fileSize,
progressbar.OptionSetWidth(8),
progressbar.OptionSetDescription(fname),
progressbar.OptionSetRenderBlankState(true), progressbar.OptionSetRenderBlankState(true),
progressbar.OptionSetBytes64(fileSize), progressbar.OptionSetBytes64(fileSize),
progressbar.OptionSetWriter(os.Stderr), progressbar.OptionSetWriter(os.Stderr),

View file

@ -2,6 +2,7 @@ package sender
import ( import (
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
"os" "os"
"sync" "sync"
@ -185,7 +186,7 @@ func (s *Session) readFile(pathToFile string) error {
} }
stat, _ := f.Stat() stat, _ := f.Stat()
s.fileSize = stat.Size() s.fileSize = stat.Size()
s.fname = stat.Name() s.fname = fmt.Sprintf("%12s", stat.Name())
s.firstByte = true s.firstByte = true
log.Debugf("Starting to read data from '%s'", pathToFile) log.Debugf("Starting to read data from '%s'", pathToFile)
s.readingStats.Start() s.readingStats.Start()
@ -253,8 +254,10 @@ func (s *Session) onBufferedAmountLow() func() {
s.sess.NetworkStats.AddBytes(uint64(cur.n)) s.sess.NetworkStats.AddBytes(uint64(cur.n))
if s.firstByte { if s.firstByte {
s.firstByte = false s.firstByte = false
fmt.Fprint(os.Stderr, "\n")
s.bar = progressbar.NewOptions64( s.bar = progressbar.NewOptions64(
s.fileSize, s.fileSize,
progressbar.OptionSetWidth(8),
progressbar.OptionSetDescription(s.fname), progressbar.OptionSetDescription(s.fname),
progressbar.OptionSetRenderBlankState(true), progressbar.OptionSetRenderBlankState(true),
progressbar.OptionSetBytes64(s.fileSize), progressbar.OptionSetBytes64(s.fileSize),