summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorHubert Hirtz <hubert.hirtz@laposte.net>2020-06-03 19:03:58 +0200
committerHubert Hirtz <hubert.hirtz@laposte.net>2020-06-03 19:03:58 +0200
commit9a732d4de4d1e82fadd5270837201819d78adb62 (patch)
tree851d91be3c3147e19a52e500a2d6189f40eaaa00 /cmd
parentInitial commit (diff)
Part Join Typing
Diffstat (limited to 'cmd')
-rw-r--r--cmd/irc/main.go40
1 files changed, 27 insertions, 13 deletions
diff --git a/cmd/irc/main.go b/cmd/irc/main.go
index 2e76c3a..61ee39f 100644
--- a/cmd/irc/main.go
+++ b/cmd/irc/main.go
@@ -59,6 +59,8 @@ func main() {
app.AddLine("home", "Connected to the server", time.Now())
case irc.SelfJoinEvent:
app.AddBuffer(ev.Channel)
+ case irc.SelfPartEvent:
+ app.RemoveBuffer(ev.Channel)
case irc.ChannelMessageEvent:
line := formatIRCMessage(ev.Nick, ev.Content)
app.AddLine(ev.Channel, line, ev.Time)
@@ -94,11 +96,14 @@ func main() {
case tcell.KeyBackspace2:
app.InputBackspace()
case tcell.KeyEnter:
- content := app.InputEnter()
- handleInput(app, &s, content)
+ buffer := app.CurrentBuffer()
+ input := app.InputEnter()
+ handleInput(&s, buffer, input)
case tcell.KeyRune:
app.InputRune(ev.Rune())
- s.Typing(app.CurrentBuffer())
+ if app.CurrentBuffer() != "home" && !strings.HasPrefix(app.Input(), "/") {
+ s.Typing(app.CurrentBuffer())
+ }
}
}
}
@@ -117,35 +122,44 @@ func parseCommand(s string) (command, args string) {
i := strings.IndexByte(s, ' ')
if i < 0 {
- i = len(s) - 1
+ i = len(s)
}
command = strings.ToUpper(s[1:i])
- args = s[i+1:]
+ args = strings.TrimLeft(s[i:], " ")
return
}
-func handleInput(app *ui.UI, s *irc.Session, content string) {
+func handleInput(s *irc.Session, buffer, content string) {
cmd, args := parseCommand(content)
switch cmd {
case "":
- ch := app.CurrentBuffer()
- if ch == "home" {
+ if buffer == "home" {
+ return
+ }
+
+ s.PrivMsg(buffer, args)
+ case "J", "JOIN":
+ s.Join(args)
+ case "PART":
+ if buffer == "home" {
return
}
- s.PrivMsg(ch, args)
+ if args == "" {
+ args = buffer
+ }
+
+ s.Part(args)
case "ME":
- ch := app.CurrentBuffer()
- if ch == "home" {
+ if buffer == "home" {
return
}
line := fmt.Sprintf("\x01ACTION %s\x01", args)
- s.PrivMsg(ch, line)
- default:
+ s.PrivMsg(buffer, line)
}
}