summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/irc/main.go12
-rw-r--r--irc/events.go2
-rw-r--r--irc/states.go24
-rw-r--r--ui/buffers.go17
-rw-r--r--ui/ui.go4
5 files changed, 47 insertions, 12 deletions
diff --git a/cmd/irc/main.go b/cmd/irc/main.go
index 5c2d436..9999e14 100644
--- a/cmd/irc/main.go
+++ b/cmd/irc/main.go
@@ -34,7 +34,7 @@ func main() {
defer app.Close()
addr := cfg.Addr
- app.AddLine("home", fmt.Sprintf("Connecting to %s...", addr), time.Now())
+ app.AddLine("home", fmt.Sprintf("Connecting to %s...", addr), time.Now(), false)
conn, err := tls.Dial("tcp", addr, nil)
if err != nil {
@@ -57,14 +57,20 @@ func main() {
case ev := <-s.Poll():
switch ev := ev.(type) {
case irc.RegisteredEvent:
- app.AddLine("home", "Connected to the server", time.Now())
+ app.AddLine("home", "Connected to the server", time.Now(), false)
case irc.SelfJoinEvent:
app.AddBuffer(ev.Channel)
+ case irc.UserJoinEvent:
+ line := fmt.Sprintf("\x033+\x0314%s", ev.Nick)
+ app.AddLine(ev.Channel, line, ev.Time, true)
case irc.SelfPartEvent:
app.RemoveBuffer(ev.Channel)
+ case irc.UserPartEvent:
+ line := fmt.Sprintf("\x034-\x0314%s", ev.Nick)
+ app.AddLine(ev.Channel, line, ev.Time, true)
case irc.ChannelMessageEvent:
line := formatIRCMessage(ev.Nick, ev.Content)
- app.AddLine(ev.Channel, line, ev.Time)
+ app.AddLine(ev.Channel, line, ev.Time, false)
case error:
log.Panicln(ev)
}
diff --git a/irc/events.go b/irc/events.go
index c2af056..96bf786 100644
--- a/irc/events.go
+++ b/irc/events.go
@@ -32,6 +32,7 @@ func (c ChannelEvent) ChannelMapped() (channel string) {
type UserJoinEvent struct {
UserEvent
ChannelEvent
+ Time time.Time
}
type SelfPartEvent struct {
@@ -41,6 +42,7 @@ type SelfPartEvent struct {
type UserPartEvent struct {
UserEvent
ChannelEvent
+ Time time.Time
}
type SelfJoinEvent struct {
diff --git a/irc/states.go b/irc/states.go
index 40ac308..c19f1db 100644
--- a/irc/states.go
+++ b/irc/states.go
@@ -527,7 +527,17 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
s.users[lNick] = User{Nick: nick}
}
c.Members[lNick] = ""
- ev = UserJoinEvent{ChannelEvent: channelEv, UserEvent: UserEvent{Nick: nick}}
+
+ t, ok := msg.Time()
+ if !ok {
+ t = time.Now()
+ }
+
+ ev = UserJoinEvent{
+ ChannelEvent: channelEv,
+ UserEvent: UserEvent{Nick: nick},
+ Time: t,
+ }
}
case "PART":
nick, _, _ := FullMask(msg.Prefix)
@@ -540,7 +550,17 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
ev = SelfPartEvent{ChannelEvent: channelEv}
} else if c, ok := s.channels[channel]; ok {
delete(c.Members, lNick)
- ev = UserPartEvent{ChannelEvent: channelEv, UserEvent: UserEvent{Nick: nick}}
+
+ t, ok := msg.Time()
+ if !ok {
+ t = time.Now()
+ }
+
+ ev = UserPartEvent{
+ ChannelEvent: channelEv,
+ UserEvent: UserEvent{Nick: nick},
+ Time: t,
+ }
}
case "353": // RPL_NAMREPLY
channel := strings.ToLower(msg.Params[2])
diff --git a/ui/buffers.go b/ui/buffers.go
index 4caadf3..8ab5b44 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -99,9 +99,16 @@ func (bs *BufferList) Idx(title string) (idx int) {
return
}
-func (bs *BufferList) AddLine(idx int, line string, t time.Time) {
- bs.List[idx].Content = append(bs.List[idx].Content, Line{
- Time: t,
- Content: line,
- })
+func (bs *BufferList) AddLine(idx int, line string, t time.Time, isStatus bool) {
+ n := len(bs.List[idx].Content)
+
+ if isStatus && n != 0 && bs.List[idx].Content[n-1].IsStatus {
+ bs.List[idx].Content[n-1].Content += " " + line
+ } else {
+ bs.List[idx].Content = append(bs.List[idx].Content, Line{
+ Time: t,
+ IsStatus: isStatus,
+ Content: line,
+ })
+ }
}
diff --git a/ui/ui.go b/ui/ui.go
index bd9f6fa..c7ad49e 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -112,13 +112,13 @@ func (ui *UI) RemoveBuffer(title string) {
}
}
-func (ui *UI) AddLine(buffer string, line string, t time.Time) {
+func (ui *UI) AddLine(buffer string, line string, t time.Time, isStatus bool) {
idx := ui.bufferList.Idx(buffer)
if idx < 0 {
return
}
- ui.bufferList.AddLine(idx, line, t)
+ ui.bufferList.AddLine(idx, line, t, isStatus)
if idx == ui.bufferList.Current {
ui.drawBuffer()