diff --git a/cmd/root.go b/cmd/root.go index edd0037..dca055d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,31 +23,99 @@ THE SOFTWARE. package cmd import ( + "encoding/json" "fmt" + "net/http" "os" + "strings" + "github.com/TheZoraiz/ascii-image-converter/aic_package" + "github.com/fatih/color" "github.com/spf13/cobra" ) +type GitHubUser struct { + Login string `json:"login"` + Name string `json:"name"` + Repos int `json:"public_repos"` + Followers int `json:"followers"` + Following int `json:"following"` +} + +var username string +var highlightColor string + // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "ghfetch", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. 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.`, - // Uncomment the following line if your bare application - // has an action associated with it: + Short: "Fetch GitHub user's profile", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("rootCmd called") + if username == "" { + fmt.Println("Please provide a GitHub username using the --user flag.") + return + } + + flags := aic_package.DefaultFlags() + flags.Dimensions = []int{50, 25} + flags.Colored = true + flags.CustomMap = " .-=+#@" + asciiArt, err := aic_package.Convert(fmt.Sprintf("https://github.com/%s.png", username), flags) + if err != nil { + fmt.Println(err) + return + } + asciiLines := strings.Split(asciiArt, "\n") + + user, err := fetchUser(username) + if err != nil { + fmt.Println("Error fetching user information:", err) + return + } + titleColor := colorMap[highlightColor].SprintFunc() + infoColor := color.New(color.FgWhite).SprintFunc() + + // Displaying username at the top + fmt.Printf("%s %s: %s\n", asciiLines[0], titleColor("GitHub User"), titleColor(user.Login)) + + userInfo := []string{ + fmt.Sprintf("Name: %s", user.Name), + fmt.Sprintf("Repos: %d", user.Repos), + fmt.Sprintf("Followers: %d", user.Followers), + fmt.Sprintf("Following: %d", user.Following), + } + + for i := 1; i < len(asciiLines) || i-1 < len(userInfo); i++ { + left := "" + if i < len(asciiLines) { + left = asciiLines[i] + } + right := "" + if i-1 < len(userInfo) { + splitted := strings.Split(userInfo[i-1], ": ") + right = titleColor(splitted[0]) + ": " + infoColor(splitted[1]) + } + fmt.Printf("%-60s %s\n", left, right) + } }, } +func fetchUser(username string) (*GitHubUser, error) { + url := fmt.Sprintf("https://api.github.com/users/%s", username) + resp, err := http.Get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var user GitHubUser + err = json.NewDecoder(resp.Body).Decode(&user) + if err != nil { + return nil, err + } + return &user, nil +} + // Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { @@ -56,13 +124,17 @@ func Execute() { } func init() { - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ghfetch.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.Flags().StringVarP(&username, "user", "u", "", "GitHub username") + rootCmd.Flags().StringVarP(&highlightColor, "color", "c", "blue", "Highlight color for text") +} + +// Color map for user-specified colors +var colorMap = map[string]*color.Color{ + "red": color.New(color.FgRed), + "green": color.New(color.FgGreen), + "yellow": color.New(color.FgYellow), + "blue": color.New(color.FgBlue), + "magenta": color.New(color.FgMagenta), + "cyan": color.New(color.FgCyan), } diff --git a/cmd/user.go b/cmd/user.go deleted file mode 100644 index 82ad26c..0000000 --- a/cmd/user.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright © 2023 Takafumi Miyanaga - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -package cmd - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -// userCmd represents the user command -var userCmd = &cobra.Command{ - Use: "user", - 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) { - fmt.Println("user called") - }, -} - -func init() { - rootCmd.AddCommand(userCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // userCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // userCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") -} diff --git a/go.mod b/go.mod index 8340328..9aa2e08 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,24 @@ module github.com/orangekame3/ghfetch go 1.21.0 -require github.com/spf13/cobra v1.7.0 +require ( + github.com/TheZoraiz/ascii-image-converter v1.13.1 + github.com/fatih/color v1.15.0 + github.com/spf13/cobra v1.7.0 +) require ( + github.com/disintegration/imaging v1.6.2 // indirect + github.com/fogleman/gg v1.3.0 // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect + github.com/gookit/color v1.4.2 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/makeworld-the-better-one/dither/v2 v2.2.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect + github.com/nathan-fiscaletti/consolesize-go v0.0.0-20210105204122-a87d9f614b9d // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect + golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect + golang.org/x/sys v0.6.0 // indirect ) diff --git a/go.sum b/go.sum index f3366a9..8f3789d 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,52 @@ +github.com/TheZoraiz/ascii-image-converter v1.13.1 h1:lGgOd8obT7hgTF6JDkz1v213/pBHZMtQxxJcEHWjp6I= +github.com/TheZoraiz/ascii-image-converter v1.13.1/go.mod h1:OdQ0YlyFkUN/h9Hu2OU4cSoAMZf/5J5pOEGeU0TPVsA= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= +github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= +github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk= +github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/makeworld-the-better-one/dither/v2 v2.2.0 h1:VTMAiyyO1YIO07fZwuLNZZasJgKUmvsIA48ze3ALHPQ= +github.com/makeworld-the-better-one/dither/v2 v2.2.0/go.mod h1:VBtN8DXO7SNtyGmLiGA7IsFeKrBkQPze1/iAeM95arc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/nathan-fiscaletti/consolesize-go v0.0.0-20210105204122-a87d9f614b9d h1:PQW4Aqovdqc9efHl9EVA+bhKmuZ4ME1HvSYYDvaDiK0= +github.com/nathan-fiscaletti/consolesize-go v0.0.0-20210105204122-a87d9f614b9d/go.mod h1:cxIIfNMTwff8f/ZvRouvWYF6wOoO7nj99neWSx2q/Es= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= +golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/orangekame3-ascii-art.png b/orangekame3-ascii-art.png new file mode 100644 index 0000000..0114549 Binary files /dev/null and b/orangekame3-ascii-art.png differ diff --git a/orangekame3-ascii-art.txt b/orangekame3-ascii-art.txt new file mode 100644 index 0000000..cf5f495 --- /dev/null +++ b/orangekame3-ascii-art.txt @@ -0,0 +1,25 @@ + ..--===++=-. + .++++++++++++= + ..-==++++++#- + =#+++++ .-=+++- + .=-----. =#+++++++ + .. +++++++++==..++#++++++ + -=+##-=#+##########-.=+###+. + -+###+#+.+######+##+--==-=-. + -+##+++##+.-==+++##+--+###+ + =#++++##+=-++++====--+####+#= + .+++###+=-=#########=-#+######..-... + .======--=############.+#####+#-.###++=. + .----. =#+++++.+#+###########+.#######.-#++++##- + =++++++ =+++++#=-#+###########+.-==++++ =++++++++ +=++++++= +++++++#-=##########+--++++=== =#+++= +-=--... =++++++#= =+++####+--+#######- ++++- + -++++++--========--+##++++#+- -+++ + =++=--=+#####++=.+#+++##+= =+. + ..-=++++++++++#=-####+-. + .=+++++++++##+.==-. + ..--=----.. + .+==+- + +++++= + -+++++- + -==--. \ No newline at end of file