ansichroma is a Go package for syntax highlighting text files and strings using ANSI escape codes. It supports various programming languages and styles, providing a customizable way to highlight code for terminal output.
ansichrom Highly based on chroma
To install ansichroma, use go get:
go get github.com/yorukot/ansichroma
go
Copy code
package main
import (
"fmt"
"github.com/yorukot/ansichroma"
"github.com/charmbracelet/lipgloss"
)
func main() {
// Highlight text file
path := "path/to/your/file.txt"
linesToRead := 10
style := "monokai"
background := "#1e1e2e"
resultString, err := ansichroma.HighlightFromFile(path, linesToRead, style, background)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(resultString)
// Highlight text string
fileContent := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello, World!\")\n}"
format := "go"
style := "monokai"
background := "#1e1e2e"
resultString, err := ansichroma.HightlightString(fileContent, format, style, background)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println(resultString)
}
For detailed documentation and examples, please refer to the GoDoc page.
Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.
This project is licensed under the MIT License - see the LICENSE file for details.