From ced5767bbbf10612d3c1b129c5fe6e862fad40c9 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Wed, 24 Jun 2020 13:53:24 -0400 Subject: [PATCH] main: Add symbol support --- host.go | 23 +++++++++++++++++++++-- identity.go | 8 ++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/host.go b/host.go index a943ff6..96331d8 100644 --- a/host.go +++ b/host.go @@ -95,7 +95,7 @@ func (h *Host) Connect(term *sshd.Terminal) { user := message.NewUserScreen(id, term) user.OnChange = func() { term.SetPrompt(GetPrompt(user)) - user.SetHighlight(user.Name()) + user.SetHighlight(user.ID()) } cfg := user.Config() @@ -283,7 +283,7 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int, if completed == "/reply" { replyTo := u.ReplyTo() if replyTo != nil { - name := replyTo.Name() + name := replyTo.ID() _, found := h.GetUser(name) if found { completed = "/msg " + name @@ -634,10 +634,29 @@ func (h *Host) InitCommands(c *chat.Commands) { return errors.New("user not found") } + symbolSet := false + if len(args) == 3 { + s := args[2] + if id, ok := member.Identifier.(*Identity); ok { + id.SetSymbol(s) + } else { + return errors.New("user does not support setting symbol") + } + + body := fmt.Sprintf("Assigned symbol %q by %s.", s, msg.From().Name()) + room.Send(message.NewSystemMsg(body, member.User)) + symbolSet = true + } + oldID := member.ID() newID := sanitize.Name(args[1]) if newID == oldID { return errors.New("new name is the same as the original") + } else if newID == "" && symbolSet { + if member.User.OnChange != nil { + member.User.OnChange() + } + return nil } member.SetID(newID) diff --git a/identity.go b/identity.go index 0817792..148a6dd 100644 --- a/identity.go +++ b/identity.go @@ -14,6 +14,7 @@ import ( type Identity struct { sshd.Connection id string + symbol string // symbol is displayed as a prefix to the name created time.Time } @@ -41,8 +42,15 @@ func (i *Identity) SetName(name string) { i.SetID(name) } +func (i *Identity) SetSymbol(symbol string) { + i.symbol = symbol +} + // Name returns the name for the Identity func (i Identity) Name() string { + if i.symbol != "" { + return i.symbol + " " + i.id + } return i.id }