File tree Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,16 @@ func (u *User) Send(m Message) error {
186
186
return nil
187
187
}
188
188
189
+ // Prompt renders a theme-colorized prompt string.
190
+ func (u * User ) Prompt () string {
191
+ name := u .Name ()
192
+ cfg := u .Config ()
193
+ if cfg .Theme != nil {
194
+ name = cfg .Theme .ColorName (u )
195
+ }
196
+ return fmt .Sprintf ("[%s] " , name )
197
+ }
198
+
189
199
// Container for per-user configurations.
190
200
type UserConfig struct {
191
201
Highlight * regexp.Regexp
Original file line number Diff line number Diff line change @@ -18,16 +18,6 @@ import (
18
18
19
19
const maxInputLength int = 1024
20
20
21
- // getPrompt will render the terminal prompt string based on the user.
22
- func getPrompt (user * message.User ) string {
23
- name := user .Name ()
24
- cfg := user .Config ()
25
- if cfg .Theme != nil {
26
- name = cfg .Theme .ColorName (user )
27
- }
28
- return fmt .Sprintf ("[%s] " , name )
29
- }
30
-
31
21
// Host is the bridge between sshd and chat modules
32
22
// TODO: Should be easy to add support for multiple rooms, if we want.
33
23
type Host struct {
@@ -124,7 +114,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
124
114
}
125
115
126
116
// Successfully joined.
127
- term .SetPrompt (getPrompt ( user ))
117
+ term .SetPrompt (user . Prompt ( ))
128
118
term .AutoCompleteCallback = h .AutoCompleteFunction (user )
129
119
user .SetHighlight (user .Name ())
130
120
@@ -172,7 +162,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
172
162
//
173
163
// FIXME: This is hacky, how do we improve the API to allow for
174
164
// this? Chat module shouldn't know about terminals.
175
- term .SetPrompt (getPrompt ( user ))
165
+ term .SetPrompt (user . Prompt ( ))
176
166
user .SetHighlight (user .Name ())
177
167
}
178
168
}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ func TestHostGetPrompt(t *testing.T) {
29
29
30
30
u := message .NewUser (& identity {id : "foo" })
31
31
32
- actual = getPrompt ( u )
32
+ actual = u . Prompt ( )
33
33
expected = "[foo] "
34
34
if actual != expected {
35
35
t .Errorf ("Got: %q; Expected: %q" , actual , expected )
@@ -38,7 +38,7 @@ func TestHostGetPrompt(t *testing.T) {
38
38
u .SetConfig (message.UserConfig {
39
39
Theme : & message .Themes [0 ],
40
40
})
41
- actual = getPrompt ( u )
41
+ actual = u . Prompt ( )
42
42
expected = "[\033 [38;05;88mfoo\033 [0m] "
43
43
if actual != expected {
44
44
t .Errorf ("Got: %q; Expected: %q" , actual , expected )
You can’t perform that action at this time.
0 commit comments