-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): lula validation view (#727)
* feat(console): add validation detail, reorg, tests * fix: yaml dep * fix: testdata * fix: minor cleanups * fix: testdata * fix: updated tests for consistency * fix: updated with filespec to yaml str --------- Co-authored-by: Brandt Keller <[email protected]>
- Loading branch information
1 parent
cb4fc6f
commit 481648f
Showing
13 changed files
with
1,275 additions
and
945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/viewport" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
type ContentType string | ||
|
||
const ( | ||
detailWidth = 80 | ||
detailHeight = 20 | ||
widthScale = 0.9 | ||
heightScale = 0.9 | ||
) | ||
|
||
type DetailOpenMsg struct { | ||
Content string | ||
WindowHeight int | ||
WindowWidth int | ||
} | ||
|
||
type DetailModel struct { | ||
Open bool | ||
help HelpModel | ||
contentViewport viewport.Model | ||
width int | ||
height int | ||
} | ||
|
||
func NewDetailModel() DetailModel { | ||
help := NewHelpModel(true) | ||
help.ShortHelp = ShortHelpDetail | ||
|
||
return DetailModel{ | ||
help: help, | ||
contentViewport: viewport.New(detailWidth, detailHeight), | ||
} | ||
} | ||
|
||
func (m DetailModel) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (m DetailModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmds []tea.Cmd | ||
var cmd tea.Cmd | ||
|
||
switch msg := msg.(type) { | ||
case tea.WindowSizeMsg: | ||
m.updateSizing(int(float64(msg.Height)*heightScale), int(float64(msg.Width)*widthScale)) | ||
|
||
case tea.KeyMsg: | ||
k := msg.String() | ||
if m.Open { | ||
switch k { | ||
case ContainsKey(k, CommonKeys.Cancel.Keys()): | ||
m.Open = false | ||
} | ||
} | ||
|
||
case DetailOpenMsg: | ||
m.Open = true | ||
m.contentViewport.GotoTop() | ||
m.contentViewport.SetContent(msg.Content) | ||
m.updateSizing(int(float64(msg.WindowHeight)*heightScale), int(float64(msg.WindowWidth)*widthScale)) | ||
} | ||
|
||
m.contentViewport, cmd = m.contentViewport.Update(msg) | ||
cmds = append(cmds, cmd) | ||
|
||
return m, tea.Batch(cmds...) | ||
} | ||
|
||
func (m DetailModel) View() string { | ||
overlayDetailStyle := OverlayStyle. | ||
Width(m.width). | ||
Height(m.height) | ||
|
||
detailContent := lipgloss.JoinVertical(lipgloss.Top, m.contentViewport.View(), "\n", m.help.View()) | ||
|
||
return overlayDetailStyle.Render(detailContent) | ||
} | ||
|
||
func (m *DetailModel) updateSizing(height, width int) { | ||
m.height = height | ||
m.width = width | ||
|
||
m.contentViewport.Height = height - OverlayStyle.GetVerticalPadding() - 2 | ||
m.contentViewport.Width = width - OverlayStyle.GetHorizontalPadding() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.