Skip to content

Commit

Permalink
improve zmodem progress
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Dec 10, 2023
1 parent a64ab46 commit 9713637
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -27,13 +27,13 @@ GO_TEST := ${shell basename `which gotest 2>/dev/null` 2>/dev/null || echo go te

all: ${BIN_DIR}/${TRZ} ${BIN_DIR}/${TSZ} ${BIN_DIR}/${TRZSZ}

${BIN_DIR}/${TRZ}: $(wildcard ./cmd/trz/*.go ./trzsz/*.go)
${BIN_DIR}/${TRZ}: $(wildcard ./cmd/trz/*.go ./trzsz/*.go) go.mod go.sum
go build -o ${BIN_DIR}/ ./cmd/trz

${BIN_DIR}/${TSZ}: $(wildcard ./cmd/tsz/*.go ./trzsz/*.go)
${BIN_DIR}/${TSZ}: $(wildcard ./cmd/tsz/*.go ./trzsz/*.go) go.mod go.sum
go build -o ${BIN_DIR}/ ./cmd/tsz

${BIN_DIR}/${TRZSZ}: $(wildcard ./cmd/trzsz/*.go ./trzsz/*.go)
${BIN_DIR}/${TRZSZ}: $(wildcard ./cmd/trzsz/*.go ./trzsz/*.go) go.mod go.sum
go build -o ${BIN_DIR}/ ./cmd/trzsz

clean:
8 changes: 7 additions & 1 deletion trzsz/zmodem.go
Original file line number Diff line number Diff line change
@@ -85,6 +85,8 @@ func (z *zmodemTransfer) writeMessage(msg string) {

func (z *zmodemTransfer) updateProgress(buf []byte) {
if buf == nil {
now := timeNowFunc()
z.showProgress(&now)
_ = writeAll(z.clientOut, []byte("\r\n"))
return
}
@@ -99,8 +101,12 @@ func (z *zmodemTransfer) updateProgress(buf []byte) {
return
}
z.lastUpdateTime = &now
z.showProgress(&now)
}

func (z *zmodemTransfer) showProgress(now *time.Time) {
_ = writeAll(z.clientOut, []byte(fmt.Sprintf("\r\x1b[2KTransferred %s, Speed %s.",
convertSizeToString(float64(z.transferredSize)), z.getSpeed(&now))))
convertSizeToString(float64(z.transferredSize)), z.getSpeed(now))))
}

func (z *zmodemTransfer) getSpeed(now *time.Time) string {

0 comments on commit 9713637

Please sign in to comment.