summaryrefslogtreecommitdiff
path: root/client/help.go
blob: 554034432f7e205e7cc8e2ddc71fcda23157df29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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 {"list", "", "list users in the currently shown channel"},
	helpText {"leave", "", "leave the currently shown channel"},
	helpText {
		"status", "<status>", "set a short status message shown to everyone",
	},
	helpText {"rename", "<name>", "rename the currently shown channel"},
	helpText {"mode", "[(+/-)modes...] <user>",
`change member permissions in channel. +mode adds a mode and -mode removes it. available modes are:
 +see
   read messages in the channel
 +put
   send messages to the channel
 +history
   read messages previously sent in the channel
 +moderate
   kick and ban other users
 +update
   change channel details
 +op
   modify permissions`},
	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
}