diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-01 17:15:44 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-01 17:15:44 -0500 |
| commit | ccea376f5750629c2a82b1f24251e52756876f5d (patch) | |
| tree | 0f47b09325d56625bbae4596ace2a5f63bb5985e /client/help.go | |
| parent | 397b8de9c2a590f98c1a3255a6dbe7570a7b70b8 (diff) | |
help command
Diffstat (limited to 'client/help.go')
| -rw-r--r-- | client/help.go | 75 |
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 +} |
