message

package
v0.0.0-...-8103da3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Reset resets the color
	Reset = "\033[0m"

	// Bold makes the following text bold
	Bold = "\033[1m"

	// Dim dims the following text
	Dim = "\033[2m"

	// Italic makes the following text italic
	Italic = "\033[3m"

	// Underline underlines the following text
	Underline = "\033[4m"

	// Blink blinks the following text
	Blink = "\033[5m"

	// Invert inverts the following text
	Invert = "\033[7m"

	// Newline
	Newline = "\r\n"

	// BEL
	Bel = "\007"
)

Variables

View Source
var ErrUserClosed = errors.New("user closed")
View Source
var Themes []Theme

List of initialzied themes

Functions

func SetLogger

func SetLogger(w io.Writer)

Types

type AnnounceMsg

type AnnounceMsg struct {
	Msg
}

AnnounceMsg is a message sent from the server to everyone, like a join or leave event.

func NewAnnounceMsg

func NewAnnounceMsg(body string) *AnnounceMsg

func (AnnounceMsg) Render

func (m AnnounceMsg) Render(t *Theme) string

func (AnnounceMsg) String

func (m AnnounceMsg) String() string

type Color0

type Color0 struct{}

No color, used for mono theme

func (Color0) Format

func (c Color0) Format(s string) string

No-op for Color0

func (Color0) String

func (c Color0) String() string

No-op for Color0

type Color256

type Color256 uint8

256 color type, for terminals who support it

func (Color256) Format

func (c Color256) Format(s string) string

Return formatted string with this color

func (Color256) String

func (c Color256) String() string

String version of this color

type CommandMsg

type CommandMsg struct {
	PublicMsg
	// contains filtered or unexported fields
}

func (CommandMsg) Args

func (m CommandMsg) Args() []string

func (CommandMsg) Body

func (m CommandMsg) Body() string

func (CommandMsg) Command

func (m CommandMsg) Command() string

type EmoteMsg

type EmoteMsg struct {
	Msg
	// contains filtered or unexported fields
}

EmoteMsg is a /me message sent to the room. It specifically does not extend PublicMsg because it doesn't implement MessageFrom to allow the sender to see the emote.

func NewEmoteMsg

func NewEmoteMsg(body string, from *User) *EmoteMsg

func (EmoteMsg) Render

func (m EmoteMsg) Render(t *Theme) string

func (EmoteMsg) String

func (m EmoteMsg) String() string

type History

type History struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

History contains the history entries

func NewHistory

func NewHistory(size int) *History

NewHistory constructs a new history of the given size

func (*History) Add

func (h *History) Add(entry Message)

Add adds the given entry to the entries in the history

func (*History) Get

func (h *History) Get(num int) []Message

Get the entry with the given number

func (*History) Len

func (h *History) Len() int

Len returns the number of entries in the history

func (*History) SetOutput

func (h *History) SetOutput(w io.Writer)

SetOutput sets the output for logging added messages

type Identifier

type Identifier interface {
	ID() string
	SetID(string)
	Name() string
}

Identifier is an interface that can uniquely identify itself.

type Message

type Message interface {
	Render(*Theme) string
	String() string
	Command() string
	Timestamp() time.Time
}

Message is an interface for messages.

func ParseInput

func ParseInput(body string, from *User) Message

type MessageFrom

type MessageFrom interface {
	Message
	From() *User
}

type MessageTo

type MessageTo interface {
	Message
	To() *User
}

type Msg

type Msg struct {
	// contains filtered or unexported fields
}

Msg is a base type for other message types.

func NewMsg

func NewMsg(body string) *Msg

func (Msg) Command

func (m Msg) Command() string

func (Msg) Render

func (m Msg) Render(t *Theme) string

Render message based on a theme.

func (Msg) String

func (m Msg) String() string

func (Msg) Timestamp

func (m Msg) Timestamp() time.Time

type Palette

type Palette struct {
	// contains filtered or unexported fields
}

Container for a collection of colors

func Color256Palette

func Color256Palette(colors ...uint8) *Palette

func (Palette) Get

func (p Palette) Get(i int) Style

Get a color by index, overflows are looped around.

func (Palette) Len

func (p Palette) Len() int

func (Palette) String

func (p Palette) String() string

type PrivateMsg

type PrivateMsg struct {
	PublicMsg
	// contains filtered or unexported fields
}

PrivateMsg is a message sent to another user, not shown to anyone else.

