1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00

Implemented ErrorDialog, added selection to header

This commit is contained in:
マリウス 2023-01-04 19:13:04 -05:00
parent 0fe810871e
commit 9b56ea8d07
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
5 changed files with 76 additions and 10 deletions

View File

@ -230,7 +230,7 @@ func SetDefaults(cacheDir string) {
[]bool{false, true, true, true},
)
viper.SetDefault("Theme.ErrorDialogBox.Window.Focused.Border.Foreground",
lipgloss.AdaptiveColor{Light: "#00ffff", Dark: "#00ffff"})
lipgloss.AdaptiveColor{Light: "#dc143c", Dark: "#dc143c"})
// ErrorDialogBox Window:Blurred
viper.SetDefault("Theme.ErrorDialogBox.Window.Blurred.Margin",
@ -253,7 +253,7 @@ func SetDefaults(cacheDir string) {
viper.SetDefault("Theme.ErrorDialogBox.Titlebar.Focused.Foreground",
lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#000000"})
viper.SetDefault("Theme.ErrorDialogBox.Titlebar.Focused.Background",
lipgloss.AdaptiveColor{Light: "#00cccc", Dark: "#00cccc"})
lipgloss.AdaptiveColor{Light: "#dc143c", Dark: "#dc143c"})
// ErrorDialogBox Titlebar:Blurred
viper.SetDefault("Theme.ErrorDialogBox.Titlebar.Blurred.Margin",

View File

@ -1,6 +1,7 @@
package header
import (
"github.com/mrusme/gobbs/config"
"github.com/mrusme/gobbs/ui/ctx"
"github.com/charmbracelet/bubbles/spinner"
@ -13,7 +14,8 @@ var (
banner = "▄▗▖▎▄▗▅▖▗▅▅▖▗▅▅▖▅▅▅▖▏▉▅▅┓▅▖▎▗▅▌\n" +
"▗▎▍▄▗▗▎▏▍▝▝▘▍▝▂▉┈▂▎▍▅▋▊▂╴▏▊▗╴▋▎\n" +
"▊▉▌╴▘▁▏▏▅▆┈▏▉▇▆▌▗▖▍▎▃▎▎▅▋▋▎▗▎▍▘\n" +
"▝▄▄▄▘▇▄▆▄▄▄▝▄▄▘▝▘▝▘▏╴▄▘▄▝▘▇╴▄▘▄"
"▝▄▄▄▘▇▄▆▄▄▄▝▄▄▘▝▘▝▘▏╴▄▘▄▝▘▇╴▄▘▄\n" +
" v" + config.VERSION
)
type Model struct {
@ -58,12 +60,32 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
func (m Model) View() string {
var row string
var spinner string = ""
if m.ctx.Loading == false {
row = lipgloss.JoinHorizontal(lipgloss.Top, banner)
} else {
row = lipgloss.JoinHorizontal(lipgloss.Top, banner, " ", m.spinner.View())
selector := lipgloss.NewStyle().
Foreground(lipgloss.Color("#7fffd4")).
BorderForeground(lipgloss.Color("#7fffd4")).
Border(lipgloss.NormalBorder()).
Padding(0, 1, 0, 1).
Width(40)
systemSelector := selector.Render("⏷ All")
forumSelector := selector.Render("⏷ All")
selectorColumn := lipgloss.JoinVertical(lipgloss.Center,
lipgloss.JoinHorizontal(lipgloss.Bottom, "System: \n "+
lipgloss.NewStyle().Foreground(m.ctx.Theme.DialogBox.Bottombar.GetForeground()).Render("c-s"),
systemSelector),
lipgloss.JoinHorizontal(lipgloss.Bottom, "Forum: \n "+
lipgloss.NewStyle().Foreground(m.ctx.Theme.DialogBox.Bottombar.GetForeground()).Render("c-f"),
forumSelector),
)
if m.ctx.Loading == true {
spinner = m.spinner.View()
}
row = lipgloss.JoinHorizontal(lipgloss.Top, banner, " ", selectorColumn, " ", spinner)
return row
}

View File

@ -49,3 +49,47 @@ func (tk *ToolKit) Dialog(title string, content string) string {
return view.String()
}
func (tk *ToolKit) ErrorDialog(title string, content string) string {
var view strings.Builder = strings.Builder{}
var style lipgloss.Style
if tk.IsFocused() {
style = tk.theme.ErrorDialogBox.Titlebar.Focused
} else {
style = tk.theme.ErrorDialogBox.Titlebar.Blurred
}
titlebar := style.Align(lipgloss.Center).
Width(tk.ViewWidth()).
Render(title)
var bindings []string
for _, binding := range tk.keybindings {
var tmp string = ""
tmp = binding.Help().Key + " " + binding.Help().Desc
bindings = append(bindings, tmp)
}
bindings = append(bindings, "esc close")
bottombar := tk.theme.ErrorDialogBox.Bottombar.
Width(tk.ViewWidth()).
Render(strings.Join(bindings, " · "))
ui := lipgloss.JoinVertical(
lipgloss.Center,
titlebar,
content,
bottombar,
)
var tmp string
if tk.IsFocused() {
tmp = tk.theme.ErrorDialogBox.Window.Focused.Render(ui)
} else {
tmp = tk.theme.ErrorDialogBox.Window.Blurred.Render(ui)
}
view.WriteString(tmp)
return view.String()
}

View File

@ -234,5 +234,5 @@ func (m Model) setSizes(winWidth int, winHeight int) {
(*m.ctx).Screen[0] = winWidth
(*m.ctx).Screen[1] = winHeight
m.ctx.Content[0] = m.ctx.Screen[0]
m.ctx.Content[1] = m.ctx.Screen[1] - 5
m.ctx.Content[1] = m.ctx.Screen[1] - 8
}

View File

@ -15,8 +15,8 @@ func buildView(mi interface{}, cached bool) string {
m.ctx.Logger.Debugln("View()")
m.ctx.Logger.Debugf("IsFocused: %v\n", m.tk.IsFocused())
return m.tk.Dialog(
"Post",
return m.tk.ErrorDialog(
"Error",
viewportStyle.Render(m.viewport.View()),
)
}