mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-01-03 14:56:41 -05:00
Implemented shadow
This commit is contained in:
parent
f8e731ae3f
commit
8b6619f2ed
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
"github.com/muesli/ansi"
|
"github.com/muesli/ansi"
|
||||||
"github.com/muesli/reflow/truncate"
|
"github.com/muesli/reflow/truncate"
|
||||||
@ -12,7 +13,7 @@ import (
|
|||||||
|
|
||||||
// Most of this code is borrowed from
|
// Most of this code is borrowed from
|
||||||
// https://github.com/charmbracelet/lipgloss/pull/102
|
// 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
|
// Split a string into lines, additionally returning the size of the widest
|
||||||
// line.
|
// line.
|
||||||
@ -30,12 +31,30 @@ func getLines(s string) (lines []string, widest int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PlaceOverlay places fg on top of bg.
|
// 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)
|
fgLines, fgWidth := getLines(fg)
|
||||||
bgLines, bgWidth := getLines(bg)
|
bgLines, bgWidth := getLines(bg)
|
||||||
bgHeight := len(bgLines)
|
bgHeight := len(bgLines)
|
||||||
fgHeight := len(fgLines)
|
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 {
|
if fgWidth >= bgWidth && fgHeight >= bgHeight {
|
||||||
// FIXME: return fg or bg?
|
// FIXME: return fg or bg?
|
||||||
return fg
|
return fg
|
||||||
|
@ -235,7 +235,7 @@ func (m Model) View() string {
|
|||||||
bottombar,
|
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()
|
return view.String()
|
||||||
|
Loading…
Reference in New Issue
Block a user