summaryrefslogtreecommitdiff
path: root/view.go
blob: 61716e548c78fc4c1c86fb5cf8dfef816ec956ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"fmt"
	"time"

	tea "charm.land/bubbletea/v2"
)

func (m model) View() tea.View {
	s := "Unpublished drafts of this Hugo site:\n\n"

	for i, choice := range m.choices {
		if i == 0 {
			continue
		}

		cursor := " " // no cursor
		if m.cursor == i {
			cursor = ">"
		}

		checked := " " // not checked
		if _, ok := m.selected[i]; ok {
			checked = "x"
		}

		title := choice[2]
		t, err := time.Parse(time.RFC3339, choice[3])
		if err != nil {

		}
		datetime := t.Format("2006-01-02 15:04")

		s += fmt.Sprintf("%s [%s] %s \t %s\n", cursor, checked, datetime, title)
	}

	s += "\n[q] quit | [Enter] edit | [SPACE] select | [↑/k] up | [↓/j] down\n"

	return tea.NewView(s)
}