コード例 #1
0
ファイル: Goose.go プロジェクト: caohao2008/goose
func (this *Goose) showLogo() string {
	str := "goose"
	ascii := figlet4go.NewAsciiRender()

	// change the font color
	options := figlet4go.NewRenderOptions()
	options.FontColor = make([]color.Attribute, len(str))
	options.FontColor[0] = color.FgMagenta
	options.FontColor[1] = color.FgYellow
	options.FontColor[2] = color.FgBlue
	options.FontColor[3] = color.FgCyan
	options.FontColor[4] = color.FgRed
	renderStr, _ := ascii.RenderOpts(str, options)
	return renderStr
}
コード例 #2
0
ファイル: figlet_netcat.go プロジェクト: leobcn/presentations
func main() {
	flag_str := flag.String("str", "Edmonton  Go", "input string")
	flag.Usage = func() {
		fmt.Println("usage: figlet_nc [-str <string>]  <hostname> <port>")
		os.Exit(0)
	}
	flag.Parse()
	if flag.NArg() != 2 {
		flag.Usage()
	}

	conn, err := net.Dial("tcp", flag.Arg(0)+":"+flag.Arg(1))
	if err != nil {
		fmt.Printf("dial error: %s\n", err)
		os.Exit(-1)
	}

	str := *flag_str
	ascii := figlet4go.NewAsciiRender()

	// change the font color
	colors := [...]color.Attribute{
		color.FgMagenta,
		color.FgYellow,
		color.FgBlue,
		color.FgCyan,
		color.FgRed,
		color.FgWhite,
	}
	options := figlet4go.NewRenderOptions()
	options.FontColor = make([]color.Attribute, len(str))
	for i := range options.FontColor {
		options.FontColor[i] = colors[i%len(colors)]
	}
	renderStr, _ := ascii.RenderOpts(str, options)
	conn.Write([]byte(renderStr))
	fmt.Println("Wrote '"+str+"' to ", conn.RemoteAddr())
}
コード例 #3
0
func (emojiBannerMaker EmojiBannerMaker) Init(config config.Configuration) (commands []slackscot.Action, listeners []slackscot.Action, err error) {
	options := figlet4go.NewRenderOptions()
	renderer := figlet4go.NewAsciiRender()

	if extensionConfig, ok := config.Extentions[emojiBannerMaker.String()]; !ok {
		return nil, nil, errors.New(fmt.Sprintf("Missing extention config for %s", emojiBannerMaker.String()))
	} else {
		if fontPath, ok := extensionConfig[FONT_PATH]; !ok {
			return nil, nil, errors.New(fmt.Sprintf("Missing %s config key: %s", emojiBannerMaker.String(), FONT_PATH))
		} else {
			err := renderer.LoadFont(fontPath)
			if err != nil {
				return nil, nil, errors.New(fmt.Sprintf("[%s] Can't load fonts from [%s]", emojiBannerMaker.String(), fontPath))
			}
			log.Printf("Loaded fonts from [%s]", fontPath)
		}

		if fontName, ok := extensionConfig[FONT_NAME]; !ok {
			return nil, nil, errors.New(fmt.Sprintf("Missing %s config key: %s", emojiBannerMaker.String(), FONT_NAME))
		} else {
			options.FontName = fontName
			log.Printf("Using font name [%s] if it exists", fontName)
		}
	}

	emojiBannerRegex := regexp.MustCompile("(?i)(emoji banner) (.*)")

	commands = append(commands, slackscot.Action{
		Regex:       emojiBannerRegex,
		Usage:       "emoji banner <word> <emoji>",
		Description: "Renders a single-word banner with the provided emoji",
		Answerer: func(message *slack.Message) string {
			return validateAndRenderEmoji(message.Text, emojiBannerRegex, renderer, options)
		},
	})

	return commands, listeners, nil
}