Continue with work on the chat component

Using own fork of gocui where I can use my own termui.PollEvent()
This commit is contained in:
erroneousboat 2017-10-07 20:30:45 +02:00
parent 0f930c8297
commit 49f8f185ea
7 changed files with 46 additions and 54 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/jroimartin/gocui"
"github.com/erroneousboat/gocui"
"github.com/erroneousboat/slack-term/service"
)
@ -123,7 +123,7 @@ func (c *Channels) GetSelectedChannel() string {
}
// MoveCursorUp will decrease the SelectedChannel by 1
func (c *Channels) MoveCursorUp(g *gocui.Gui, v *gocui.View) error {
func (c *Channels) MoveCursorUp() error {
if c.SelectedChannel > 0 {
c.SetSelectedChannel(c.SelectedChannel - 1)
c.ScrollUp()
@ -133,7 +133,7 @@ func (c *Channels) MoveCursorUp(g *gocui.Gui, v *gocui.View) error {
}
// MoveCursorDown will increase the SelectedChannel by 1
func (c *Channels) MoveCursorDown(g *gocui.Gui, v *gocui.View) error {
func (c *Channels) MoveCursorDown() error {
if c.SelectedChannel < len(c.Items)-1 {
c.SetSelectedChannel(c.SelectedChannel + 1)
c.ScrollDown()

View File

@ -3,7 +3,7 @@ package components
import (
"fmt"
"github.com/jroimartin/gocui"
"github.com/erroneousboat/gocui"
)
type Chat struct {
@ -53,7 +53,8 @@ func (c *Chat) Refresh() {
}
}
// FIXME: maybe rename to LoadMessages?
// SetMessage will put the provided message into the the Items field
// of the Chat view
func (c *Chat) SetMessages(messages []string) {
for _, msg := range messages {
c.Items = append(c.Items, msg)
@ -63,4 +64,5 @@ func (c *Chat) SetMessages(messages []string) {
// ClearMessages clear the c.Items
func (c *Chat) ClearMessages() {
c.Items = []string{}
c.View.Clear()
}

View File

@ -3,7 +3,7 @@ package components
import (
"fmt"
"github.com/jroimartin/gocui"
"github.com/erroneousboat/gocui"
)
type Debug struct {

View File

@ -1,12 +1,10 @@
package handlers
import (
"log"
"os"
"strconv"
"time"
"github.com/jroimartin/gocui"
termbox "github.com/nsf/termbox-go"
"github.com/erroneousboat/slack-term/context"
@ -43,18 +41,7 @@ func RegisterEventHandlers(ctx *context.AppContext) {
// incomingMessageHandler(ctx)
}
func RegisterKeyBindings(ctx *context.AppContext) {
if err := ctx.View.GUI.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, actionQuit); err != nil {
log.Fatal(err)
}
if err := ctx.View.GUI.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, view.Channels.MoveCursorDown); err != nil {
log.Fatal(err)
}
if err := ctx.View.GUI.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, view.Channels.MoveCursorUp); err != nil {
log.Fatal(err)
}
}
// TODO: add incomingMessageHandler to the select statement
func eventHandler(ctx *context.AppContext) {
go func() {
for {
@ -62,10 +49,12 @@ func eventHandler(ctx *context.AppContext) {
}
}()
go func() {
for {
ev := <-ctx.EventQueue
for {
ctx.View.GUI.Flush()
select {
case ev := <-ctx.EventQueue:
switch ev.Type {
case termbox.EventKey:
actionKeyEvent(ctx, ev)
@ -73,7 +62,9 @@ func eventHandler(ctx *context.AppContext) {
// actionResizeEvent(ctx, ev)
}
}
}()
ctx.View.GUI.Flush()
}
}
// func incomingMessageHandler(ctx *context.AppContext) {
@ -259,7 +250,6 @@ func actionMoveCursorUpChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorUp()
ctx.View.Debug.SetText("test")
timer = time.NewTimer(time.Second / 4)
<-timer.C
@ -275,7 +265,6 @@ func actionMoveCursorDownChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorDown()
ctx.View.Debug.SetText("test")
timer = time.NewTimer(time.Second / 4)
<-timer.C
@ -316,6 +305,8 @@ func actionChangeChannel(ctx *context.AppContext) {
// Set read mark
// ctx.View.Channels.SetReadMark(ctx.Service)
ctx.View.Debug.SetText("hello, world")
// Refresh Chat component
ctx.View.Chat.Refresh()
}

19
main.go
View File

@ -4,11 +4,11 @@ import (
"flag"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os/user"
"path"
"github.com/jroimartin/gocui"
"github.com/erroneousboat/slack-term/context"
"github.com/erroneousboat/slack-term/handlers"
)
@ -57,6 +57,10 @@ func init() {
}
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// Create context
appCTX, err := context.CreateAppContext(flgConfig)
if err != nil {
@ -64,17 +68,6 @@ func main() {
}
defer appCTX.View.GUI.Close()
// Create the view
// view, err := views.CreateView(ctx)
// if err != nil {
// log.Fatal(err)
// }
// defer view.Close()
// Register handlers
handlers.RegisterEventHandlers(appCTX)
if err := appCTX.View.GUI.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Fatal(err)
}
}

12
vendor/vendor.json vendored
View File

@ -2,6 +2,12 @@
"comment": "",
"ignore": "test",
"package": [
{
"checksumSHA1": "68RoiZ+7Vw6FkRuV1ZLHJyFRZlU=",
"path": "github.com/erroneousboat/gocui",
"revision": "0b3eb1f51efeae086da64024a431b69524f67698",
"revisionTime": "2017-10-07T12:13:47Z"
},
{
"checksumSHA1": "En911lu7f/u83ScLGxAaTM2SJVE=",
"path": "github.com/gizak/termui",
@ -33,10 +39,10 @@
"revisionTime": "2017-07-25T12:17:30Z"
},
{
"checksumSHA1": "lqSuR5kZpYqI18/Hfhh3t/SYzPA=",
"checksumSHA1": "GY8G0wn9l4zVTQW9POZCdH+iftM=",
"path": "github.com/nsf/termbox-go",
"revision": "4ed959e0540971545eddb8c75514973d670cf739",
"revisionTime": "2017-07-10T10:34:07Z"
"revision": "d51f2f6d6ccb97dd83ed04ae2f79c34234851f39",
"revisionTime": "2017-09-30T11:41:06Z"
},
{
"checksumSHA1": "7EZyXN0EmZLgGxZxK01IJua4c8o=",

View File

@ -3,8 +3,8 @@ package views
import (
"log"
"github.com/erroneousboat/gocui"
"github.com/gizak/termui"
"github.com/jroimartin/gocui"
"github.com/erroneousboat/slack-term/components"
"github.com/erroneousboat/slack-term/service"
@ -88,17 +88,17 @@ func (v *View) RefreshComponent(name string) {
)
}
func initKeyBindings(view *View) {
if err := view.GUI.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Fatal(err)
}
if err := view.GUI.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, view.Channels.MoveCursorDown); err != nil {
log.Fatal(err)
}
if err := view.GUI.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, view.Channels.MoveCursorUp); err != nil {
log.Fatal(err)
}
}
// func initKeyBindings(view *View) {
// if err := view.GUI.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
// log.Fatal(err)
// }
// if err := view.GUI.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, view.Channels.MoveCursorDown); err != nil {
// log.Fatal(err)
// }
// if err := view.GUI.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, view.Channels.MoveCursorUp); err != nil {
// log.Fatal(err)
// }
// }
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit