--tmux vs. --height: Last one wins
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent cfdf2f1 · Browse files · 3 files·+31 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+31 added−21 removed
- other:+31 added−21 removed
Provenance
- Commit
e2f93e5- Tree
0e1d081- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
cfdf2f1
3 files changed+31 added−21 removed
modified:src/core.go+1 added-1 removed
18 unmodified lines19 */20 21 // Run starts fzf22 func Run(opts *Options) (int, error) {23- if opts.Tmux != nil && len(os.Getenv("TMUX")) > 0 {23+ if opts.Tmux != nil && len(os.Getenv("TMUX")) > 0 && opts.Tmux.index >= opts.Height.index {24 return runTmux(os.Args, opts)25 }26 27 if needWinpty(opts) {394 unmodified linesmodified:src/options_test.go+8 added-5 removed
104 unmodified lines105 }106 }107 108 func TestIrrelevantNth(t *testing.T) {109+ index := 0110 {111 opts := defaultOptions()112 words := []string{"--nth", "..", "-x"}112- parseOptions(opts, words)113+ parseOptions(&index, opts, words)114 postProcessOptions(opts)115 if len(opts.Nth) != 0 {116 t.Errorf("nth should be empty: %v", opts.Nth)117 }118 }119 for _, words := range [][]string{{"--nth", "..,3", "+x"}, {"--nth", "3,1..", "+x"}, {"--nth", "..-1,1", "+x"}} {120 {121 opts := defaultOptions()121- parseOptions(opts, words)122+ parseOptions(&index, opts, words)123 postProcessOptions(opts)124 if len(opts.Nth) != 0 {125 t.Errorf("nth should be empty: %v", opts.Nth)126 }127 }128 {129 opts := defaultOptions()130 words = append(words, "-x")130- parseOptions(opts, words)131+ parseOptions(&index, opts, words)132 postProcessOptions(opts)133 if len(opts.Nth) != 2 {134 t.Errorf("nth should not be empty: %v", opts.Nth)135 }199 unmodified lines335 }336 }337 338 func TestDefaultCtrlNP(t *testing.T) {339+ index := 0340 check := func(words []string, et tui.EventType, expected actionType) {341 e := et.AsEvent()342 opts := defaultOptions()341- parseOptions(opts, words)343+ parseOptions(&index, opts, words)344 postProcessOptions(opts)345 if opts.Keymap[e][0].t != expected {346 t.Error()347 }17 unmodified lines365 check([]string{hist, "--bind=ctrl-p:accept"}, tui.CtrlP, actAccept)366 }367 368 func optsFor(words ...string) *Options {369+ index := 0370 opts := defaultOptions()368- parseOptions(opts, words)371+ parseOptions(&index, opts, words)372 postProcessOptions(opts)373 return opts374 }375 128 unmodified linesmodified:src/options.go+22 added-15 removed
188 unmodified lines189 size float64190 percent bool191 auto bool192 inverse bool193+ index int194 }195 196 type sizeSpec struct {197 size float6432 unmodified lines230 type tmuxOptions struct {231 width sizeSpec232 height sizeSpec233 position windowPosition234+ index int235 }236 237 type layoutType int238 41 unmodified lines280 func (o *previewOpts) Toggle() {281 o.hidden = !o.hidden282 }283 282-func defaultTmuxOptions() *tmuxOptions {284+func defaultTmuxOptions(index int) *tmuxOptions {285 return &tmuxOptions{286 position: posCenter,287 width: sizeSpec{50, true},286- height: sizeSpec{50, true}}288+ height: sizeSpec{50, true},289+ index: index}290 }291 289-func parseTmuxOptions(arg string) (*tmuxOptions, error) {292+func parseTmuxOptions(arg string, index int) (*tmuxOptions, error) {293 var err error291- opts := defaultTmuxOptions()294+ opts := defaultTmuxOptions(index)295 tokens := splitRegexp.Split(arg, -1)296 errorToReturn := errors.New("invalid tmux option: " + arg + " (expected: [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]])")297 if len(tokens) == 0 || len(tokens) > 3 {298 return nil, errorToReturn1338 unmodified lines1637 }1638 return sizeSpec{val, percent}, nil1639 }1640 1638-func parseHeight(str string) (heightSpec, error) {1639- heightSpec := heightSpec{}1641+func parseHeight(str string, index int) (heightSpec, error) {1642+ heightSpec := heightSpec{index: index}1643 if strings.HasPrefix(str, "~") {1644 heightSpec.auto = true1645 str = str[1:]1646 }239 unmodified lines1886 }1887 return result, nil1888 }1889 1887-func parseOptions(opts *Options, allArgs []string) error {1890+func parseOptions(index *int, opts *Options, allArgs []string) error {1891 var err error1892 var historyMax int1893 if opts.History == nil {1894 historyMax = defaultHistoryMax27 unmodified lines1922 opts.Help = false1923 opts.Version = false1924 opts.Man = false1925 }1926+ startIndex := *index1927 for i := 0; i < len(allArgs); i++ {1928 arg := allArgs[i]1929+ index := i + startIndex1930 switch arg {1931 case "--man":1932 clearExitingOpts()1933 opts.Man = true16 unmodified lines1950 opts.NoWinpty = true1951 case "--tmux":1952 given, str := optionalNextString(allArgs, &i)1953 if given {1949- if opts.Tmux, err = parseTmuxOptions(str); err != nil {1954+ if opts.Tmux, err = parseTmuxOptions(str, index); err != nil {1955 return err1956 }1957 } else {1953- opts.Tmux = defaultTmuxOptions()1958+ opts.Tmux = defaultTmuxOptions(index)1959 }1960 case "--no-tmux":1961 opts.Tmux = nil1962 case "--force-tty-in":355 unmodified lines2318 str, err := nextString(allArgs, &i, "height required: [~]HEIGHT[%]")2319 if err != nil {2320 return err2321 }2317- if opts.Height, err = parseHeight(str); err != nil {2322+ if opts.Height, err = parseHeight(str, index); err != nil {2323 return err2324 }2325 case "--min-height":2326 if opts.MinHeight, err = nextInt(allArgs, &i, "height required: HEIGHT"); err != nil {133 unmodified lines2460 if opts.FuzzyAlgo, err = parseAlgo(value); err != nil {2461 return err2462 }2463 } else if match, value := optString(arg, "--tmux="); match {2459- if opts.Tmux, err = parseTmuxOptions(value); err != nil {2464+ if opts.Tmux, err = parseTmuxOptions(value, index); err != nil {2465 return err2466 }2467 } else if match, value := optString(arg, "--scheme="); match {2468 opts.Scheme = strings.ToLower(value)45 unmodified lines2514 if opts.Multi, err = atoi(value); err != nil {2515 return err2516 }2517 } else if match, value := optString(arg, "--height="); match {2513- if opts.Height, err = parseHeight(value); err != nil {2518+ if opts.Height, err = parseHeight(value, index); err != nil {2519 return err2520 }2521 } else if match, value := optString(arg, "--min-height="); match {2522 if opts.MinHeight, err = atoi(value); err != nil {112 unmodified lines2635 return errors.New("unknown option: " + arg)2636 }2637 }2638 }2639+ *index += len(allArgs)2640 2641 if opts.HeaderLines < 0 {2642 return errors.New("header lines must be a non-negative integer")2643 }213 unmodified lines2857 2858 // ParseOptions parses command-line options2859 func ParseOptions(useDefaults bool, args []string) (*Options, error) {2860 opts := defaultOptions()2861+ index := 02862 2863 if useDefaults {2864 // 1. Options from $FZF_DEFAULT_OPTS_FILE2865 if path := os.Getenv("FZF_DEFAULT_OPTS_FILE"); path != "" {6 unmodified lines2872 if parseErr != nil {2873 return nil, errors.New(path + ": " + parseErr.Error())2874 }2875 if len(words) > 0 {2869- if err := parseOptions(opts, words); err != nil {2876+ if err := parseOptions(&index, opts, words); err != nil {2877 return nil, errors.New(path + ": " + err.Error())2878 }2879 }2880 }3 unmodified lines2884 if parseErr != nil {2885 return nil, errors.New("$FZF_DEFAULT_OPTS: " + parseErr.Error())2886 }2887 if len(words) > 0 {2881- if err := parseOptions(opts, words); err != nil {2888+ if err := parseOptions(&index, opts, words); err != nil {2889 return nil, errors.New("$FZF_DEFAULT_OPTS: " + err.Error())2890 }2891 }2892 }2893 2894 // 3. Options from command-line arguments2888- if err := parseOptions(opts, args); err != nil {2895+ if err := parseOptions(&index, opts, args); err != nil {2896 return nil, err2897 }2898 2899 // 4. Final validation of merged options6 unmodified lines