Skip to content

Commit

Permalink
feat: add faded bg to modals
Browse files Browse the repository at this point in the history
  • Loading branch information
jackMort committed Nov 9, 2024
1 parent be162a8 commit 221965f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ require (
github.com/evertras/bubble-table v0.17.0
github.com/google/uuid v1.6.0
github.com/lrstanley/bubblezone v0.0.0-20240914071701-b48c55a5e78e
github.com/mattn/go-runewidth v0.0.16
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6
github.com/muesli/reflow v0.3.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/treilik/bubbleboxer v0.2.0
Expand All @@ -34,10 +36,8 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
Expand Down
14 changes: 9 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func (m Model) AddToCollection() tea.Cmd {
return app.GetInstance().AddToCollection(coll.CollectionName(), call)
}

func (m Model) GetFadedView() string {
return lipgloss.NewStyle().Foreground(config.COLOR_SUBTLE).Render(utils.RemoveANSI(m.View()))
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
var cmds []tea.Cmd
Expand Down Expand Up @@ -202,7 +206,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.SetFocused("url")
url := m.getUrlPane()

coll := collections.NewAddToCollection(m.View(), 40, m.tui.LayoutTree.GetWidth())
coll := collections.NewAddToCollection(m.GetFadedView(), 40, m.tui.LayoutTree.GetWidth())
coll.SetUrl(url.Value())

m.popup = coll
Expand Down Expand Up @@ -296,21 +300,21 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

width := 100
m.popup = popup.NewChoice(m.View(), width, "Are you sure, you want to quit?", false)
m.popup = popup.NewChoice(m.GetFadedView(), width, "Are you sure, you want to quit?", false)
return m, m.popup.Init()

case "ctrl+n":
m.popup = collections.NewCreate(m.View(), utils.MinInt(70, 100))
m.popup = collections.NewCreate(m.GetFadedView(), utils.MinInt(70, 100))
return m, m.popup.Init()

case "ctrl+a":
m.popup = NewHelp(m.View(), 70)
m.popup = NewHelp(m.GetFadedView(), 70)
return m, m.popup.Init()

case "ctrl+s":
url := m.getUrlPane()

coll := collections.NewAddToCollection(m.View(), 40, m.tui.LayoutTree.GetWidth())
coll := collections.NewAddToCollection(m.GetFadedView(), 40, m.tui.LayoutTree.GetWidth())
coll.SetUrl(url.Value())

m.popup = coll
Expand Down
8 changes: 8 additions & 0 deletions utils/strings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"regexp"
"strings"

"github.com/muesli/ansi"
Expand Down Expand Up @@ -39,3 +40,10 @@ func GetStartColRow(content string, bgRaw string) (int, int) {

return startCol, startRow
}

// Regex to match ANSI escape codes
var ansiReg = regexp.MustCompile(`\x1b\[[0-9;]*m`)

func RemoveANSI(str string) string {
return ansiReg.ReplaceAllString(str, "")
}

0 comments on commit 221965f

Please sign in to comment.