2015-01-02 04:49:30 +09:00
|
|
|
package fzf
|
|
|
|
|
2015-01-12 12:56:17 +09:00
|
|
|
import (
|
2019-11-02 12:55:26 +09:00
|
|
|
"math"
|
2017-06-04 16:23:47 +09:00
|
|
|
"os"
|
2015-04-17 22:23:52 +09:00
|
|
|
"time"
|
|
|
|
|
2015-01-12 12:56:17 +09:00
|
|
|
"github.com/junegunn/fzf/src/util"
|
|
|
|
)
|
|
|
|
|
2015-04-17 22:23:52 +09:00
|
|
|
const (
|
|
|
|
// Core
|
|
|
|
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
|
|
|
coordinatorDelayStep time.Duration = 10 * time.Millisecond
|
|
|
|
|
|
|
|
// Reader
|
2017-08-16 03:24:23 +09:00
|
|
|
readerBufferSize = 64 * 1024
|
|
|
|
readerPollIntervalMin = 10 * time.Millisecond
|
|
|
|
readerPollIntervalStep = 5 * time.Millisecond
|
|
|
|
readerPollIntervalMax = 50 * time.Millisecond
|
2015-04-17 22:23:52 +09:00
|
|
|
|
|
|
|
// Terminal
|
2018-09-27 15:27:08 +09:00
|
|
|
initialDelay = 20 * time.Millisecond
|
|
|
|
initialDelayTac = 100 * time.Millisecond
|
2020-01-15 10:43:09 +09:00
|
|
|
spinnerDuration = 100 * time.Millisecond
|
2018-09-27 15:27:08 +09:00
|
|
|
previewCancelWait = 500 * time.Millisecond
|
2020-10-18 17:03:33 +09:00
|
|
|
previewChunkDelay = 100 * time.Millisecond
|
|
|
|
previewDelayed = 500 * time.Millisecond
|
2018-09-27 15:27:08 +09:00
|
|
|
maxPatternLength = 300
|
2019-11-02 12:55:26 +09:00
|
|
|
maxMulti = math.MaxInt32
|
2015-04-17 22:23:52 +09:00
|
|
|
|
|
|
|
// Matcher
|
2016-09-07 09:58:18 +09:00
|
|
|
numPartitionsMultiplier = 8
|
|
|
|
maxPartitions = 32
|
|
|
|
progressMinDuration = 200 * time.Millisecond
|
2015-04-17 22:23:52 +09:00
|
|
|
|
|
|
|
// Capacity of each chunk
|
|
|
|
chunkSize int = 100
|
|
|
|
|
2016-09-07 09:58:18 +09:00
|
|
|
// Pre-allocated memory slices to minimize GC
|
|
|
|
slab16Size int = 100 * 1024 // 200KB * 32 = 12.8MB
|
|
|
|
slab32Size int = 2048 // 8KB * 32 = 256KB
|
|
|
|
|
2015-04-17 22:23:52 +09:00
|
|
|
// Do not cache results of low selectivity queries
|
|
|
|
queryCacheMax int = chunkSize / 5
|
|
|
|
|
|
|
|
// Not to cache mergers with large lists
|
|
|
|
mergerCacheMax int = 100000
|
2015-06-14 00:43:44 +09:00
|
|
|
|
|
|
|
// History
|
|
|
|
defaultHistoryMax int = 1000
|
2016-05-18 02:06:52 +09:00
|
|
|
|
|
|
|
// Jump labels
|
2016-05-19 01:46:22 +09:00
|
|
|
defaultJumpLabels string = "asdfghjklqwertyuiopzxcvbnm1234567890ASDFGHJKLQWERTYUIOPZXCVBNM`~;:,<.>/?'\"!@#$%^&*()[{]}-_=+"
|
2015-04-17 22:23:52 +09:00
|
|
|
)
|
2015-01-02 04:49:30 +09:00
|
|
|
|
2017-06-04 16:23:47 +09:00
|
|
|
var defaultCommand string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
if !util.IsWindows() {
|
2017-12-01 01:39:56 +09:00
|
|
|
defaultCommand = `set -o pipefail; command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-`
|
2017-06-04 16:23:47 +09:00
|
|
|
} else if os.Getenv("TERM") == "cygwin" {
|
|
|
|
defaultCommand = `sh -c "command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-12 03:01:24 +09:00
|
|
|
// fzf events
|
2015-01-02 04:49:30 +09:00
|
|
|
const (
|
2015-01-12 12:56:17 +09:00
|
|
|
EvtReadNew util.EventType = iota
|
2015-01-12 03:01:24 +09:00
|
|
|
EvtReadFin
|
|
|
|
EvtSearchNew
|
|
|
|
EvtSearchProgress
|
|
|
|
EvtSearchFin
|
2015-07-22 03:21:20 +09:00
|
|
|
EvtHeader
|
2017-08-16 03:24:23 +09:00
|
|
|
EvtReady
|
2021-03-07 11:30:26 +09:00
|
|
|
EvtQuit
|
2015-01-02 04:49:30 +09:00
|
|
|
)
|
2015-09-15 13:21:51 +09:00
|
|
|
|
|
|
|
const (
|
2018-09-27 15:27:08 +09:00
|
|
|
exitCancel = -1
|
2015-09-18 10:25:07 +09:00
|
|
|
exitOk = 0
|
|
|
|
exitNoMatch = 1
|
|
|
|
exitError = 2
|
|
|
|
exitInterrupt = 130
|
2015-09-15 13:21:51 +09:00
|
|
|
)
|