Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yorukot/ansichroma
A general purpose syntax highlighter for ANSI in pure Go
https://github.com/yorukot/ansichroma
go golang highlighter highlighting library syntax-highlighting terminal
Last synced: about 1 month ago
JSON representation
A general purpose syntax highlighter for ANSI in pure Go
- Host: GitHub
- URL: https://github.com/yorukot/ansichroma
- Owner: yorukot
- License: mit
- Created: 2024-05-19T07:20:24.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-19T12:37:11.000Z (8 months ago)
- Last Synced: 2024-07-15T12:22:41.766Z (6 months ago)
- Topics: go, golang, highlighter, highlighting, library, syntax-highlighting, terminal
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ansichroma
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](https://github.com/alecthomas/chroma)
## Installation
To install ansichroma, use go get:```bash
go get github.com/yorukot/ansichroma
```## Usage
```go
go
Copy code
package mainimport (
"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)
}
```
## Documentation
For detailed documentation and examples, please refer to the [GoDoc page](https://pkg.go.dev/github.com/yorukot/ansichroma).## Contributing
Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.## License
This project is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.