Skip to content

Commit

Permalink
Enabling numContextLines in non-json format (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
po3rin authored Jul 29, 2024
1 parent 12ce07a commit 04e7057
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions web/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ApiSearchResult struct {
type LastInput struct {
Query string
Num int
Ctx int

// If set, focus on the search box.
AutoFocus bool
Expand Down
11 changes: 5 additions & 6 deletions web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,10 @@ func (s *Server) serveSearchErr(r *http.Request) (*ApiSearchResult, error) {
}

numCtxLines := 0
if qvals.Get("format") == "json" {
if ctxLinesStr := qvals.Get("ctx"); ctxLinesStr != "" {
numCtxLines, err = strconv.Atoi(ctxLinesStr)
if err != nil || numCtxLines < 0 || numCtxLines > 10 {
return nil, fmt.Errorf("Number of context lines must be between 0 and 10")
}
if ctxLinesStr := qvals.Get("ctx"); ctxLinesStr != "" {
numCtxLines, err = strconv.Atoi(ctxLinesStr)
if err != nil || numCtxLines < 0 || numCtxLines > 10 {
return nil, fmt.Errorf("Number of context lines must be between 0 and 10")
}
}
sOpts.NumContextLines = numCtxLines
Expand Down Expand Up @@ -313,6 +311,7 @@ func (s *Server) serveSearchErr(r *http.Request) (*ApiSearchResult, error) {
Last: LastInput{
Query: queryStr,
Num: num,
Ctx: numCtxLines,
AutoFocus: true,
},
Stats: result.Stats,
Expand Down

0 comments on commit 04e7057

Please sign in to comment.