Added features
This commit is contained in:
parent
56827fa470
commit
4bae35793e
9
_examples/kittyImg.go
Normal file
9
_examples/kittyImg.go
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"whspbrd/pkg/render_image"
|
||||
)
|
||||
|
||||
func main() {
|
||||
render_image.RenderImage("../configs/icon.png", 0, 0, 3, 0, true)
|
||||
}
|
||||
@ -14,37 +14,6 @@ import (
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
var chatData ChatData
|
||||
var selectedUserIdx int = 0
|
||||
|
||||
func layoutChat(g *gocui.Gui, maxX, maxY int) error {
|
||||
if v, err := g.SetView("chat", 21, 0, maxX-1, maxY-5); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Chat "
|
||||
v.Wrap = true
|
||||
v.Autoscroll = true
|
||||
updateChatView(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func layoutInput(g *gocui.Gui, maxX, maxY int) error {
|
||||
if v, err := g.SetView("input", 21, maxY-4, maxX-1, maxY-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Type your message: "
|
||||
v.Editable = true
|
||||
v.Wrap = true
|
||||
if _, err := g.SetCurrentView("input"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateChatView(v *gocui.View) {
|
||||
v.Clear()
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@ import (
|
||||
)
|
||||
|
||||
func keybindings(g *gocui.Gui) error {
|
||||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
return err
|
||||
}
|
||||
//if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
// return err
|
||||
//}
|
||||
if err := g.SetKeybinding("input", gocui.KeyEnter, gocui.ModNone, sendMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -20,6 +20,9 @@ func keybindings(g *gocui.Gui) error {
|
||||
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, toggleProfileView); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyCtrlQ, gocui.ModNone, quit); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,14 @@ func layout(g *gocui.Gui) error {
|
||||
if chatView, err := g.View("chat"); err == nil {
|
||||
updateChatView(chatView)
|
||||
}
|
||||
|
||||
//if profileView, err := g.View("profile"); err == nil {
|
||||
// updateProfileView(profileView)
|
||||
//}
|
||||
|
||||
if _, err := g.View("users"); err == nil {
|
||||
updateContactsView(g)
|
||||
}
|
||||
}
|
||||
|
||||
if err := layoutSidebar(g, maxY); err != nil {
|
||||
@ -27,3 +35,61 @@ func layout(g *gocui.Gui) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func layoutChat(g *gocui.Gui, maxX, maxY int) error {
|
||||
if v, err := g.SetView("chat", 21, 0, maxX-1, maxY-5); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Chat "
|
||||
v.Wrap = true
|
||||
v.Autoscroll = true
|
||||
updateChatView(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func layoutInput(g *gocui.Gui, maxX, maxY int) error {
|
||||
if v, err := g.SetView("input", 21, maxY-4, maxX-1, maxY-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Type your message: "
|
||||
v.Editable = true
|
||||
v.Wrap = true
|
||||
if _, err := g.SetCurrentView("input"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func layoutSidebar(g *gocui.Gui, maxY int) error {
|
||||
if v, err := g.SetView("users", 0, 0, 20, maxY-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Users "
|
||||
v.Clear()
|
||||
updateContactsView(g)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func layoutProfile(g *gocui.Gui, maxX, maxY int) error {
|
||||
var VIEW_WIDTH int
|
||||
if maxX-maxX/6 < 21 {
|
||||
VIEW_WIDTH = 50
|
||||
} else {
|
||||
VIEW_WIDTH = maxX - maxX/3
|
||||
}
|
||||
if v, err := g.SetView("profile", VIEW_WIDTH, 0, maxX-1, maxY-5); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Profile "
|
||||
v.Wrap = true
|
||||
//updateProfileView(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
func layoutProfile(g *gocui.Gui, maxX, maxY int) error {
|
||||
var VIEW_WIDTH int
|
||||
if maxX-maxX/6 < 21 {
|
||||
VIEW_WIDTH = 30
|
||||
} else {
|
||||
VIEW_WIDTH = maxX - maxX/6
|
||||
}
|
||||
if v, err := g.SetView("profile", VIEW_WIDTH, 0, maxX-1, maxY-5); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Profile "
|
||||
v.Wrap = true
|
||||
//updateProfileView(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func toggleProfileView(g *gocui.Gui, v *gocui.View) error {
|
||||
if _, err := g.View("profile"); err != nil {
|
||||
layoutProfile(g, prevWidth, prevHeight)
|
||||
} else {
|
||||
g.DeleteView("profile")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
14
internal/tui/profile.go
Normal file
14
internal/tui/profile.go
Normal file
@ -0,0 +1,14 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
func toggleProfileView(g *gocui.Gui, v *gocui.View) error {
|
||||
if _, err := g.View("profile"); err != nil {
|
||||
layoutProfile(g, prevWidth, prevHeight)
|
||||
} else {
|
||||
g.DeleteView("profile")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -15,19 +15,6 @@ import (
|
||||
//"os"
|
||||
)
|
||||
|
||||
// LAYOUT
|
||||
func layoutSidebar(g *gocui.Gui, maxY int) error {
|
||||
if v, err := g.SetView("users", 0, 0, 20, maxY-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
v.Title = " Users "
|
||||
v.Clear()
|
||||
updateContactsView(g)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateContactsView(g *gocui.Gui) error {
|
||||
v, err := g.View("users")
|
||||
if err != nil {
|
||||
|
||||
@ -8,8 +8,8 @@ import (
|
||||
|
||||
var users []string
|
||||
var prevWidth, prevHeight int
|
||||
|
||||
|
||||
var chatData ChatData
|
||||
var selectedUserIdx int = 0
|
||||
|
||||
func Run() {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user