regen

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "regen [flags]",
	Short: "Regenerate colors from previous generation",
	Args:  cobra.NoArgs,
	PreRun: func(cmd *cobra.Command, _ []string) {
		viper.BindPFlags(cmd.Flags())
	},
	RunE: func(_ *cobra.Command, _ []string) error {
		state, err := cache.LoadState()
		if err != nil {
			return fmt.Errorf("failed load current state: %v", err)
		}

		slog.Info("Generating color from cached state", "path", state.Path)

		cfg, err := material.GetConfig()
		if err != nil {
			return err
		}

		colorMap, wu, err := material.GenerateFromQuantized(
			state.Quantized,
			cfg,
		)
		if err != nil {
			return fmt.Errorf("failed to generate colors: %w", err)
		}

		fg, bg := colorMap["on_background"], colorMap["background"]
		based := base16.Generate(fg, bg, wu)

		path := state.Path
		mtype, err := mimetype.DetectFile(state.Path)
		if err == nil && strings.HasPrefix(mtype.String(), "video") {
			if preview, err := cache.GetPreview(path, state.Hash); err == nil {
				path = preview
			}
		}

		output := models.NewOutput(path, based, colorMap)

		if viper.GetBool("json") {
			if err := json.NewEncoder(os.Stdout).Encode(output); err != nil {
				slog.Error("Failed to encode output", "error", err)
			}
		}

		if !viper.GetBool("dry-run") {
			return templates.Execute(output)
		}

		return nil
	},
}

Command is the image command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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