1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-09-15 04:28:07 -04:00

Implemented textarea/reply, adjusted colors

This commit is contained in:
マリウス 2022-12-31 20:58:45 -05:00
parent d07a01df17
commit 826f81a9d9
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 72 additions and 20 deletions

View File

@ -153,7 +153,7 @@ func SetDefaults(cacheDir string) {
viper.SetDefault("Theme.PostsList.List.Focused.Padding",
[]int{1, 1, 1, 1})
viper.SetDefault("Theme.PostsList.List.Focused.Border.Border",
lipgloss.RoundedBorder())
lipgloss.DoubleBorder())
viper.SetDefault("Theme.PostsList.List.Focused.Border.Sides",
[]bool{true, true, true, true},
)
@ -166,7 +166,7 @@ func SetDefaults(cacheDir string) {
viper.SetDefault("Theme.PostsList.List.Blurred.Padding",
[]int{1, 1, 1, 1})
viper.SetDefault("Theme.PostsList.List.Blurred.Border.Border",
lipgloss.RoundedBorder())
lipgloss.DoubleBorder())
viper.SetDefault("Theme.PostsList.List.Blurred.Border.Sides",
[]bool{true, true, true, true},
)
@ -234,7 +234,7 @@ func SetDefaults(cacheDir string) {
[]bool{false, true, true, true},
)
viper.SetDefault("Theme.DialogBox.Window.Border.Foreground",
lipgloss.AdaptiveColor{Light: "#333333", Dark: "#cccccc"})
lipgloss.AdaptiveColor{Light: "#ba55d3", Dark: "#ba55d3"})
// DialogBox Titlebar
viper.SetDefault("Theme.DialogBox.Titlebar.Margin",
@ -244,7 +244,7 @@ func SetDefaults(cacheDir string) {
viper.SetDefault("Theme.DialogBox.Titlebar.Foreground",
lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#000000"})
viper.SetDefault("Theme.DialogBox.Titlebar.Background",
lipgloss.AdaptiveColor{Light: "#333333", Dark: "#cccccc"})
lipgloss.AdaptiveColor{Light: "#da70d6", Dark: "#da70d6"})
// DialogBox Bottombar
viper.SetDefault("Theme.DialogBox.Bottombar.Margin",
@ -273,6 +273,6 @@ func SetDefaults(cacheDir string) {
[]int{0, 1, 0, 1})
viper.SetDefault("Theme.Reply.Author.Foreground",
lipgloss.AdaptiveColor{Light: "#000000", Dark: "#00000"})
viper.SetDefault("Theme.Reply.Author.Foreground",
lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#874BFD"})
viper.SetDefault("Theme.Reply.Author.Background",
lipgloss.AdaptiveColor{Light: "#5f9ea0", Dark: "#5f9ea0"})
}

View File

@ -6,6 +6,7 @@ import (
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
@ -53,6 +54,7 @@ type Model struct {
list list.Model
items []list.Item
viewport viewport.Model
textarea textarea.Model
ctx *ctx.Ctx
a *aggregator.Aggregator
@ -62,7 +64,7 @@ type Model struct {
}
func (m Model) Init() tea.Cmd {
return nil
return m.refresh()
}
func NewModel(c *ctx.Ctx) Model {
@ -83,6 +85,10 @@ func NewModel(c *ctx.Ctx) Model {
m.list = list.New(m.items, listDelegate, 0, 0)
m.list.SetShowTitle(false)
m.list.SetShowStatusBar(false)
m.textarea = textarea.New()
m.textarea.Placeholder = "Type in your reply ..."
m.a, _ = aggregator.New(m.ctx)
return m
@ -95,20 +101,30 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch {
case key.Matches(msg, m.keymap.Refresh):
m.ctx.Loading = true
cmds = append(cmds, m.refresh())
if m.focused == "list" {
m.ctx.Loading = true
cmds = append(cmds, m.refresh())
} else if m.focused == "post" {
m.focused = "reply"
return m, m.textarea.Focus()
}
case key.Matches(msg, m.keymap.Select):
m.ctx.Loading = true
i, ok := m.list.SelectedItem().(post.Post)
if ok {
cmds = append(cmds, m.loadItem(&i))
if m.focused == "list" {
m.ctx.Loading = true
i, ok := m.list.SelectedItem().(post.Post)
if ok {
cmds = append(cmds, m.loadItem(&i))
}
}
case key.Matches(msg, m.keymap.Close):
if m.focused == "post" {
m.focused = "list"
return m, nil
} else if m.focused == "reply" {
m.focused = "post"
return m, nil
}
}
@ -131,7 +147,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
viewportStyle.Height(viewportHeight)
m.viewport = viewport.New(viewportWidth-4, viewportHeight-4)
m.viewport.Width = viewportWidth - 4
m.viewport.Height = viewportHeight - 4
m.viewport.Height = viewportHeight + 1
// cmds = append(cmds, viewport.Sync(m.viewport))
case []list.Item:
@ -152,6 +168,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.list, cmd = m.list.Update(msg)
} else if m.focused == "post" {
m.viewport, cmd = m.viewport.Update(msg)
} else if m.focused == "reply" {
if !m.textarea.Focused() {
cmds = append(cmds, m.textarea.Focus())
}
m.textarea, cmd = m.textarea.Update(msg)
}
cmds = append(cmds, cmd)
@ -172,7 +193,7 @@ func (m Model) View() string {
l,
))
if m.focused == "post" {
if m.focused == "post" || m.focused == "reply" {
titlebar := m.ctx.Theme.DialogBox.Titlebar.
Align(lipgloss.Center).
Width(m.viewport.Width + 4).
@ -189,9 +210,40 @@ func (m Model) View() string {
bottombar,
)
return helpers.PlaceOverlay(3, 2,
tmp := helpers.PlaceOverlay(3, 2,
m.ctx.Theme.DialogBox.Window.Render(ui),
view.String(), true)
view = strings.Builder{}
view.WriteString(tmp)
}
if m.focused == "reply" {
titlebar := m.ctx.Theme.DialogBox.Titlebar.
Align(lipgloss.Center).
Width(m.viewport.Width - 2).
Render("Reply")
m.textarea.SetWidth(m.viewport.Width - 2)
m.textarea.SetHeight(6)
bottombar := m.ctx.Theme.DialogBox.Bottombar.
Width(m.viewport.Width - 2).
Render("ctrl+r reply · esc close")
replyWindow := lipgloss.JoinVertical(
lipgloss.Center,
titlebar,
m.textarea.View(),
bottombar,
)
tmp := helpers.PlaceOverlay(5, m.ctx.Screen[1]-21,
m.ctx.Theme.DialogBox.Window.Render(replyWindow),
view.String(), true)
view = strings.Builder{}
view.WriteString(tmp)
}
return view.String()
@ -275,7 +327,7 @@ func (m *Model) renderReplies(
var author string = ""
if re.Deleted {
body = "\n DELETED"
body = "\n DELETED\n\n"
author = "DELETED"
} else {
body, err = m.glam.Render(re.Body)
@ -291,9 +343,9 @@ func (m *Model) renderReplies(
m.ctx.Theme.Reply.Author.Render(
author,
),
lipgloss.NewStyle().Foreground(lipgloss.Color("#874BFD")).Render(
fmt.Sprintf("writes in reply to %s:", inReplyTo),
),
lipgloss.NewStyle().
Foreground(m.ctx.Theme.Reply.Author.GetBackground()).
Render(fmt.Sprintf("writes in reply to %s:", inReplyTo)),
body,
)