Skip to content

Commit 927a088

Browse files
committed
Make the output of show speaker look nicer
The output for each is colorized, and now it shows the name not the filename. Fixes #114 Signed-off-by: Matt Stratton <[email protected]>
1 parent 9027c28 commit 927a088

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

speaker/speaker.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,43 +264,59 @@ func SpeakerImage(srcPath, speaker, city, year string) (imageFile string) {
264264
func ShowSpeakers(city, year string) (err error) {
265265
var selection string
266266

267-
options, _ := GetSpeakers(city, year)
268-
options = append(options, "Return to Main Menu")
267+
speakerList, _ := GetSpeakers(city, year)
268+
options2, _ := listSpeakerNames(speakerList, city, year)
269+
270+
options2 = append(options2, "Return to Main Menu")
269271
for selection != "Return to Main Menu" {
270272
prompt := &survey.Select{
271273
Message: "Select a speaker:",
272-
Options: options,
274+
Options: options2,
273275
}
274276
survey.AskOne(prompt, &selection, nil)
275277
if selection == "Return to Main Menu" {
276278
return
277279
}
280+
speakerFileName := strings.Join([]string{strings.TrimSpace(names.NameClean(selection)), ".md"}, "")
281+
278282
var mySpeaker model.Speaker
279-
mySpeaker, err = GetSpeakerInfo(selection, city, year)
283+
mySpeaker, err = GetSpeakerInfo(speakerFileName, city, year)
284+
fmt.Println()
280285
color.Cyan("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+")
281-
fmt.Println("Name is " + mySpeaker.Title)
286+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("Name: "), color.GreenString(mySpeaker.Title))
287+
282288
if mySpeaker.Website != "" {
283-
fmt.Println("Website is " + mySpeaker.Website)
289+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("WebsiteName: "), color.GreenString(mySpeaker.Website))
284290
}
285291
if mySpeaker.Twitter != "" {
286-
fmt.Println("Twitter is @" + mySpeaker.Twitter)
292+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("Twitter: "), color.GreenString(fmt.Sprintf("@%s", mySpeaker.Twitter)))
287293
}
288294
if mySpeaker.Facebook != "" {
289-
fmt.Println("Facebook is " + mySpeaker.Facebook)
295+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("Facebook: "), color.GreenString(mySpeaker.Facebook))
290296
}
291297
if mySpeaker.Linkedin != "" {
292-
fmt.Println("Website is " + mySpeaker.Linkedin)
298+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("LinkedIn: "), color.GreenString(mySpeaker.Linkedin))
293299
}
294300
if mySpeaker.Github != "" {
295-
fmt.Println("Github is @" + mySpeaker.Github)
301+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("GitHub: "), color.GreenString(mySpeaker.Github))
296302
}
297303
if mySpeaker.Gitlab != "" {
298-
fmt.Println("Gitlab is " + mySpeaker.Gitlab)
304+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("GitLab: "), color.GreenString(mySpeaker.Gitlab))
299305
}
300306
if mySpeaker.Bio != "" {
301-
fmt.Println("Bio is " + mySpeaker.Bio)
307+
fmt.Fprintf(color.Output, "%s %s\n", color.CyanString("Bio: "), color.GreenString(mySpeaker.Bio))
302308
}
303309
color.Cyan("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+")
310+
fmt.Println()
311+
}
312+
return
313+
}
314+
315+
func listSpeakerNames(speakers []string, city string, year string) (speakerFullNames []string, err error) {
316+
for _, f := range speakers {
317+
var mySpeaker model.Speaker
318+
mySpeaker, err = GetSpeakerInfo(f, city, year)
319+
speakerFullNames = append(speakerFullNames, mySpeaker.Title)
304320
}
305321
return
306322
}

speaker/speaker_utils.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package speaker
22

33
import (
4-
"fmt"
54
"io/ioutil"
65
"log"
76
"path/filepath"
@@ -19,14 +18,12 @@ func GetSpeakers(city, year string) ([]string, error) {
1918

2019
speakerdir := filepath.Join(paths.EventContentPath(city, year), "speakers")
2120

22-
fmt.Println(speakerdir)
2321
files, err := ioutil.ReadDir(speakerdir)
2422

2523
if err != nil {
2624
return nil, errors.Wrap(err, "read speaker directory failed")
2725
}
2826
var s []string
29-
// s := make([]string, len(files))
3027
for _, f := range files {
3128
s = append(s, f.Name())
3229
}
@@ -35,22 +32,8 @@ func GetSpeakers(city, year string) ([]string, error) {
3532

3633
func GetSpeakerInfo(file, city, year string) (speaker model.Speaker, err error) {
3734

38-
// speakerPerson := `+++
39-
// Website = ""
40-
// Title = "Rainbow Dash"
41-
// Twitter = ""
42-
// date = "2016-12-08T20:55:58-06:00"
43-
// Type = "speaker"
44-
// Image = "rainbow-dash.png"
45-
// Facebook = ""
46-
// Linkedin = ""
47-
// Pronouns = ""
48-
// +++
49-
// Food-truck SpaceTeam pivot
50-
// `
5135
filePath := filepath.Join(paths.EventContentPath(city, year), "speakers", file)
5236
dat, err := ioutil.ReadFile(filePath)
53-
// lines.WriteTo(os.Stdout)
5437
m := front.NewMatter()
5538
m.Handle("+++", TOMLHandler)
5639

@@ -78,20 +61,6 @@ func GetSpeakerInfo(file, city, year string) (speaker model.Speaker, err error)
7861
// TOMLHandler decodes ymal string into a go map[string]interface{}
7962
func TOMLHandler(front string) (map[string]interface{}, error) {
8063

81-
// type thing struct {
82-
// Name string
83-
// Title string
84-
// Website string `toml:"website,omitempty"`
85-
// Twitter string `toml:"twitter,omitempty"`
86-
// Facebook string `toml:"facebook,omitempty"`
87-
// Linkedin string `toml:"linkedin,omitempty"`
88-
// Github string `toml:"github,omitempty"`
89-
// Gitlab string `toml:"gitlab,omitempty"`
90-
// ImagePath string `toml:"image,omitempty"`
91-
// Bio string
92-
// }
93-
94-
// var stuff thing
9564
var stuff model.Speaker
9665
if _, err := toml.Decode(front, &stuff); err != nil {
9766
log.Fatal(err)

testdata/content/events/2017-ponyville/speakers/matt-stratton.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ twitter = "mattstratton"
66
facebook = "https://www.facebook.com/matt.stratton"
77
linkedin = "https://www.linkedin.com/in/mattstratton/"
88
github = "mattstratton"
9-
gitlab = "mattstratton"image = "matt-stratton.jpg"
9+
gitlab = "mattstratton"
10+
image = "matt-stratton.jpg"
1011
+++
1112

0 commit comments

Comments
 (0)