func NewPrivateMsg

func NewPrivateMsg(body string, from *User, to *User) PrivateMsg

func (PrivateMsg) Render

func (m PrivateMsg) Render(t *Theme) string

func (PrivateMsg) String

func (m PrivateMsg) String() string

func (PrivateMsg) To

func (m PrivateMsg) To() *User

type PublicMsg

type PublicMsg struct {
	Msg
	// contains filtered or unexported fields
}

PublicMsg is any message from a user sent to the room.

func NewPublicMsg

func NewPublicMsg(body string, from *User) PublicMsg

func (PublicMsg) From

func (m PublicMsg) From() *User

func (PublicMsg) ParseCommand

func (m PublicMsg) ParseCommand() (*CommandMsg, bool)

func (PublicMsg) Render

func (m PublicMsg) Render(t *Theme) string

func (PublicMsg) RenderFor

func (m PublicMsg) RenderFor(cfg UserConfig) string

func (PublicMsg) String

func (m PublicMsg) String() string

type SimpleID

type SimpleID string

SimpleID is a simple Identifier implementation used for testing.

func (SimpleID) ID

func (i SimpleID) ID() string

ID returns the ID as a string.

func (SimpleID) Name

func (i SimpleID) Name() string

Name returns the ID

func (SimpleID) SetID

func (i SimpleID) SetID(s string)

SetID is a no-op

type Style

type Style interface {
	String() string
	Format(string) string
}

Interface for Styles

type SystemMsg

type SystemMsg struct {
	Msg
	// contains filtered or unexported fields
}

SystemMsg is a response sent from the server directly to a user, not shown to anyone else. Usually in response to something, like /help.

func NewSystemMsg

func NewSystemMsg(body string, to *User) *SystemMsg

func (*SystemMsg) Render

func (m *SystemMsg) Render(t *Theme) string

func (*SystemMsg) String

func (m *SystemMsg) String() string

func (*SystemMsg) To

func (m *SystemMsg) To() *User

type Theme

type Theme struct {
	// contains filtered or unexported fields
}

Collection of settings for chat

var DefaultTheme *Theme

Default theme to use

func (Theme) ColorName

func (t Theme) ColorName(u *User) string

Colorize name string given some index

func (Theme) ColorPM

func (t Theme) ColorPM(s string) string

Colorize the PM string

func (Theme) ColorSys

func (t Theme) ColorSys(s string) string

Colorize the Sys message

func (Theme) Highlight

func (t Theme) Highlight(s string) string

Highlight a matched string, usually name

func (Theme) ID

func (t Theme) ID() string

type User

type User struct {
	Identifier
	Ignored *set.Set
	// contains filtered or unexported fields
}

User definition, implemented set Item interface and io.Writer

func NewUser

func NewUser(identity Identifier) *User

func NewUserScreen

func NewUserScreen(identity Identifier, screen io.WriteCloser) *User

func (*User) Close

func (u *User) Close()

Disconnect user, stop accepting messages

func (*User) Config

func (u *User) Config() UserConfig

func (*User) Consume

func (u *User) Consume()

Consume message buffer into the handler. Will block, should be called in a goroutine.

func (*User) ConsumeOne

func (u *User) ConsumeOne() Message

Consume one message and stop, mostly for testing

func (*User) HandleMsg

func (u *User) HandleMsg(m Message) error

HandleMsg will render the message to the screen, blocking.

func (*User) HasMessages

func (u *User) HasMessages() bool

Check if there are pending messages, used for testing

func (*User) ReplyTo

func (u *User) ReplyTo() *User

ReplyTo returns the last user that messaged this user.

func (*User) Send

func (u *User) Send(m Message) error

Add message to consume by user

func (*User) SetConfig

func (u *User) SetConfig(cfg UserConfig)

func (*User) SetHighlight

func (u *User) SetHighlight(s string) error

SetHighlight sets the highlighting regular expression to match string.

func (*User) SetID

func (u *User) SetID(id string)

Rename the user with a new Identifier.

func (*User) SetReplyTo

func (u *User) SetReplyTo(user *User)

SetReplyTo sets the last user to message this user.

type UserConfig

type UserConfig struct {
	Highlight *regexp.Regexp
	Bell      bool
	Quiet     bool
	Theme     *Theme
}

Container for per-user configurations.

var DefaultUserConfig UserConfig

Default user configuration to use

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL