eventLoop is the central message loop. It receives and handles the default Bubble Tea messages, update the model and triggers redraws.
(model Model, cmds chan Cmd)
| 741 | // eventLoop is the central message loop. It receives and handles the default |
| 742 | // Bubble Tea messages, update the model and triggers redraws. |
| 743 | func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) { |
| 744 | for { |
| 745 | select { |
| 746 | case <-p.ctx.Done(): |
| 747 | return model, nil |
| 748 | |
| 749 | case err := <-p.errs: |
| 750 | return model, err |
| 751 | |
| 752 | case msg := <-p.msgs: |
| 753 | msg = p.translateInputEvent(msg) |
| 754 | |
| 755 | // Filter messages. |
| 756 | if p.filter != nil { |
| 757 | msg = p.filter(model, msg) |
| 758 | } |
| 759 | if msg == nil { |
| 760 | continue |
| 761 | } |
| 762 | |
| 763 | // Handle special internal messages. |
| 764 | switch msg := msg.(type) { |
| 765 | case QuitMsg: |
| 766 | return model, nil |
| 767 | |
| 768 | case InterruptMsg: |
| 769 | return model, ErrInterrupted |
| 770 | |
| 771 | case SuspendMsg: |
| 772 | if suspendSupported { |
| 773 | p.suspend() |
| 774 | } |
| 775 | |
| 776 | case CapabilityMsg: |
| 777 | switch msg.Content { |
| 778 | case "RGB", "Tc": |
| 779 | if *p.profile != colorprofile.TrueColor { |
| 780 | tc := colorprofile.TrueColor |
| 781 | p.profile = &tc |
| 782 | go p.Send(ColorProfileMsg{*p.profile}) |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | case ModeReportMsg: |
| 787 | switch msg.Mode { |
| 788 | case ansi.ModeSynchronizedOutput: |
| 789 | if msg.Value == ansi.ModeReset { |
| 790 | // The terminal supports synchronized output and it's |
| 791 | // currently disabled, so we can enable it on the renderer. |
| 792 | p.renderer.setSyncdUpdates(true) |
| 793 | } |
| 794 | case ansi.ModeUnicodeCore: |
| 795 | if msg.Value == ansi.ModeReset || msg.Value == ansi.ModeSet || msg.Value == ansi.ModePermanentlySet { |
| 796 | p.renderer.setWidthMethod(ansi.GraphemeWidth) |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | case MouseMsg: |
no test coverage detected