countCmdLeaves runs cmd, recurses into the slice-shaped []tea.Cmd payload of tea.BatchMsg / tea.sequenceMsg (both unexported), and counts leaves where match holds, asserting what a Sequence emits without importing bubbletea's internal types.
(cmd tea.Cmd, match func(tea.Cmd, tea.Msg) bool)
| 216 | // where match holds, asserting what a Sequence emits without importing |
| 217 | // bubbletea's internal types. |
| 218 | func countCmdLeaves(cmd tea.Cmd, match func(tea.Cmd, tea.Msg) bool) int { |
| 219 | if cmd == nil { |
| 220 | return 0 |
| 221 | } |
| 222 | msg := cmd() |
| 223 | if match(cmd, msg) { |
| 224 | return 1 |
| 225 | } |
| 226 | rv := reflect.ValueOf(msg) |
| 227 | if rv.Kind() != reflect.Slice { |
| 228 | return 0 |
| 229 | } |
| 230 | n := 0 |
| 231 | for i := 0; i < rv.Len(); i++ { |
| 232 | c, ok := rv.Index(i).Interface().(tea.Cmd) |
| 233 | if !ok { |
| 234 | continue |
| 235 | } |
| 236 | n += countCmdLeaves(c, match) |
| 237 | } |
| 238 | return n |
| 239 | } |
| 240 | |
| 241 | func cmdYieldsClearScreen(cmd tea.Cmd) bool { |
| 242 | target := reflect.TypeOf(tea.ClearScreen()) |
no outgoing calls
no test coverage detected