Skip to content

Commit

Permalink
added chroma
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Mar 27, 2023
1 parent ec4c0fc commit ed0630e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
64 changes: 64 additions & 0 deletions completers/chroma_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/chroma"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "chroma",
Short: "Chroma is a general purpose syntax highlighter",
Long: "https://github.com/alecthomas/chroma",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}

func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().Bool("check", false, "Do not format, check for tokenisation errors instead.")
rootCmd.Flags().Bool("fail", false, "Exit silently with status 1 if no specific lexer was found.")
rootCmd.Flags().String("filename", "", "Filename to use for selecting a lexer when reading from stdin.")
rootCmd.Flags().StringP("formatter", "f", "", "Formatter to use.")
rootCmd.Flags().BoolP("help", "h", false, "Show context-sensitive help.")
rootCmd.Flags().Bool("html", false, "Convenience flag to use HTML formatter.")
rootCmd.Flags().Bool("html-all-styles", false, "Output all HTML CSS styles, including redundant ones.")
rootCmd.Flags().String("html-base-line", "", "Base line number.")
rootCmd.Flags().String("html-highlight", "", "Highlight these lines.")
rootCmd.Flags().String("html-highlight-style", "", "Style used for highlighting lines.")
rootCmd.Flags().Bool("html-inline-styles", false, "Output HTML with inline styles (no classes).")
rootCmd.Flags().Bool("html-lines", false, "Include line numbers in output.")
rootCmd.Flags().String("html-lines-style", "", "Style for line numbers.")
rootCmd.Flags().Bool("html-lines-table", false, "Split line numbers and code in a HTML table")
rootCmd.Flags().Bool("html-linkable-lines", false, "Make the line numbers linkable and be a link to themselves.")
rootCmd.Flags().Bool("html-only", false, "Output HTML fragment.")
rootCmd.Flags().String("html-prefix", "", "HTML CSS class prefix.")
rootCmd.Flags().Bool("html-prevent-surrounding-pre", false, "Prevent the surrounding pre tag.")
rootCmd.Flags().Bool("html-styles", false, "Output HTML CSS styles.")
rootCmd.Flags().String("html-tab-width", "", "Set the HTML tab width.")
rootCmd.Flags().Bool("json", false, "Convenience flag to use JSON formatter.")
rootCmd.Flags().StringP("lexer", "l", "", "Lexer to use when formatting or path to an XML file to load.")
rootCmd.Flags().Bool("list", false, "List lexers, styles and formatters.")
rootCmd.Flags().String("profile", "", "Enable profiling to file.")
rootCmd.Flags().StringP("style", "s", "", "Style to use for formatting or path to an XML file to load.")
rootCmd.Flags().Bool("svg", false, "Convenience flag to use SVG formatter.")
rootCmd.Flags().Bool("trace", false, "Trace lexer states as they are traversed.")
rootCmd.Flags().Bool("unbuffered", false, "Do not buffer output.")
rootCmd.Flags().Bool("version", false, "Show version.")
rootCmd.Flags().String("xml", "", "Generate XML lexer definitions.")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"formatter": chroma.ActionFormatters(),
"lexer": chroma.ActionLexers(),
"profile": carapace.ActionFiles(),
"xml": carapace.ActionDirectories(),
})

carapace.Gen(rootCmd).PositionalAnyCompletion(
carapace.ActionFiles(),
)
}
7 changes: 7 additions & 0 deletions completers/chroma_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/chroma_completer/cmd"

func main() {
cmd.Execute()
}
22 changes: 22 additions & 0 deletions pkg/actions/tools/chroma/formatter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package chroma

import "github.com/rsteube/carapace"

// ActionFormatters completes formatters
//
// html
// json
func ActionFormatters() carapace.Action {
return carapace.ActionValues(
"html",
"json",
"noop",
"svg",
"terminal",
"terminal16",
"terminal16m",
"terminal256",
"terminal8",
"tokens",
)
}

0 comments on commit ed0630e

Please sign in to comment.