mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-09-15 04:28:07 -04:00
Implemented shadow
This commit is contained in:
parent
f8e731ae3f
commit
8b6619f2ed
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user