mirror of
https://github.com/fumiama/RVC-Models-Downloader.git
synced 2025-01-18 12:10:14 +09:00
feat(tui): optimize display
This commit is contained in:
parent
c79338aa40
commit
8e8aea2cef
@ -73,6 +73,8 @@ Usage: rvcmd [-notrs] [-dns dns.yaml] 'target/to/download'
|
||||
-f force download even file exists
|
||||
-notrs
|
||||
use standard TLS client
|
||||
-notui
|
||||
use plain text instead of TUI
|
||||
-w uint
|
||||
connection waiting seconds (default 4)
|
||||
'target/to/download'
|
||||
|
@ -73,6 +73,8 @@ Usage: rvcmd [-notrs] [-dns dns.yaml] 'target/to/download'
|
||||
-f force download even file exists
|
||||
-notrs
|
||||
use standard TLS client
|
||||
-notui
|
||||
use plain text instead of TUI
|
||||
-w uint
|
||||
connection waiting seconds (default 4)
|
||||
'target/to/download'
|
||||
|
24
main.go
24
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -54,6 +55,8 @@ func main() {
|
||||
defer ui.Close()
|
||||
sc = newscreen()
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() {
|
||||
if *dnsf != "" {
|
||||
f, err := os.Open(*dnsf)
|
||||
@ -80,12 +83,21 @@ func main() {
|
||||
errorln(err)
|
||||
return
|
||||
}
|
||||
err = usercfg.download(args[0], "", time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
|
||||
if err != nil {
|
||||
errorln(err)
|
||||
return
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
err := usercfg.download(args[0], "", time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
|
||||
ch <- struct{}{}
|
||||
if err != nil {
|
||||
errorln(err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case <-ch:
|
||||
infoln("all download tasks finished.")
|
||||
case <-ctx.Done():
|
||||
logrus.Warnln("download canceled")
|
||||
}
|
||||
infoln("all download tasks finished.")
|
||||
}()
|
||||
sc.flushloop(time.Second)
|
||||
sc.show(time.Second)
|
||||
}
|
||||
|
10
ui.go
10
ui.go
@ -47,7 +47,7 @@ func newscreen() (s screen) {
|
||||
s.logroll.SetRect(w/2, 0, w, h/2)
|
||||
|
||||
s.speedln = widgets.NewPlot()
|
||||
s.speedln.Title = "Speed"
|
||||
s.speedln.Title = "Speed (MB/s)"
|
||||
s.speedln.Data = make([][]float64, 1)
|
||||
s.speedln.Data[0] = []float64{0, 0}
|
||||
s.speedln.AxesColor = ui.ColorWhite
|
||||
@ -60,18 +60,22 @@ func newscreen() (s screen) {
|
||||
func (s *screen) logwrite(sz int) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
w := s.speedln.Size().X
|
||||
s.totaldl += sz
|
||||
tdiff := time.Since(s.lastclr)
|
||||
if tdiff > time.Second {
|
||||
s.speedln.Data[0] = append(s.speedln.Data[0],
|
||||
float64(s.totaldl/1024)/(float64(tdiff)/float64(time.Second)),
|
||||
float64(s.totaldl/1024)/1024/(float64(tdiff)/float64(time.Second)),
|
||||
)
|
||||
if len(s.speedln.Data[0]) > w-5 {
|
||||
s.speedln.Data[0] = s.speedln.Data[0][1:]
|
||||
}
|
||||
s.totaldl = 0
|
||||
s.lastclr = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *screen) flushloop(interval time.Duration) {
|
||||
func (s *screen) show(interval time.Duration) {
|
||||
t := time.NewTicker(interval)
|
||||
defer t.Stop()
|
||||
s.flush()
|
||||
|
Loading…
x
Reference in New Issue
Block a user