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)
| 791 | // eventLoop is the central message loop. It receives and handles the default |
| 792 | // Bubble Tea messages, update the model and triggers redraws. |
| 793 | func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) { |
| 794 | for { |
| 795 | select { |
| 796 | case <-p.ctx.Done(): |
| 797 | return model, nil |
| 798 | |
| 799 | case err := <-p.errs: |
| 800 | return model, err |
| 801 | |
| 802 | case msg := <-p.msgs: |
| 803 | msg = p.translateInputEvent(msg) |
| 804 | |
| 805 | if size, ok := msg.(WindowSizeMsg); ok && !isPlausibleWindowSize(size.Width, size.Height) { |
| 806 | continue |
| 807 | } |
| 808 | |
| 809 | // Filter messages. |
| 810 | if p.filter != nil { |
| 811 | msg = p.filter(model, msg) |
| 812 | } |
| 813 | if msg == nil { |
| 814 | continue |
| 815 | } |
| 816 | |
| 817 | // Handle special internal messages. |
| 818 | switch msg := msg.(type) { |
| 819 | case QuitMsg: |
| 820 | return model, nil |
| 821 | |
| 822 | case InterruptMsg: |
| 823 | return model, ErrInterrupted |
| 824 | |
| 825 | case SuspendMsg: |
| 826 | if suspendSupported { |
| 827 | p.suspend() |
| 828 | } |
| 829 | |
| 830 | case CapabilityMsg: |
| 831 | switch msg.Content { |
| 832 | case "RGB", "Tc": |
| 833 | if *p.profile != colorprofile.TrueColor { |
| 834 | tc := colorprofile.TrueColor |
| 835 | p.profile = &tc |
| 836 | go p.Send(ColorProfileMsg{*p.profile}) |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | case ModeReportMsg: |
| 841 | switch msg.Mode { |
| 842 | case ansi.ModeSynchronizedOutput: |
| 843 | if msg.Value == ansi.ModeReset { |
| 844 | // The terminal supports synchronized output and it's |
| 845 | // currently disabled, so we can enable it on the renderer. |
| 846 | p.renderer.setSyncdUpdates(true) |
| 847 | } |
| 848 | case ansi.ModeUnicodeCore: |
| 849 | if msg.Value == ansi.ModeReset || msg.Value == ansi.ModeSet || msg.Value == ansi.ModePermanentlySet { |
| 850 | p.renderer.setWidthMethod(ansi.GraphemeWidth) |
no test coverage detected