1
0
Fork 0

Implemented draft Dialog in TK

This commit is contained in:
マリウス 2023-01-03 15:02:43 -05:00
parent be62b30a59
commit 8e57103040
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 55 additions and 33 deletions

43
ui/toolkit/dialog.go Normal file
View File

@ -0,0 +1,43 @@
package toolkit
import (
"strings"
"github.com/charmbracelet/lipgloss"
)
func (tk *ToolKit) Dialog(title string, content string) string {
var view strings.Builder = strings.Builder{}
var style lipgloss.Style
if tk.IsFocused() {
style = tk.theme.DialogBox.Titlebar.Focused
} else {
style = tk.theme.DialogBox.Titlebar.Blurred
}
titlebar := style.Align(lipgloss.Center).
Width(tk.ViewWidth()).
Render(title)
bottombar := tk.theme.DialogBox.Bottombar.
Width(tk.ViewWidth()).
Render("[#]r reply · esc close") // TODO
ui := lipgloss.JoinVertical(
lipgloss.Center,
titlebar,
content,
bottombar,
)
var tmp string
if tk.IsFocused() {
tmp = tk.theme.DialogBox.Window.Focused.Render(ui)
} else {
tmp = tk.theme.DialogBox.Window.Blurred.Render(ui)
}
view.WriteString(tmp)
return view.String()
}

View File

@ -3,6 +3,7 @@ package toolkit
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/mrusme/gobbs/ui/cmd"
"github.com/mrusme/gobbs/ui/theme"
"go.uber.org/zap"
)
@ -10,6 +11,7 @@ type ViewFunc func(m interface{}, cached bool) string
type ToolKit struct {
winID string
theme *theme.Theme
logger *zap.SugaredLogger
m interface{}
@ -20,9 +22,10 @@ type ToolKit struct {
viewcache string
}
func New(winID string, l *zap.SugaredLogger) *ToolKit {
func New(winID string, t *theme.Theme, l *zap.SugaredLogger) *ToolKit {
tk := new(ToolKit)
tk.winID = winID
tk.theme = t
tk.logger = l
tk.wh = [2]int{0, 0}

View File

@ -65,8 +65,12 @@ func (m Model) Init() tea.Cmd {
func NewModel(c *ctx.Ctx) Model {
m := Model{
ctx: c,
tk: toolkit.New(WIN_ID, c.Logger),
ctx: c,
tk: toolkit.New(
WIN_ID,
c.Theme,
c.Logger,
),
keymap: DefaultKeyMap,
buffer: "",
@ -222,7 +226,6 @@ func (m Model) View() string {
func buildView(mi interface{}, cached bool) string {
var m *Model = mi.(*Model)
var view strings.Builder = strings.Builder{}
if cached && !m.tk.IsFocused() && m.tk.IsCached() {
m.ctx.Logger.Debugln("Cached View()")
@ -232,37 +235,10 @@ func buildView(mi interface{}, cached bool) string {
m.ctx.Logger.Debugln("View()")
m.ctx.Logger.Debugf("IsFocused: %v\n", m.tk.IsFocused())
var style lipgloss.Style
if m.tk.IsFocused() {
style = m.ctx.Theme.DialogBox.Titlebar.Focused
} else {
style = m.ctx.Theme.DialogBox.Titlebar.Blurred
}
titlebar := style.Align(lipgloss.Center).
Width(m.tk.ViewWidth()).
Render("Post")
bottombar := m.ctx.Theme.DialogBox.Bottombar.
Width(m.tk.ViewWidth()).
Render("[#]r reply · esc close")
ui := lipgloss.JoinVertical(
lipgloss.Center,
titlebar,
return m.tk.Dialog(
"Post",
viewportStyle.Render(m.viewport.View()),
bottombar,
)
var tmp string
if m.tk.IsFocused() {
tmp = m.ctx.Theme.DialogBox.Window.Focused.Render(ui)
} else {
tmp = m.ctx.Theme.DialogBox.Window.Blurred.Render(ui)
}
view.WriteString(tmp)
return view.String()
}
func (m *Model) renderViewport(p *post.Post) string {