99 "os"
1010 "os/exec"
1111 "os/signal"
12- "runtime"
1312 "strings"
1413 "syscall"
1514
@@ -20,7 +19,6 @@ import (
2019 "github.com/tidwall/gjson"
2120 "github.com/tidwall/pretty"
2221 "github.com/urfave/cli/v3"
23- "golang.org/x/sys/unix"
2422 "golang.org/x/term"
2523)
2624
@@ -117,46 +115,19 @@ func streamToStdout(generateOutput func(w *os.File) error) error {
117115}
118116
119117func createPagerFiles () (* os.File , * os.File , bool , error ) {
120- // Windows lacks UNIX socket APIs, so we fall back to pipes there or if
121- // socket creation fails. We prefer sockets when available because they
122- // allow for smaller buffer sizes, preventing unnecessary data streaming
123- // from the backend. Pipes typically have large buffers but serve as a
124- // decent alternative when sockets aren't available.
125- if runtime .GOOS != "windows" {
126- pagerInput , outputFile , isSocketPair , err := createSocketPair ()
127- if err == nil {
128- return pagerInput , outputFile , isSocketPair , nil
129- }
118+ // We prefer sockets when available because they allow for smaller buffer
119+ // sizes, preventing unnecessary data streaming from the backend. Pipes
120+ // typically have large buffers but serve as a decent alternative when
121+ // sockets aren't available (e.g., on Windows).
122+ pagerInput , outputFile , isSocketPair , err := createSocketPair ()
123+ if err == nil {
124+ return pagerInput , outputFile , isSocketPair , nil
130125 }
131126
132127 r , w , err := os .Pipe ()
133128 return r , w , false , err
134129}
135130
136- // In order to avoid large buffers on pipes, this function create a pair of
137- // files for reading and writing through a barely buffered socket.
138- func createSocketPair () (* os.File , * os.File , bool , error ) {
139- fds , err := unix .Socketpair (unix .AF_UNIX , unix .SOCK_STREAM , 0 )
140- if err != nil {
141- return nil , nil , false , err
142- }
143-
144- parentSock , childSock := fds [0 ], fds [1 ]
145-
146- // Use small buffer sizes so we don't ask the server for more paginated
147- // values than we actually need.
148- if err := unix .SetsockoptInt (parentSock , unix .SOL_SOCKET , unix .SO_SNDBUF , 128 ); err != nil {
149- return nil , nil , false , err
150- }
151- if err := unix .SetsockoptInt (childSock , unix .SOL_SOCKET , unix .SO_RCVBUF , 128 ); err != nil {
152- return nil , nil , false , err
153- }
154-
155- pagerInput := os .NewFile (uintptr (childSock ), "child_socket" )
156- outputFile := os .NewFile (uintptr (parentSock ), "parent_socket" )
157- return pagerInput , outputFile , true , nil
158- }
159-
160131// Start a subprocess running the user's preferred pager (or `less` if `$PAGER` is unset)
161132func startPagerCommand (pagerInput * os.File , label string , useSocketpair bool ) (* exec.Cmd , error ) {
162133 pagerProgram := os .Getenv ("PAGER" )
0 commit comments