summaryrefslogtreecommitdiff
path: root/client/help.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/help.go')
-rw-r--r--client/help.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/client/help.go b/client/help.go
new file mode 100644
index 0000000..55509b4
--- /dev/null
+++ b/client/help.go
@@ -0,0 +1,75 @@
+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", "<name>", "change your username"},
+ helpText {"join", "<name>", "join the channel with this name"},
+ helpText {"leave", "", "leave the currently shown channel"},
+ helpText {"create", "<name>", "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
+}