* CHAT */
(key tea.KeyMsg)
| 685 | /* CHAT */ |
| 686 | |
| 687 | func (m *ircModel) updateChat(key tea.KeyMsg) (tea.Model, tea.Cmd) { |
| 688 | switch key.String() { |
| 689 | case "up": |
| 690 | m.chatVP.LineUp(1) |
| 691 | case "down": |
| 692 | m.chatVP.LineDown(1) |
| 693 | case "pgup": |
| 694 | m.chatVP.HalfViewUp() |
| 695 | case "pgdown": |
| 696 | m.chatVP.HalfViewDown() |
| 697 | case "enter": |
| 698 | txt := strings.TrimSpace(m.chatInput.Value()) |
| 699 | if txt == "" { |
| 700 | return m, nil |
| 701 | } |
| 702 | m.chatInput.SetValue("") |
| 703 | s := m.servers[m.activeID] |
| 704 | |
| 705 | // FIRST TIME: username capture |
| 706 | if m.awaitNick { |
| 707 | s.nick = txt |
| 708 | m.awaitNick = false |
| 709 | m.chatInput.Placeholder = "Type message or /command…" |
| 710 | m.pushSysLine(s.id, "_sys", "-- connecting as "+txt+" --") |
| 711 | m.refreshChat() |
| 712 | return m, m.connectServerCmd(s.id) |
| 713 | } |
| 714 | |
| 715 | if strings.HasPrefix(txt, "/") { |
| 716 | return m, m.handleSlash(s, txt) |
| 717 | } |
| 718 | |
| 719 | if m.activeChan == "" || m.activeChan == "_sys" { |
| 720 | m.pushSysLine(s.id, "_sys", "-- no channel selected, use /join #chan or select an item --") |
| 721 | m.refreshChat() |
| 722 | return m, nil |
| 723 | } |
| 724 | |
| 725 | if s.client != nil { |
| 726 | s.client.Cmd.Message(m.activeChan, txt) |
| 727 | } |
| 728 | line := styleDarkPink.Render( |
| 729 | fmt.Sprintf("[%s] <%s> %s", time.Now().Format("15:04"), s.nick, txt), |
| 730 | ) |
| 731 | return m, sendChanLineCmd(s.id, m.activeChan, line) |
| 732 | } |
| 733 | var cmd tea.Cmd |
| 734 | m.chatInput, cmd = m.chatInput.Update(key) |
| 735 | return m, cmd |
| 736 | } |
| 737 | |
| 738 | func (m *ircModel) refreshChat() { |
| 739 | if m.activeID == 0 { |
no test coverage detected