Add help command
This commit is contained in:
32
cmdHelp.go
Normal file
32
cmdHelp.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// +build !rm_basic_commands allcommands helpcmd
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/jroimartin/gocui"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
command := Command{
|
||||||
|
Cmd: []string{"help", "h"},
|
||||||
|
Description: "Show information about avaailable commands",
|
||||||
|
Help: "",
|
||||||
|
Exec: cmdHelp,
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterCommand(command)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdHelp(g *gocui.Gui, cmd []string) {
|
||||||
|
var helpText string
|
||||||
|
if len(cmd) == 1 {
|
||||||
|
sort.Strings(baseCommands)
|
||||||
|
for _, c := range baseCommands {
|
||||||
|
helpText = fmt.Sprintf("%s%s%s\t\t%s\n", helpText, cmdPrefix, c, commands[c].Description)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printToView(g, "Chat", helpText)
|
||||||
|
}
|
||||||
27
main.go
27
main.go
@ -11,11 +11,6 @@ import (
|
|||||||
"samhofi.us/x/keybase"
|
"samhofi.us/x/keybase"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cmdPrefix = "/"
|
|
||||||
|
|
||||||
var commands = make(map[string]Command)
|
|
||||||
var baseCommands = make([]string, 0)
|
|
||||||
|
|
||||||
// Configurable section
|
// Configurable section
|
||||||
var downloadPath = "/tmp/"
|
var downloadPath = "/tmp/"
|
||||||
var outputFormat = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
var outputFormat = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
@ -28,6 +23,11 @@ var timeFormat = "15:04"
|
|||||||
|
|
||||||
// End configurable section
|
// End configurable section
|
||||||
|
|
||||||
|
const cmdPrefix = "/"
|
||||||
|
|
||||||
|
var commands = make(map[string]Command)
|
||||||
|
var baseCommands = make([]string, 0)
|
||||||
|
|
||||||
var k = keybase.NewKeybase()
|
var k = keybase.NewKeybase()
|
||||||
var channel keybase.Channel
|
var channel keybase.Channel
|
||||||
var channels []keybase.Channel
|
var channels []keybase.Channel
|
||||||
@ -47,7 +47,6 @@ func main() {
|
|||||||
defer kbtui.Close()
|
defer kbtui.Close()
|
||||||
kbtui.SetManagerFunc(layout)
|
kbtui.SetManagerFunc(layout)
|
||||||
|
|
||||||
printToView(kbtui, "Chat", fmt.Sprintf("Welcome %s!", k.Username))
|
|
||||||
go populateList(kbtui)
|
go populateList(kbtui)
|
||||||
go updateChatWindow(kbtui)
|
go updateChatWindow(kbtui)
|
||||||
if err := initKeybindings(kbtui); err != nil {
|
if err := initKeybindings(kbtui); err != nil {
|
||||||
@ -214,15 +213,8 @@ func layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
chatView.Autoscroll = true
|
chatView.Autoscroll = true
|
||||||
chatView.Wrap = true
|
chatView.Wrap = true
|
||||||
fmt.Fprintf(chatView, "Your chats will appear here.\nSupported commands are as follows:\n")
|
fmt.Fprintf(chatView, "Welcome %s!\n\nYour chats will appear here.\nSupported commands are as follows:\n\n", k.Username)
|
||||||
fmt.Fprintln(chatView, "/j $username - Open your chat with $username")
|
RunCommand(g, "help")
|
||||||
fmt.Fprintln(chatView, "/j $team $channel - Open $channel from $team")
|
|
||||||
fmt.Fprintln(chatView, "/u $path $title - Uploads file $path with title $title")
|
|
||||||
fmt.Fprintln(chatView, "/d $msgId $downloadName - Downloads file from $msgId to $DownloadPath/$downloadName")
|
|
||||||
fmt.Fprintln(chatView, "/r $msgId $reaction - Reacts to $msgId with $reaction reaction can be emoji :+1:")
|
|
||||||
fmt.Fprintln(chatView, " Can also be used for STRING reactions")
|
|
||||||
fmt.Fprintln(chatView, "/s - Experimental: View all incoming messages from everywhere.")
|
|
||||||
fmt.Fprintln(chatView, "/q - Exit")
|
|
||||||
}
|
}
|
||||||
if inputView, err3 := g.SetView("Input", maxX/2-maxX/3, maxY-4, maxX-1, maxY-1); err3 != nil {
|
if inputView, err3 := g.SetView("Input", maxX/2-maxX/3, maxY-4, maxX-1, maxY-1); err3 != nil {
|
||||||
if err3 != gocui.ErrUnknownView {
|
if err3 != gocui.ErrUnknownView {
|
||||||
@ -399,3 +391,8 @@ func RegisterCommand(c Command) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunCommand calls a command as if it was run by the user
|
||||||
|
func RunCommand(g *gocui.Gui, c ...string) {
|
||||||
|
commands[c[0]].Exec(g, c)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user