MCPcopy
hub / github.com/charmbracelet/bubbletea / eventLoop

Method eventLoop

tea.go:743–883  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

741// eventLoop is the central message loop. It receives and handles the default
742// Bubble Tea messages, update the model and triggers redraws.
743func (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:

Callers 1

RunMethod · 0.95

Calls 15

translateInputEventMethod · 0.95
suspendMethod · 0.95
SendMethod · 0.95
executeMethod · 0.95
execMethod · 0.95
execBatchMsgMethod · 0.95
execSequenceMsgMethod · 0.95
checkResizeMethod · 0.95
renderMethod · 0.95
setSyncdUpdatesMethod · 0.65
setWidthMethodMethod · 0.65
onMouseMethod · 0.65

Tested by

no test coverage detected