Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved syntax highlighting #34

Merged
merged 3 commits into from
Nov 23, 2023
Merged

Improved syntax highlighting #34

merged 3 commits into from
Nov 23, 2023

Conversation

pygrum
Copy link
Collaborator

@pygrum pygrum commented Nov 23, 2023

Changes

Previously, Console used the cobra.Command usage rather than the operand for syntax highlighting. This prevented highlights from being made with commands that had usages with positional arguments, e.g. exit [code].

This change now allows highlighting for such commands, and doesn't affect commands with single word usages - they still highlight.

Example / test script:

package main

import (
        "os"
        "fmt"
        "github.com/reeflective/console"
        "github.com/spf13/cobra"
)

func cmds() *cobra.Command {
        rootCmd := &cobra.Command{}
        exitCmd := &cobra.Command{
                Use: "exit [code]",
                Short: "exit the application",
                Run: func(cmd *cobra.Command, args []string) {
                        os.Exit(0)
                },
        }
        hwCmd := &cobra.Command{
                Use: "hw",
                Short: "print hello world",
                Run: func(cmd *cobra.Command, args []string) {
                        fmt.Println("Hello, World!")
                },
        }
        rootCmd.AddCommand(exitCmd, hwCmd)
        return rootCmd
}

func main(){
        app := console.New("app")
        menu := app.ActiveMenu()
        menu.SetCommands(cmds)
        app.Start()
}

@maxlandon
Copy link
Member

Thanks a lot for this ! Running the workflows and merging !

@maxlandon maxlandon merged commit 973f978 into reeflective:main Nov 23, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants