summaryrefslogtreecommitdiffstats
path: root/src/terminal.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2022-12-20 16:28:36 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2022-12-21 01:35:08 +0900
commit4b055bf260768780fce345fdb88abeb826122315 (patch)
treedd10e35ee5a27668e0087642f39b8bbd473fd874 /src/terminal.go
parent1ba7484d606bf3797b3936651051bb4113dbcad2 (diff)
Rewrite HTTP server without net/http
This cuts down the binary size from 5.7MB to 3.3MB.
Diffstat (limited to 'src/terminal.go')
-rw-r--r--src/terminal.go37
1 files changed, 1 insertions, 36 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 47cc34cf..0d99637c 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -3,10 +3,8 @@ package fzf
import (
"bufio"
"fmt"
- "io"
"io/ioutil"
"math"
- "net/http"
"os"
"os/signal"
"regexp"
@@ -626,39 +624,6 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
return &t
}
-func (t *Terminal) startServer() {
- if t.listenPort == 0 {
- return
- }
-
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- if r.Method != "POST" {
- w.WriteHeader(http.StatusBadRequest)
- return
- }
- body, err := io.ReadAll(r.Body)
- if err != nil {
- w.WriteHeader(http.StatusBadRequest)
- return
- }
-
- response := ""
- actions := parseSingleActionList(string(body), func(message string) {
- response = message
- })
-
- if len(response) > 0 {
- w.WriteHeader(http.StatusBadRequest)
- fmt.Fprintln(w, response)
- return
- }
- t.serverChan <- actions
- })
- go func() {
- http.ListenAndServe(fmt.Sprintf(":%d", t.listenPort), nil)
- }()
-}
-
func borderLines(shape tui.BorderShape) int {
switch shape {
case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble:
@@ -2535,7 +2500,7 @@ func (t *Terminal) Loop() {
looping := true
_, startEvent := t.keymap[tui.Start.AsEvent()]
- t.startServer()
+ startHttpServer(t.listenPort, t.serverChan)
eventChan := make(chan tui.Event)
needBarrier := true
barrier := make(chan bool)