display in true colors
This commit is contained in:
parent
dc6ec67168
commit
0579adeb80
21
cmd/draw.go
21
cmd/draw.go
|
@ -1,12 +1,14 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/LorenzHohermuth/cli-shapes/internal/color"
|
||||||
|
"github.com/LorenzHohermuth/cli-shapes/internal/renderer"
|
||||||
|
"github.com/LorenzHohermuth/cli-shapes/pkg/image"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,12 +23,27 @@ Cobra is a CLI library for Go that empowers applications.
|
||||||
This application is a tool to generate the needed files
|
This application is a tool to generate the needed files
|
||||||
to quickly create a Cobra application.`,
|
to quickly create a Cobra application.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println("draw called")
|
fileFlag, _ := cmd.Flags().GetString("png")
|
||||||
|
if fileFlag != "" {
|
||||||
|
pix := image.ImageToPixles(fileFlag)
|
||||||
|
s := ""
|
||||||
|
for _, y := range pix {
|
||||||
|
for _, x := range y {
|
||||||
|
color, non := color.GetTrueColor([3]int{x.R, x.G, x.B})
|
||||||
|
char := renderer.GetChar(x.Brightness())
|
||||||
|
s += color + char + non
|
||||||
|
}
|
||||||
|
s += "\n"
|
||||||
|
}
|
||||||
|
fmt.Println(s)
|
||||||
|
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(drawCmd)
|
rootCmd.AddCommand(drawCmd)
|
||||||
|
drawCmd.Flags().String("png", "", "png image")
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
// Here you will define your flags and configuration settings.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/LorenzHohermuth/cli-shapes/internal/color"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// paletteCmd represents the palette command
|
||||||
|
var paletteCmd = &cobra.Command{
|
||||||
|
Use: "palette",
|
||||||
|
Short: "A brief description of your command",
|
||||||
|
Long: `A longer description that spans multiple lines and likely contains examples
|
||||||
|
and usage of using your command. For example:
|
||||||
|
|
||||||
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
|
This application is a tool to generate the needed files
|
||||||
|
to quickly create a Cobra application.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
color.PrintColorPallet()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(paletteCmd)
|
||||||
|
|
||||||
|
// Here you will define your flags and configuration settings.
|
||||||
|
|
||||||
|
// Cobra supports Persistent Flags which will work for this command
|
||||||
|
// and all subcommands, e.g.:
|
||||||
|
// paletteCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||||
|
|
||||||
|
// Cobra supports local flags which will only run when this command
|
||||||
|
// is called directly, e.g.:
|
||||||
|
// paletteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ func PrintColorPallet() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetColor(p [3]int) (string, string) {
|
func GetDefaultColor(p [3]int) (string, string) {
|
||||||
var color string = "\033[39m"
|
var color string = "\033[39m"
|
||||||
var delta float64 = 255
|
var delta float64 = 255
|
||||||
r2 := float64(p[0])
|
r2 := float64(p[0])
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package color
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
//printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
|
||||||
|
|
||||||
|
func GetTrueColor(p [3]int) (string, string) {
|
||||||
|
color := fmt.Sprintf("\x1b[38;2;%d;%d;%dm", p[0], p[1], p[2])
|
||||||
|
return color, "\x1b[0m"
|
||||||
|
}
|
||||||
|
|
19
main.go
19
main.go
|
@ -4,28 +4,9 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/LorenzHohermuth/cli-shapes/cmd"
|
"github.com/LorenzHohermuth/cli-shapes/cmd"
|
||||||
"github.com/LorenzHohermuth/cli-shapes/internal/color"
|
|
||||||
"github.com/LorenzHohermuth/cli-shapes/internal/renderer"
|
|
||||||
"github.com/LorenzHohermuth/cli-shapes/pkg/image"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//pix := image.ImageToPixles("/home/lorenz/Downloads/mushroom-mini.png")
|
|
||||||
//pix := image.ImageToPixles("/home/lorenz/Downloads/rgb.png")
|
|
||||||
pix := image.ImageToPixles("/home/lorenz/Downloads/yoshi.png")
|
|
||||||
s := ""
|
|
||||||
for _, y := range pix {
|
|
||||||
for _, x := range y {
|
|
||||||
color, non := color.GetColor([3]int{x.R, x.G, x.B})
|
|
||||||
char := renderer.GetChar(x.Brightness())
|
|
||||||
s += color + char + non
|
|
||||||
}
|
|
||||||
s += "\n"
|
|
||||||
}
|
|
||||||
fmt.Println(s)
|
|
||||||
color.PrintColorPallet()
|
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue