mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-31 02:29:18 +02:00
WIP tier CLI
This commit is contained in:
parent
9b54f63eb1
commit
e3b39f670f
10 changed files with 367 additions and 35 deletions
util
14
util/util.go
14
util/util.go
|
@ -222,6 +222,20 @@ func ParseSize(s string) (int64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// FormatSize formats bytes into a human-readable notation, e.g. 2.1 MB
|
||||
func FormatSize(b int64) string {
|
||||
const unit = 1024
|
||||
if b < unit {
|
||||
return fmt.Sprintf("%d bytes", b)
|
||||
}
|
||||
div, exp := int64(unit), 0
|
||||
for n := b / unit; n >= unit; n /= unit {
|
||||
div *= unit
|
||||
exp++
|
||||
}
|
||||
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
|
||||
// ReadPassword will read a password from STDIN. If the terminal supports it, it will not print the
|
||||
// input characters to the screen. If not, it'll just read using normal readline semantics (useful for testing).
|
||||
func ReadPassword(in io.Reader) ([]byte, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue