diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2022-12-21 13:02:25 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2022-12-21 13:02:25 +0900 |
| commit | fd1f7665a77f3bd062586f0f3b54d4ff9863dd4b (patch) | |
| tree | 23eac10e63933d7509250f4c8ebfdab349908356 | |
| parent | 6d14573fd038e9b9789e1250fb194b67ff2e2d06 (diff) | |
| download | fzf-fd1f7665a77f3bd062586f0f3b54d4ff9863dd4b.tar.gz | |
Abort fzf if --listen port is unavailable
| -rw-r--r-- | src/server.go | 8 | ||||
| -rw-r--r-- | src/terminal.go | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/server.go b/src/server.go index eaa314c9..75af23ff 100644 --- a/src/server.go +++ b/src/server.go @@ -16,14 +16,14 @@ const ( httpBadRequest = "HTTP/1.1 400 Bad Request" + crlf ) -func startHttpServer(port int, channel chan []*action) { +func startHttpServer(port int, channel chan []*action) error { if port == 0 { - return + return nil } listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { - return + return fmt.Errorf("port not available: %d", port) } go func() { @@ -41,6 +41,8 @@ func startHttpServer(port int, channel chan []*action) { } listener.Close() }() + + return nil } // Here we are writing a simplistic HTTP server without using net/http diff --git a/src/terminal.go b/src/terminal.go index 1ff40412..d0c0a9de 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -621,6 +621,10 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { t.separator, t.separatorLen = t.ansiLabelPrinter(bar, &tui.ColSeparator, true) } + if err := startHttpServer(t.listenPort, t.serverChan); err != nil { + errorExit(err.Error()) + } + return &t } @@ -2500,7 +2504,6 @@ func (t *Terminal) Loop() { looping := true _, startEvent := t.keymap[tui.Start.AsEvent()] - startHttpServer(t.listenPort, t.serverChan) eventChan := make(chan tui.Event) needBarrier := true barrier := make(chan bool) |
