ansichroma

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MIT Imports: 13 Imported by: 2

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

Installation

To install ansichroma, use go get:

go get github.com/yorukot/ansichroma

Usage

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)
}

Documentation

For detailed documentation and examples, please refer to the GoDoc page.

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 file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HighlightFromFile

func HighlightFromFile(path string, linesToRead int, style, background string) (resultString string, err error)

Hightlight text file. When linesToRead is 0. the complete file is read.

func HightlightString

func HightlightString(fileContent, format string, style, background string) (resultString string, err error)

Hightlight text string.

Types

type NotTextFile

type NotTextFile struct {
	FileName string
}

func (*NotTextFile) Error

func (e *NotTextFile) Error() string

test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL