refactor: User.SetColorIdx -> User.setColorIdx, preparing to abstract user

This commit is contained in:
Andrey Petrov 2016-08-29 09:58:17 -04:00
parent 33d7d26a17
commit 454777448f
3 changed files with 7 additions and 8 deletions

View File

@ -44,7 +44,7 @@ func NewUser(identity Identifier) *User {
done: make(chan struct{}), done: make(chan struct{}),
Ignored: set.New(), Ignored: set.New(),
} }
u.SetColorIdx(rand.Int()) u.setColorIdx(rand.Int())
return &u return &u
} }
@ -59,7 +59,7 @@ func NewUserScreen(identity Identifier, screen io.WriteCloser) *User {
// Rename the user with a new Identifier. // Rename the user with a new Identifier.
func (u *User) SetID(id string) { func (u *User) SetID(id string) {
u.Identifier.SetID(id) u.Identifier.SetID(id)
u.SetColorIdx(rand.Int()) u.setColorIdx(rand.Int())
} }
// ReplyTo returns the last user that messaged this user. // ReplyTo returns the last user that messaged this user.
@ -83,9 +83,9 @@ func (u *User) ToggleQuietMode() {
u.Config.Quiet = !u.Config.Quiet u.Config.Quiet = !u.Config.Quiet
} }
// SetColorIdx will set the colorIdx to a specific value, primarily used for // setColorIdx will set the colorIdx to a specific value, primarily used for
// testing. // testing.
func (u *User) SetColorIdx(idx int) { func (u *User) setColorIdx(idx int) {
u.colorIdx = idx u.colorIdx = idx
} }

View File

@ -106,12 +106,12 @@ func (r *Room) HandleMsg(m message.Message) {
} }
if skip && skipUser == user { if skip && skipUser == user {
// Skip // Skip self
return return
} }
if _, ok := m.(*message.AnnounceMsg); ok { if _, ok := m.(*message.AnnounceMsg); ok {
if user.Config.Quiet { if user.Config.Quiet {
// Skip // Skip announcements
return return
} }
} }

View File

@ -28,7 +28,6 @@ func TestHostGetPrompt(t *testing.T) {
var expected, actual string var expected, actual string
u := message.NewUser(&Identity{id: "foo"}) u := message.NewUser(&Identity{id: "foo"})
u.SetColorIdx(2)
actual = GetPrompt(u) actual = GetPrompt(u)
expected = "[foo] " expected = "[foo] "
@ -38,7 +37,7 @@ func TestHostGetPrompt(t *testing.T) {
u.Config.Theme = &message.Themes[0] u.Config.Theme = &message.Themes[0]
actual = GetPrompt(u) actual = GetPrompt(u)
expected = "[\033[38;05;3mfoo\033[0m] " expected = "[\033[38;05;88mfoo\033[0m] "
if actual != expected { if actual != expected {
t.Errorf("Got: %q; Expected: %q", actual, expected) t.Errorf("Got: %q; Expected: %q", actual, expected)
} }