forgot to commit this
This commit is contained in:
parent
61b930c588
commit
a7f1bbdd19
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
snake.go
|
||||||
133
main.go
133
main.go
@ -2,27 +2,38 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"log"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/charmbracelet/ssh"
|
"github.com/charmbracelet/ssh"
|
||||||
"github.com/charmbracelet/wish"
|
"github.com/charmbracelet/wish"
|
||||||
wishtea "github.com/charmbracelet/wish/bubbletea"
|
wishtea "github.com/charmbracelet/wish/bubbletea"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var asciiArt = []string{}
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
title string
|
title string
|
||||||
sections []string
|
sections []string
|
||||||
selected int
|
selected int
|
||||||
currentScreen string
|
currentScreen string
|
||||||
|
width int
|
||||||
|
height int
|
||||||
|
mouseX int
|
||||||
|
mouseY int
|
||||||
|
mouseActive bool
|
||||||
|
isClicked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialModel() model {
|
func initialModel() model {
|
||||||
return model{
|
return model{
|
||||||
title: "tuff SSH stuff",
|
title: "Đorđe Kšan",
|
||||||
sections: []string{"About", "Projects", "Contact"},
|
sections: []string{"About", "Projects", "Contact"},
|
||||||
currentScreen: "menu",
|
currentScreen: "menu",
|
||||||
|
mouseActive: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,9 +43,17 @@ func (m model) Init() tea.Cmd {
|
|||||||
|
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
case tea.WindowSizeMsg:
|
||||||
|
m.width = msg.Width
|
||||||
|
m.height = msg.Height
|
||||||
|
if m.mouseX < 0 || m.mouseX > m.width || m.mouseY < 0 || m.mouseY > m.height {
|
||||||
|
m.mouseActive = false
|
||||||
|
}
|
||||||
|
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
|
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "q", "ctrl+c", "esc":
|
case "q", "ctrl+c":
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
||||||
case "up", "k":
|
case "up", "k":
|
||||||
@ -49,15 +68,29 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
case "enter":
|
case "enter":
|
||||||
m.currentScreen = m.sections[m.selected]
|
m.currentScreen = m.sections[m.selected]
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
case "left", "h":
|
case "left", "h":
|
||||||
case "right", "l":
|
case "right", "l":
|
||||||
case "b", "backspace":
|
case "b", "u", "backspace", "esc":
|
||||||
m.currentScreen = "menu"
|
m.currentScreen = "menu"
|
||||||
return m, nil
|
return m, nil
|
||||||
default:
|
default:
|
||||||
fmt.Println("click")
|
fmt.Println("click")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO add mouse logic
|
||||||
|
case tea.MouseMsg:
|
||||||
|
m.mouseX = msg.X
|
||||||
|
m.mouseY = msg.Y
|
||||||
|
m.mouseActive = m.mouseX >= 0 && m.mouseX < m.width && m.mouseY >= 0 && m.mouseY < m.height
|
||||||
|
|
||||||
|
if msg.Button == tea.MouseButtonLeft && msg.Type == tea.MouseEventType(tea.MouseActionRelease) {
|
||||||
|
fmt.Println("mouse click")
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
@ -95,25 +128,104 @@ func (m model) View() string {
|
|||||||
output += sectionStyle.Render("- "+section) + "\n"
|
output += sectionStyle.Render("- "+section) + "\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output += "\n" + footerStyle.Render("Press q to quit.") + "\n"
|
||||||
} else {
|
} else {
|
||||||
switch m.currentScreen {
|
switch m.currentScreen {
|
||||||
case "About":
|
case "About":
|
||||||
output = titleStyle.Render("About Me") + "\n\n" + "Tbh I don't even know anymore. <3"
|
output = m.renderAbout()
|
||||||
|
|
||||||
case "Projects":
|
case "Projects":
|
||||||
output = titleStyle.Render("Projects") + "\n\n" + "Here are some projects I’ve worked on..."
|
output = m.renderProjects()
|
||||||
case "Contact":
|
case "Contact":
|
||||||
output = titleStyle.Render("Contact") + "\n\n" + "Get in touch with me at djordje@ksan.dev."
|
output = m.renderContact()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "\n" + footerStyle.Render("Press b to go back to the menu.") + "\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "\n" + footerStyle.Render("Press q to quit.") + "\n"
|
return lipgloss.Place(
|
||||||
|
m.width,
|
||||||
|
m.height,
|
||||||
|
lipgloss.Center,
|
||||||
|
lipgloss.Center,
|
||||||
|
output,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return output
|
var aboutText = `
|
||||||
|
Tbh I don't even know anymore. <3
|
||||||
|
`
|
||||||
|
|
||||||
|
var contactText = `
|
||||||
|
Get in touch with me at djordje@ksan.dev.
|
||||||
|
`
|
||||||
|
|
||||||
|
var projectsText = `
|
||||||
|
Here are some projects I’ve worked on...
|
||||||
|
`
|
||||||
|
|
||||||
|
var (
|
||||||
|
titleStyle = lipgloss.NewStyle().
|
||||||
|
Bold(true).
|
||||||
|
Foreground(lipgloss.Color("#E2E8F0")).
|
||||||
|
Background(lipgloss.Color("#0F172A")).
|
||||||
|
Padding(0, 3)
|
||||||
|
|
||||||
|
sectionStyle = lipgloss.NewStyle().
|
||||||
|
Foreground(lipgloss.Color("#94A3B8"))
|
||||||
|
|
||||||
|
selectedSectionStyle = lipgloss.NewStyle().
|
||||||
|
Foreground(lipgloss.Color("#8A1D7D")).
|
||||||
|
Bold(true)
|
||||||
|
|
||||||
|
footerStyle = lipgloss.NewStyle().
|
||||||
|
Foreground(lipgloss.Color("#64748B"))
|
||||||
|
|
||||||
|
contentStyle = lipgloss.NewStyle().
|
||||||
|
Foreground(lipgloss.Color("#FFFFFF"))
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m model) renderAbout() string {
|
||||||
|
var str strings.Builder
|
||||||
|
|
||||||
|
str.WriteString(titleStyle.Render("━━━ About Me ━━━"))
|
||||||
|
str.WriteString("\n")
|
||||||
|
str.WriteString(contentStyle.Render(aboutText))
|
||||||
|
str.WriteString("\n")
|
||||||
|
str.WriteString(footerStyle.Render("esc: back to menu"))
|
||||||
|
|
||||||
|
return str.String()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m model) renderProjects() string {
|
||||||
|
|
||||||
|
var str strings.Builder
|
||||||
|
|
||||||
|
str.WriteString(titleStyle.Render("━━━ Projects ━━━"))
|
||||||
|
str.WriteString("\n")
|
||||||
|
str.WriteString(contentStyle.Render(projectsText))
|
||||||
|
str.WriteString("\n")
|
||||||
|
str.WriteString(footerStyle.Render("esc: back to menu"))
|
||||||
|
|
||||||
|
return str.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m model) renderContact() string {
|
||||||
|
var str strings.Builder
|
||||||
|
|
||||||
|
str.WriteString(titleStyle.Render("━━━ Contact ━━━"))
|
||||||
|
str.WriteString("\n")
|
||||||
|
str.WriteString(contentStyle.Render(contactText))
|
||||||
|
str.WriteString("\n")
|
||||||
|
str.WriteString(footerStyle.Render("esc: back to menu"))
|
||||||
|
|
||||||
|
return str.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
server, _ := wish.NewServer(
|
server, _ := wish.NewServer(
|
||||||
wish.WithAddress("0.0.0.0:2222"),
|
wish.WithAddress("0.0.0.0:2222"),
|
||||||
wish.WithHostKeyPath(".ssh/host_ed25519"),
|
wish.WithHostKeyPath(".ssh/host_ed25519"),
|
||||||
@ -133,5 +245,6 @@ func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
|
|||||||
|
|
||||||
return initialModel(), []tea.ProgramOption{
|
return initialModel(), []tea.ProgramOption{
|
||||||
tea.WithAltScreen(),
|
tea.WithAltScreen(),
|
||||||
|
tea.WithMouseCellMotion(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user