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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
package profile
import (
"crypto/ed25519"
"strconv"
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/kyren223/eko/internal/client/ui/colors"
"github.com/kyren223/eko/internal/client/ui/core/state"
"github.com/kyren223/eko/pkg/assert"
"github.com/kyren223/eko/pkg/snowflake"
"golang.org/x/crypto/ssh"
)
var width = 70
type Model struct {
id snowflake.ID
}
func New(userId snowflake.ID) Model {
return Model{
id: userId,
}
}
func (m Model) Init() tea.Cmd {
return nil
}
func (m Model) View() string {
user := state.State.Users[m.id]
var builder strings.Builder
headerStyle := lipgloss.NewStyle().
PaddingLeft(2).
Width(width).
Background(colors.Background).
Foreground(colors.Focus)
name := user.Name
name = lipgloss.NewStyle().
MarginBackground(colors.Background).
Background(colors.Gold).
Foreground(colors.Background).
Bold(true).
Render(name)
paddingLeft := lipgloss.NewStyle().
MarginLeft(2).
Background(colors.Background).
Foreground(colors.Gold).
Render("")
paddingRight := lipgloss.NewStyle().
Background(colors.Background).
Foreground(colors.Gold).
Render("")
builder.WriteString(paddingLeft)
builder.WriteString(name)
builder.WriteString(paddingRight)
builder.WriteByte('\n')
builder.WriteByte('\n')
publicDMs := "Private DMs"
if user.IsPublicDM {
publicDMs = "Public DMs"
}
id := strconv.FormatInt(int64(user.ID), 10)
info := lipgloss.NewStyle().
PaddingLeft(2).
Width(width).
Background(colors.Background).
Foreground(colors.LightGray).
Render("ID: " + id + " | " + publicDMs)
builder.WriteString(info)
builder.WriteByte('\n')
builder.WriteByte('\n')
publicKeyHeader := headerStyle.Render("Public Key (ssh-ed25519)")
publicKey := lipgloss.NewStyle().
PaddingLeft(2).
Width(width).
Render(publicKeyToSshString(user.PublicKey))
builder.WriteString(publicKeyHeader)
builder.WriteByte('\n')
builder.WriteByte('\n')
builder.WriteString(publicKey)
builder.WriteByte('\n')
aboutMeHeader := headerStyle.Render("About me")
builder.WriteString(aboutMeHeader)
builder.WriteByte('\n')
builder.WriteByte('\n')
textBg := colors.BackgroundHighlight
textFg := colors.White
bg := colors.Background
description := user.Description
if description == "" {
description = lipgloss.NewStyle().
Foreground(colors.Purple).
Render("No description was provided")
}
excessWidth := 4 - 2
bgStyle := lipgloss.NewStyle().Background(textBg).Foreground(bg)
topMiddle := strings.Repeat(" ", width-excessWidth)
top := bgStyle.Render("🭠🭘" + topMiddle + "🭣🭕")
middle := lipgloss.NewStyle().Width(width+2).Padding(0, 2).
Background(textBg).Foreground(textFg).Render(description)
bgStyle2 := lipgloss.NewStyle().Foreground(textBg)
bottomMiddle := strings.Repeat("█", width-excessWidth)
bottom := bgStyle2.Render("🭥🭓" + bottomMiddle + "🭞🭚")
aboutMe := lipgloss.JoinVertical(lipgloss.Left, top, middle, bottom)
builder.WriteString(aboutMe)
content := builder.String()
return lipgloss.NewStyle().
Border(lipgloss.ThickBorder()).
Padding(1, 2).
Align(lipgloss.Left, lipgloss.Center).
BorderBackground(colors.Background).
BorderForeground(colors.White).
Background(colors.Background).
Foreground(colors.White).
Render(content)
}
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, nil
}
func publicKeyToSshString(pub ed25519.PublicKey) string {
sshPubKey, err := ssh.NewPublicKey(pub)
assert.NoError(err, "converting to ssh key should never fail")
sshPubKeyBytes := ssh.MarshalAuthorizedKey(sshPubKey)
return strings.Split(string(sshPubKeyBytes), " ")[1]
}
|