Skip to content

Commit a446bf3

Browse files
committed
Fixes
1 parent 05efd6c commit a446bf3

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

cmd/search.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"text/template"
99
"time"
1010

11+
"github.com/mattn/go-tty"
1112
"github.com/scalvert/glean-cli/pkg/config"
1213
"github.com/scalvert/glean-cli/pkg/http"
1314
"github.com/spf13/cobra"
@@ -177,13 +178,18 @@ func formatDatasource(s string) string {
177178
return string(words)
178179
}
179180

180-
var defaultTemplate = `{{range $i, $result := .Results}}
181-
{{add $i 1}} {{formatDatasource $result.Document.Datasource}} | {{gleanBlue $result.Document.Title}}
181+
var defaultTemplate = `{{- range $i, $result := .Results -}}
182+
{{if $i}}
183+
184+
{{end}}{{add $i 1}} {{formatDatasource $result.Document.Datasource}} | {{gleanBlue $result.Document.Title}}
182185
{{gleanYellow $result.Document.URL}}
183-
{{range $result.Snippets}}{{.Text}}
184-
{{end}}
185-
{{end}}{{if .SuggestedSpellCorrectedQuery}}Did you mean: {{.SuggestedSpellCorrectedQuery}}?{{end}}
186-
{{if .RewrittenQuery}}Showing results for: {{.RewrittenQuery}}{{end}}`
186+
{{- range $result.Snippets}}
187+
{{.Text}}{{end}}
188+
{{- end}}{{if .SuggestedSpellCorrectedQuery}}
189+
190+
Did you mean: {{.SuggestedSpellCorrectedQuery}}?{{end}}{{if .RewrittenQuery}}
191+
192+
Showing results for: {{.RewrittenQuery}}{{end}}`
187193

188194
func NewCmdSearch() *cobra.Command {
189195
opts := &SearchOptions{
@@ -466,10 +472,21 @@ func runSearch(cmd *cobra.Command, opts *SearchOptions) error {
466472

467473
// Handle pagination if there are more results
468474
for response.HasMoreResults {
469-
fmt.Fprint(cmd.OutOrStdout(), "\nPress 'q' to quit, any other key to load more results...")
470-
var input string
471-
fmt.Scanln(&input)
472-
if input == "q" {
475+
fmt.Fprint(cmd.OutOrStdout(), "\n\nPress 'q' to quit, any other key to load more results...")
476+
477+
tty, err := tty.Open()
478+
if err != nil {
479+
return fmt.Errorf("failed to open tty: %w", err)
480+
}
481+
defer tty.Close()
482+
483+
r, err := tty.ReadRune()
484+
if err != nil {
485+
return fmt.Errorf("failed to read input: %w", err)
486+
}
487+
488+
if r == 'q' || r == 'Q' {
489+
fmt.Fprintln(cmd.OutOrStdout())
473490
break
474491
}
475492

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ require (
2121
github.com/fatih/color v1.7.0 // indirect
2222
github.com/godbus/dbus/v5 v5.1.0 // indirect
2323
github.com/inconshreveable/mousetrap v1.1.0 // indirect
24-
github.com/mattn/go-colorable v0.1.2 // indirect
25-
github.com/mattn/go-isatty v0.0.8 // indirect
24+
github.com/mattn/go-colorable v0.1.13 // indirect
25+
github.com/mattn/go-isatty v0.0.20 // indirect
26+
github.com/mattn/go-tty v0.0.7 // indirect
2627
github.com/pmezard/go-difflib v1.0.0 // indirect
2728
github.com/spf13/pflag v1.0.5 // indirect
2829
golang.org/x/sys v0.29.0 // indirect

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
2424
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2525
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
2626
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
27+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
28+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
2729
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
2830
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
31+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
32+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
33+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
34+
github.com/mattn/go-tty v0.0.7 h1:KJ486B6qI8+wBO7kQxYgmmEFDaFEE96JMBQ7h400N8Q=
35+
github.com/mattn/go-tty v0.0.7/go.mod h1:f2i5ZOvXBU/tCABmLmOfzLz9azMo5wdAaElRNnJKr+k=
2936
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3037
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3138
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -41,6 +48,8 @@ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf
4148
github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms=
4249
github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk=
4350
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
51+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
52+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4453
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
4554
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4655
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=

0 commit comments

Comments
 (0)