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 {
186186return nil
187187}
188188
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+
189199// Container for per-user configurations.
190200type UserConfig struct {
191201Highlight * regexp.Regexp
Original file line number Diff line number Diff line change @@ -18,16 +18,6 @@ import (
1818
1919const maxInputLength int = 1024
2020
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-
3121// Host is the bridge between sshd and chat modules
3222// TODO: Should be easy to add support for multiple rooms, if we want.
3323type Host struct {
@@ -124,7 +114,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
124114}
125115
126116// Successfully joined.
127- term .SetPrompt (getPrompt ( user ))
117+ term .SetPrompt (user . Prompt ( ))
128118term .AutoCompleteCallback = h .AutoCompleteFunction (user )
129119user .SetHighlight (user .Name ())
130120
@@ -172,7 +162,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
172162//
173163// FIXME: This is hacky, how do we improve the API to allow for
174164// this? Chat module shouldn't know about terminals.
175- term .SetPrompt (getPrompt ( user ))
165+ term .SetPrompt (user . Prompt ( ))
176166user .SetHighlight (user .Name ())
177167}
178168}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ func TestHostGetPrompt(t *testing.T) {
2929
3030u := message .NewUser (& identity {id : "foo" })
3131
32- actual = getPrompt ( u )
32+ actual = u . Prompt ( )
3333expected = "[foo] "
3434if actual != expected {
3535t .Errorf ("Got: %q; Expected: %q" , actual , expected )
@@ -38,7 +38,7 @@ func TestHostGetPrompt(t *testing.T) {
3838u .SetConfig (message.UserConfig {
3939Theme : & message .Themes [0 ],
4040})
41- actual = getPrompt ( u )
41+ actual = u . Prompt ( )
4242expected = "[\033 [38;05;88mfoo\033 [0m] "
4343if actual != expected {
4444t .Errorf ("Got: %q; Expected: %q" , actual , expected )
You can’t perform that action at this time.
0 commit comments