Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling numContextLines in non-json format #796

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading