mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-15 20:23:50 -07:00
Abort fzf if --listen port is unavailable
This commit is contained in:
@@ -16,14 +16,14 @@ const (
|
|||||||
httpBadRequest = "HTTP/1.1 400 Bad Request" + crlf
|
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 {
|
if port == 0 {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return fmt.Errorf("port not available: %d", port)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -41,6 +41,8 @@ func startHttpServer(port int, channel chan []*action) {
|
|||||||
}
|
}
|
||||||
listener.Close()
|
listener.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we are writing a simplistic HTTP server without using net/http
|
// Here we are writing a simplistic HTTP server without using net/http
|
||||||
|
@@ -621,6 +621,10 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
t.separator, t.separatorLen = t.ansiLabelPrinter(bar, &tui.ColSeparator, true)
|
t.separator, t.separatorLen = t.ansiLabelPrinter(bar, &tui.ColSeparator, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := startHttpServer(t.listenPort, t.serverChan); err != nil {
|
||||||
|
errorExit(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
return &t
|
return &t
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2500,7 +2504,6 @@ func (t *Terminal) Loop() {
|
|||||||
looping := true
|
looping := true
|
||||||
_, startEvent := t.keymap[tui.Start.AsEvent()]
|
_, startEvent := t.keymap[tui.Start.AsEvent()]
|
||||||
|
|
||||||
startHttpServer(t.listenPort, t.serverChan)
|
|
||||||
eventChan := make(chan tui.Event)
|
eventChan := make(chan tui.Event)
|
||||||
needBarrier := true
|
needBarrier := true
|
||||||
barrier := make(chan bool)
|
barrier := make(chan bool)
|
||||||
|
Reference in New Issue
Block a user