mirror of https://github.com/junegunn/fzf
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
953 B
Go
57 lines
953 B
Go
10 years ago
|
package util
|
||
10 years ago
|
|
||
10 years ago
|
// #include <unistd.h>
|
||
|
import "C"
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"time"
|
||
|
)
|
||
10 years ago
|
|
||
10 years ago
|
// Max returns the largest integer
|
||
10 years ago
|
func Max(first int, items ...int) int {
|
||
|
max := first
|
||
|
for _, item := range items {
|
||
|
if item > max {
|
||
|
max = item
|
||
|
}
|
||
|
}
|
||
|
return max
|
||
|
}
|
||
|
|
||
10 years ago
|
// Max32 returns the largest 32-bit integer
|
||
10 years ago
|
func Max32(first int32, second int32) int32 {
|
||
|
if first > second {
|
||
|
return first
|
||
|
}
|
||
|
return second
|
||
|
}
|
||
|
|
||
10 years ago
|
// Constrain limits the given integer with the upper and lower bounds
|
||
|
func Constrain(val int, min int, max int) int {
|
||
|
if val < min {
|
||
|
return min
|
||
10 years ago
|
}
|
||
10 years ago
|
if val > max {
|
||
|
return max
|
||
|
}
|
||
|
return val
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
// DurWithin limits the given time.Duration with the upper and lower bounds
|
||
10 years ago
|
func DurWithin(
|
||
|
val time.Duration, min time.Duration, max time.Duration) time.Duration {
|
||
|
if val < min {
|
||
|
return min
|
||
|
}
|
||
|
if val > max {
|
||
|
return max
|
||
|
}
|
||
|
return val
|
||
|
}
|
||
10 years ago
|
|
||
|
// IsTty returns true is stdin is a terminal
|
||
|
func IsTty() bool {
|
||
|
return int(C.isatty(C.int(os.Stdin.Fd()))) != 0
|
||
|
}
|