package main import ( "citrons.xyz/talk/tui" "strconv" ) type helpText struct { command string usage string description string } var helpTexts = []helpText { helpText {"help", "[command]", "view/list command descriptions"}, helpText {"nick", "", "change your username"}, helpText {"join", "", "join the channel with this name"}, helpText {"list", "", "list users in the currently shown channel"}, helpText {"leave", "", "leave the currently shown channel"}, helpText {"create", "", "create a channel with this name"}, helpText {"quit", "", "exit the application"}, } type helpMsg struct { index int help []helpText } func (h helpMsg) Id() string { return "help." + strconv.Itoa(h.index) } func (h helpMsg) Show(odd bool) { style := &tui.Style {Bg: colorCmd[odd], Fg: tui.White} tui.Push("", tui.Box { Width: tui.Fill, Height: tui.Children, Style: style, Dir: tui.Right, }) tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize}) tui.Text("* ", nil) tui.Pop() tui.Push("", tui.Box {Width: tui.Fill, Height: tui.Children}) for _, h := range h.help { tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize}) tui.Text("/", nil) tui.Text(h.command, nil) tui.Text(" ", nil) tui.Text(h.usage, nil) tui.Pop() tui.Push("", tui.Box { Width: tui.Fill, Height: tui.TextSize, Margins: [4]int {2, 0, 0, 0}, }) tui.Text(h.description, nil) tui.Pop() } tui.Pop() tui.Pop() } func getHelp(command string) (helpMsg, bool) { lastIndex++ if command == "" { return helpMsg {lastIndex, helpTexts}, true } else { for _, h := range helpTexts { if h.command == command { return helpMsg {lastIndex, []helpText {h}}, true } } } return helpMsg{}, false }