Browse Source

Merge branch 'feature/commands' of keybase://team/dxb_.rudi9719/kbtui into feature/commands

pull/1/head
Gregory Rudolph 5 years ago
parent
commit
339bd1e6ce
  1. 32
      cmdHelp.go
  2. 27
      main.go

32
cmdHelp.go

@ -0,0 +1,32 @@ @@ -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

@ -11,11 +11,6 @@ import ( @@ -11,11 +11,6 @@ import (
"samhofi.us/x/keybase"
)
const cmdPrefix = "/"
var commands = make(map[string]Command)
var baseCommands = make([]string, 0)
// Configurable section
var downloadPath = "/tmp/"
var outputFormat = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
@ -28,6 +23,11 @@ var timeFormat = "15:04" @@ -28,6 +23,11 @@ var timeFormat = "15:04"
// End configurable section
const cmdPrefix = "/"
var commands = make(map[string]Command)
var baseCommands = make([]string, 0)
var k = keybase.NewKeybase()
var channel keybase.Channel
var channels []keybase.Channel
@ -47,7 +47,6 @@ func main() { @@ -47,7 +47,6 @@ func main() {
defer kbtui.Close()
kbtui.SetManagerFunc(layout)
printToView(kbtui, "Chat", fmt.Sprintf("Welcome %s!", k.Username))
go populateList(kbtui)
go updateChatWindow(kbtui)
if err := initKeybindings(kbtui); err != nil {
@ -214,15 +213,8 @@ func layout(g *gocui.Gui) error { @@ -214,15 +213,8 @@ func layout(g *gocui.Gui) error {
}
chatView.Autoscroll = true
chatView.Wrap = true
fmt.Fprintf(chatView, "Your chats will appear here.\nSupported commands are as follows:\n")
fmt.Fprintln(chatView, "/j $username - Open your chat with $username")
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")
fmt.Fprintf(chatView, "Welcome %s!\n\nYour chats will appear here.\nSupported commands are as follows:\n\n", k.Username)
RunCommand(g, "help")
}
if inputView, err3 := g.SetView("Input", maxX/2-maxX/3, maxY-4, maxX-1, maxY-1); err3 != nil {
if err3 != gocui.ErrUnknownView {
@ -399,3 +391,8 @@ func RegisterCommand(c Command) error { @@ -399,3 +391,8 @@ func RegisterCommand(c Command) error {
}
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)
}

Loading…
Cancel
Save