mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-15 00:20:37 +03:00
refactor: User.SetColorIdx -> User.setColorIdx, preparing to abstract user
This commit is contained in:
parent
33d7d26a17
commit
454777448f
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user