2 sgodup -- File deduplication utility
3 Copyright (C) 2020 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "github.com/dustin/go-humanize"
32 var LineClear = fmt.Sprintf("%c[%dA%c[2K", ESC, 2, ESC)
34 type Progress struct {
49 suffixFiles, suffixSize string,
54 humanize.Comma(int64(fullFiles)),
55 humanize.IBytes(uint64(fullSize)),
58 make(chan struct{}, 0),
64 func (p Progress) Log(prefix string, files int64, size uint64) {
65 percentageFiles := int64(0)
67 percentageFiles = 100 * files / p.fullFiles
69 percentageSize := uint64(0)
71 percentageSize = 100 * size / p.fullSize
73 now := time.Now().Format("2006/01/02 15:04:05")
76 "%s%s %s / %s (%d%%) files%s\n%s %s / %s (%d%%)%s\n",
78 now, humanize.Comma(files), p.fullFilesS, percentageFiles, p.suffixFiles,
79 now, humanize.IBytes(size), p.fullSizeS, percentageSize, p.suffixSize,
83 func (p Progress) Run(files *int, size *int64) {
85 ticker := time.NewTicker(250 * time.Millisecond)
89 p.Log(LineClear, int64(*files), uint64(*size))
92 p.Log(LineClear, int64(*files), uint64(*size))
99 func (p Progress) Stop() {