feat: use glow renderer
This commit is contained in:
24
cmd/root.go
24
cmd/root.go
@@ -156,7 +156,17 @@ func showResult(result *search.Result) {
|
||||
}
|
||||
|
||||
func displayFile(filePath string, highlightLine int) {
|
||||
// Try bat first for syntax highlighting
|
||||
// Try glow first for Markdown rendering
|
||||
if glowPath, err := exec.LookPath("glow"); err == nil {
|
||||
cmd := exec.Command(glowPath, filePath)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to bat for syntax highlighting
|
||||
if batPath, err := exec.LookPath("bat"); err == nil {
|
||||
args := []string{
|
||||
"--paging=never",
|
||||
@@ -175,7 +185,17 @@ func displayFile(filePath string, highlightLine int) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to plain output
|
||||
// Fallback to cat
|
||||
if catPath, err := exec.LookPath("cat"); err == nil {
|
||||
cmd := exec.Command(catPath, filePath)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Final fallback to plain Go file read
|
||||
content, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reading file: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user