From a7f1bbdd19911e4a96673c09c5c9076106239acf Mon Sep 17 00:00:00 2001 From: Ksan Date: Tue, 14 Apr 2026 11:23:48 +0200 Subject: [PATCH] forgot to commit this --- .gitignore | 1 + main.go | 133 +++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d263462 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +snake.go diff --git a/main.go b/main.go index 07fb192..23a8327 100644 --- a/main.go +++ b/main.go @@ -2,27 +2,38 @@ package main import ( "fmt" + "strings" + + "log" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/ssh" "github.com/charmbracelet/wish" wishtea "github.com/charmbracelet/wish/bubbletea" - "log" ) +var asciiArt = []string{} + type model struct { title string sections []string selected int currentScreen string + width int + height int + mouseX int + mouseY int + mouseActive bool + isClicked bool } func initialModel() model { return model{ - title: "tuff SSH stuff", + title: "Đorđe Kšan", sections: []string{"About", "Projects", "Contact"}, 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) { 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: + switch msg.String() { - case "q", "ctrl+c", "esc": + case "q", "ctrl+c": return m, tea.Quit case "up", "k": @@ -49,15 +68,29 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case "enter": m.currentScreen = m.sections[m.selected] + return m, nil + case "left", "h": case "right", "l": - case "b", "backspace": + case "b", "u", "backspace", "esc": m.currentScreen = "menu" return m, nil default: 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 @@ -95,25 +128,104 @@ func (m model) View() string { output += sectionStyle.Render("- "+section) + "\n" } } + + output += "\n" + footerStyle.Render("Press q to quit.") + "\n" } else { switch m.currentScreen { case "About": - output = titleStyle.Render("About Me") + "\n\n" + "Tbh I don't even know anymore. <3" + output = m.renderAbout() + case "Projects": - output = titleStyle.Render("Projects") + "\n\n" + "Here are some projects I’ve worked on..." + output = m.renderProjects() 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() { + server, _ := wish.NewServer( wish.WithAddress("0.0.0.0:2222"), wish.WithHostKeyPath(".ssh/host_ed25519"), @@ -133,5 +245,6 @@ func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) { return initialModel(), []tea.ProgramOption{ tea.WithAltScreen(), + tea.WithMouseCellMotion(), } }