Skip to content
Myr

Make GET endpoint available from 'execute' and 'transform' actions

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 9dc3ed6 · Browse files · 4 files+50 added−27 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+50 added−27 removed

  • other:+50 added−27 removed

4 files+50 added−27 removed

modified:src/actiontype_string.go+4 added-5 removed
115 unmodified lines
116 _ = x[actDeselect-105]117 _ = x[actUnbind-106]118 _ = x[actRebind-107]119 _ = x[actBecome-108]120 _ = x[actResponse-109]121 _ = x[actShowHeader-110]122 _ = x[actHideHeader-111]120 _ = x[actShowHeader-109]121 _ = x[actHideHeader-110]122}123125const _actionType_name = "actIgnoreactStartactClickactInvalidactCharactMouseactBeginningOfLineactAbortactAcceptactAcceptNonEmptyactAcceptOrPrintQueryactBackwardCharactBackwardDeleteCharactBackwardDeleteCharEofactBackwardWordactCancelactChangeBorderLabelactChangeHeaderactChangeMultiactChangePreviewLabelactChangePromptactChangeQueryactClearScreenactClearQueryactClearSelectionactCloseactDeleteCharactDeleteCharEofactEndOfLineactFatalactForwardCharactForwardWordactKillLineactKillWordactUnixLineDiscardactUnixWordRuboutactYankactBackwardKillWordactSelectAllactDeselectAllactToggleactToggleSearchactToggleAllactToggleDownactToggleUpactToggleInactToggleOutactToggleTrackactToggleTrackCurrentactToggleHeaderactTrackCurrentactUntrackCurrentactDownactUpactPageUpactPageDownactPositionactHalfPageUpactHalfPageDownactOffsetUpactOffsetDownactJumpactJumpAcceptactPrintQueryactRefreshPreviewactReplaceQueryactToggleSortactShowPreviewactHidePreviewactTogglePreviewactTogglePreviewWrapactTransformactTransformBorderLabelactTransformHeaderactTransformPreviewLabelactTransformPromptactTransformQueryactPreviewactChangePreviewactChangePreviewWindowactPreviewTopactPreviewBottomactPreviewUpactPreviewDownactPreviewPageUpactPreviewPageDownactPreviewHalfPageUpactPreviewHalfPageDownactPrevHistoryactPrevSelectedactPrintactPutactNextHistoryactNextSelectedactExecuteactExecuteSilentactExecuteMultiactSigStopactFirstactLastactReloadactReloadSyncactDisableSearchactEnableSearchactSelectactDeselectactUnbindactRebindactBecomeactResponseactShowHeaderactHideHeader"124const _actionType_name = "actIgnoreactStartactClickactInvalidactCharactMouseactBeginningOfLineactAbortactAcceptactAcceptNonEmptyactAcceptOrPrintQueryactBackwardCharactBackwardDeleteCharactBackwardDeleteCharEofactBackwardWordactCancelactChangeBorderLabelactChangeHeaderactChangeMultiactChangePreviewLabelactChangePromptactChangeQueryactClearScreenactClearQueryactClearSelectionactCloseactDeleteCharactDeleteCharEofactEndOfLineactFatalactForwardCharactForwardWordactKillLineactKillWordactUnixLineDiscardactUnixWordRuboutactYankactBackwardKillWordactSelectAllactDeselectAllactToggleactToggleSearchactToggleAllactToggleDownactToggleUpactToggleInactToggleOutactToggleTrackactToggleTrackCurrentactToggleHeaderactTrackCurrentactUntrackCurrentactDownactUpactPageUpactPageDownactPositionactHalfPageUpactHalfPageDownactOffsetUpactOffsetDownactJumpactJumpAcceptactPrintQueryactRefreshPreviewactReplaceQueryactToggleSortactShowPreviewactHidePreviewactTogglePreviewactTogglePreviewWrapactTransformactTransformBorderLabelactTransformHeaderactTransformPreviewLabelactTransformPromptactTransformQueryactPreviewactChangePreviewactChangePreviewWindowactPreviewTopactPreviewBottomactPreviewUpactPreviewDownactPreviewPageUpactPreviewPageDownactPreviewHalfPageUpactPreviewHalfPageDownactPrevHistoryactPrevSelectedactPrintactPutactNextHistoryactNextSelectedactExecuteactExecuteSilentactExecuteMultiactSigStopactFirstactLastactReloadactReloadSyncactDisableSearchactEnableSearchactSelectactDeselectactUnbindactRebindactBecomeactShowHeaderactHideHeader"125127var _actionType_index = [...]uint16{0, 9, 17, 25, 35, 42, 50, 68, 76, 85, 102, 123, 138, 159, 183, 198, 207, 227, 242, 256, 277, 292, 306, 320, 333, 350, 358, 371, 387, 399, 407, 421, 435, 446, 457, 475, 492, 499, 518, 530, 544, 553, 568, 580, 593, 604, 615, 627, 641, 662, 677, 692, 709, 716, 721, 730, 741, 752, 765, 780, 791, 804, 811, 824, 837, 854, 869, 882, 896, 910, 926, 946, 958, 981, 999, 1023, 1041, 1058, 1068, 1084, 1106, 1119, 1135, 1147, 1161, 1177, 1195, 1215, 1237, 1251, 1266, 1274, 1280, 1294, 1309, 1319, 1335, 1350, 1360, 1368, 1375, 1384, 1397, 1413, 1428, 1437, 1448, 1457, 1466, 1475, 1486, 1499, 1512}126var _actionType_index = [...]uint16{0, 9, 17, 25, 35, 42, 50, 68, 76, 85, 102, 123, 138, 159, 183, 198, 207, 227, 242, 256, 277, 292, 306, 320, 333, 350, 358, 371, 387, 399, 407, 421, 435, 446, 457, 475, 492, 499, 518, 530, 544, 553, 568, 580, 593, 604, 615, 627, 641, 662, 677, 692, 709, 716, 721, 730, 741, 752, 765, 780, 791, 804, 811, 824, 837, 854, 869, 882, 896, 910, 926, 946, 958, 981, 999, 1023, 1041, 1058, 1068, 1084, 1106, 1119, 1135, 1147, 1161, 1177, 1195, 1215, 1237, 1251, 1266, 1274, 1280, 1294, 1309, 1319, 1335, 1350, 1360, 1368, 1375, 1384, 1397, 1413, 1428, 1437, 1448, 1457, 1466, 1475, 1488, 1501}127128func (i actionType) String() string {129 if i < 0 || i >= actionType(len(_actionType_index)-1) {130 return "actionType(" + strconv.FormatInt(int64(i), 10) + ")"
3 unmodified lines
modified:src/server.go+10 added-16 removed
36 unmodified lines
37 maxContentLength = 1024 * 102438)3940type httpServer struct {41 apiKey []byte42 actionChannel chan []*action43 responseChannel chan string41 apiKey []byte42 actionChannel chan []*action43 getHandler func(getParams) string44}4546type listenAddress struct {47 host string
24 unmodified lines
72 }73 return listenAddress{parts[0], port}, nil74}7576func startHttpServer(address listenAddress, actionChannel chan []*action, responseChannel chan string) (net.Listener, int, error) {76func startHttpServer(address listenAddress, actionChannel chan []*action, getHandler func(getParams) string) (net.Listener, int, error) {77 host := address.host78 port := address.port79 apiKey := os.Getenv("FZF_API_KEY")80 if !address.IsLocal() && len(apiKey) == 0 {
17 unmodified lines
98 }99 }100101 server := httpServer{102 apiKey: []byte(apiKey),103 actionChannel: actionChannel,104 responseChannel: responseChannel,102 apiKey: []byte(apiKey),103 actionChannel: actionChannel,104 getHandler: getHandler,105 }106107 go func() {108 for {
55 unmodified lines
164 switch section {165 case 0:166 getMatch := getRegex.FindStringSubmatch(text)167 if len(getMatch) > 0 {168 server.actionChannel <- []*action{{t: actResponse, a: getMatch[1]}}169 select {170 case response := <-server.responseChannel:168 response := server.getHandler(parseGetParams(getMatch[1]))169 if len(response) > 0 {170 return good(response)172 case <-time.After(channelTimeout):173 go func() {174 // Drain the channel175 <-server.responseChannel176 }()177 return answer(httpUnavailable+jsonContentType, `{"error":"timeout"}`)171 }172 return answer(httpUnavailable+jsonContentType, `{"error":"timeout"}`)173 } else if !strings.HasPrefix(text, "POST / HTTP") {174 return bad("invalid request method")175 }176 section++
70 unmodified lines
modified:src/terminal.go+27 added-6 removed
316 unmodified lines
317 sigstop bool318 startChan chan fitpad319 killChan chan bool320 serverInputChan chan []*action321 serverOutputChan chan string321 eventChan chan tui.Event322 slab *util.Slab323 theme *tui.ColorTheme324 tui tui.Renderer
170 unmodified lines
495 actDeselect496 actUnbind497 actRebind498 actBecome500 actResponse499 actShowHeader500 actHideHeader501)502
333 unmodified lines
836 theme: opts.Theme,837 startChan: make(chan fitpad, 1),838 killChan: make(chan bool),839 serverInputChan: make(chan []*action, 100),842 serverOutputChan: make(chan string),840 eventChan: make(chan tui.Event, 6), // (load + result + zero|one) | (focus) | (resize) | (GetChar)841 tui: renderer,842 ttyin: ttyin,843 initFunc: func() error { return renderer.Init() },
45 unmodified lines
889 _, t.hasFocusActions = t.keymap[tui.Focus.AsEvent()]890 _, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]891892 if t.listenAddr != nil {896 listener, port, err := startHttpServer(*t.listenAddr, t.serverInputChan, t.serverOutputChan)893 listener, port, err := startHttpServer(*t.listenAddr, t.serverInputChan, t.dumpStatus)894 if err != nil {895 return nil, err896 }897 t.listener = listener
2094 unmodified lines
2992 }2993 }29942995 t.tui.Pause(true)2996 t.mutex.Unlock()2997 cmd.Run()2998 t.mutex.Lock()2999 t.tui.Resume(true, false)3000 t.redraw()3001 t.refresh()3002 } else {3003 t.mutex.Unlock()3004 if capture {3005 out, _ := cmd.StdoutPipe()3006 reader := bufio.NewReader(out)3007 cmd.Start()
7 unmodified lines
3015 cmd.Wait()3016 } else {3017 cmd.Run()3018 }3019 t.mutex.Lock()3020 }3021 t.executing.Set(false)3022 removeFiles(tempFiles)3023 return line
695 unmodified lines
3719 }3720 doAction = func(a *action) bool {3721 switch a.t {3722 case actIgnore, actStart, actClick:3722 case actResponse:3723 t.serverOutputChan <- t.dumpStatus(parseGetParams(a.a))3723 case actBecome:3724 valid, list := t.buildPlusList(a.a, false)3725 if valid {3726 // We do not remove temp files in this case
979 unmodified lines
4706 Text: i.AsString(t.ansi),4707 }4708}47094710func (t *Terminal) tryLock(timeout time.Duration) bool {4711 sleepDuration := 10 * time.Millisecond47124713 for {4714 if t.mutex.TryLock() {4715 return true4716 }47174718 timeout -= sleepDuration4719 if timeout <= 0 {4720 break4721 }4722 time.Sleep(sleepDuration)4723 }4724 return false4725}47264727func (t *Terminal) dumpStatus(params getParams) string {4728 if !t.tryLock(channelTimeout) {4729 return ""4730 }4731 defer t.mutex.Unlock()47324733 selectedItems := t.sortSelected()4734 selected := make([]StatusItem, util.Max(0, util.Min(params.limit, len(selectedItems)-params.offset)))4735 for i := range selected {4736 selected[i] = t.dumpItem(selectedItems[i+params.offset].item)
29 unmodified lines
modified:CHANGELOG.md+9 added
2 unmodified lines
340.53.15------6- Bug fixes and minor improvements7 - Better cache management and improved rendering for `--tail`8 - Fixed crash when using `--tiebreak=end` with very long items9 - Fixed mouse support on Windows10 - zsh 5.0 compatibility (thanks to @LangLangBart)11 - Fixed `--walker-skip` to also skip symlinks to directories12 - GET endpoint is now available from `execute` and `transform` actions (it used to timeout due to lock conflict)13 ```sh14 fzf --listen --bind 'focus:transform-header:curl -s localhost:$FZF_PORT?limit=0 | jq .'15 ```16170.53.018------19- Multi-line display
2145 unmodified lines