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

Implemented shadow

This commit is contained in:
マリウス 2022-12-31 14:30:11 -05:00
parent f8e731ae3f
commit 8b6619f2ed
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 22 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/mattn/go-runewidth"
"github.com/muesli/ansi"
"github.com/muesli/reflow/truncate"
@ -12,7 +13,7 @@ import (
// Most of this code is borrowed from
// https://github.com/charmbracelet/lipgloss/pull/102
// as well as the lipgloss library.
// as well as the lipgloss library, with some modification for what I needed.
// Split a string into lines, additionally returning the size of the widest
// line.
@ -30,12 +31,30 @@ func getLines(s string) (lines []string, widest int) {
}
// PlaceOverlay places fg on top of bg.
func PlaceOverlay(x, y int, fg, bg string, opts ...WhitespaceOption) string {
func PlaceOverlay(x, y int, fg, bg string, shadow bool, opts ...WhitespaceOption) string {
fgLines, fgWidth := getLines(fg)
bgLines, bgWidth := getLines(bg)
bgHeight := len(bgLines)
fgHeight := len(fgLines)
if shadow {
var shadowbg string = ""
shadowchar := lipgloss.NewStyle().
Foreground(lipgloss.Color("#333333")).
Render("░")
for i := 0; i <= fgHeight; i++ {
if i == 0 {
shadowbg += " " + strings.Repeat(" ", fgWidth) + "\n"
} else {
shadowbg += " " + strings.Repeat(shadowchar, fgWidth) + "\n"
}
}
fg = PlaceOverlay(0, 0, fg, shadowbg, false, opts...)
fgLines, fgWidth = getLines(fg)
fgHeight = len(fgLines)
}
if fgWidth >= bgWidth && fgHeight >= bgHeight {
// FIXME: return fg or bg?
return fg

View File

@ -235,7 +235,7 @@ func (m Model) View() string {
bottombar,
)
return helpers.PlaceOverlay(3, 2, dialogBoxStyle.Render(ui), view.String())
return helpers.PlaceOverlay(3, 2, dialogBoxStyle.Render(ui), view.String(), true)
}
return view.String()