Skip to content

Commit 3bb9be3

Browse files
committed
app view modelled, some new packages created
1 parent bf0b292 commit 3bb9be3

6 files changed

Lines changed: 88 additions & 0 deletions

File tree

internal/tui/app/model.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package app
22

33
import (
44
tea "github.com/charmbracelet/bubbletea"
5+
"github.com/charmbracelet/lipgloss"
6+
"github.com/maniac-en/req/internal/tui/styles"
57
)
68

79
type AppModel struct {
@@ -28,9 +30,23 @@ func (a AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
2830
}
2931

3032
func (a AppModel) View() string {
33+
footer := a.Footer()
34+
header := a.Header()
35+
availableHeight := a.height - lipgloss.Height(header) - lipgloss.Height(footer)
36+
view := lipgloss.NewStyle().Height(availableHeight).Width(a.width).Align(lipgloss.Center, lipgloss.Center).Render("Hello world!")
37+
return lipgloss.JoinVertical(lipgloss.Top, header, view, footer)
38+
}
39+
40+
func (a AppModel) Header() string {
3141
return "Hello World"
3242
}
3343

44+
func (a AppModel) Footer() string {
45+
name := styles.GradientText("REQ", styles.FooterNameFGFrom, styles.FooterNameFGTo, styles.FooterNameStyle, styles.FooterNameBGStyle)
46+
version := styles.FooterVersionStyle.Width(a.width - lipgloss.Width(name)).Render("v0.1.0-alpha2")
47+
return lipgloss.JoinHorizontal(lipgloss.Left, name, version)
48+
}
49+
3450
func NewAppModel() AppModel {
3551
return AppModel{}
3652
}

internal/tui/keys/keys.go

Whitespace-only changes.

internal/tui/styles/app-styles.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package styles
2+
3+
import "github.com/charmbracelet/lipgloss"
4+
5+
var (
6+
FooterNameStyle = lipgloss.NewStyle().Bold(true)
7+
FooterNameBGStyle = lipgloss.NewStyle().Background(FooterNameBG).Padding(0, 3, 0)
8+
FooterVersionStyle = lipgloss.NewStyle().Background(lipgloss.Color("#262626")).AlignHorizontal(lipgloss.Right).PaddingRight(2).Foreground(lipgloss.Color("#656565"))
9+
)

internal/tui/styles/colors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package styles
2+
3+
import "github.com/charmbracelet/lipgloss"
4+
5+
var (
6+
FooterNameBG = lipgloss.Color("#1a1a1a")
7+
FooterNameFGFrom = lipgloss.Color("#6D51FE")
8+
FooterNameFGTo = lipgloss.Color("#8B0F7D")
9+
)

internal/tui/styles/functions.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package styles
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/charmbracelet/lipgloss"
7+
)
8+
9+
func GradientText(text string, startColor, endColor lipgloss.Color, base, additional lipgloss.Style) string {
10+
n := len(text)
11+
result := ""
12+
13+
for i := range n {
14+
ratio := float64(i) / float64(n-1)
15+
color := interpolateColor(startColor, endColor, ratio)
16+
17+
style := base.Foreground(lipgloss.Color(color))
18+
result += style.Render(string(text[i]))
19+
}
20+
21+
return additional.Render(result)
22+
}
23+
24+
func interpolateColor(start, end lipgloss.Color, ratio float64) string {
25+
r1, g1, b1 := hexToRGB(string(start))
26+
r2, g2, b2 := hexToRGB(string(end))
27+
28+
r := int(float64(r1) + (float64(r2)-float64(r1))*ratio)
29+
g := int(float64(g1) + (float64(g2)-float64(g1))*ratio)
30+
b := int(float64(b1) + (float64(b2)-float64(b1))*ratio)
31+
32+
return fmt.Sprintf("#%02X%02X%02X", r, g, b)
33+
}
34+
35+
func hexToRGB(hex string) (int, int, int) {
36+
var r, g, b int
37+
fmt.Sscanf(hex, "#%02x%02x%02x", &r, &g, &b)
38+
return r, g, b
39+
}

internal/tui/views/types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package views
2+
3+
import (
4+
tea "github.com/charmbracelet/bubbletea"
5+
)
6+
7+
type ViewInterface interface {
8+
Init() tea.Cmd
9+
Name() string
10+
Help() string
11+
Update(tea.Msg) (ViewInterface, tea.Cmd)
12+
View() string
13+
OnFocus()
14+
OnBlur()
15+
}

0 commit comments

Comments
 (0)