mirror of
				https://github.com/KevinMidboe/motdGO.git
				synced 2025-10-29 17:50:24 +00:00 
			
		
		
		
	added cli client
This commit is contained in:
		| @@ -80,6 +80,7 @@ The default font is `standard`. These are the builtin fonts | ||||
| Other fonts can mainly be found on [figlet](http://www.figlet.org). You have to load them as in [this example](#other-font). | ||||
|  | ||||
| ## Todo | ||||
| - [ ] Cli client | ||||
| - [x] Cli client | ||||
| - [ ] automatic the perfect char margin | ||||
| - [ ] Linebreak possible? | ||||
| - [ ] Colors in the cli client | ||||
| @@ -2,12 +2,56 @@ package main | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	_"flag" | ||||
| 	"flag" | ||||
| 	"log" | ||||
| 	"errors" | ||||
| 	_"github.com/fatih/color" | ||||
| 	_"github.com/probandula/figlet4go" | ||||
| 	"github.com/probandula/figlet4go" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	str *string = flag.String("str", "", "String to be converted with FIGlet") | ||||
| 	font *string = flag.String("font", "", "Font name to use") | ||||
| 	fontpath *string = flag.String("fontpath", "", "Font path to load fonts from") | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	fmt.Println("Hello Figlet") | ||||
| 	// Parse the flags | ||||
| 	flag.Parse() | ||||
|  | ||||
| 	// Validate and log the error | ||||
| 	err := validate() | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	// Create objects | ||||
| 	ascii := figlet4go.NewAsciiRender() | ||||
| 	options := figlet4go.NewRenderOptions() | ||||
|  | ||||
| 	// Load fonts | ||||
| 	if *fontpath != "" { | ||||
| 		ascii.LoadFont(*fontpath) | ||||
| 	} | ||||
|  | ||||
| 	// Set the font | ||||
| 	options.FontName = *font | ||||
|  | ||||
|  | ||||
| 	// Render the string | ||||
| 	renderStr, err := ascii.RenderOpts(*str, options) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	fmt.Println(renderStr) | ||||
| } | ||||
|  | ||||
| // Validate if all required options are given | ||||
| // flag.Parse() must be called before this | ||||
| func validate() error { | ||||
| 	if *str == "" { | ||||
| 		return errors.New("No string given") | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
		Reference in New Issue
	
	Block a user