(root: &Frame, prefix: &[&Frame], config: &mut Config)
| 1020 | } |
| 1021 | |
| 1022 | fn debug_frame(root: &Frame, prefix: &[&Frame], config: &mut Config) -> Vec<Lines> { |
| 1023 | let (stack, sources) = collect(root, prefix); |
| 1024 | let (stack, prefix) = partition(&stack); |
| 1025 | |
| 1026 | let len = stack.len(); |
| 1027 | // collect all the contexts that we have partitioned previously and render them |
| 1028 | let mut contexts: VecDeque<_> = stack |
| 1029 | .into_iter() |
| 1030 | .enumerate() |
| 1031 | .map(|(idx, (head, mut body))| { |
| 1032 | // each "paket" on the stack is made up of a head (guaranteed to be a `Context`) and |
| 1033 | // `n` attachments. |
| 1034 | // The attachments are rendered as direct descendants of the parent context |
| 1035 | let head_context = debug_context( |
| 1036 | match head.kind() { |
| 1037 | FrameKind::Context(context) => context, |
| 1038 | FrameKind::Attachment(_) => unreachable!(), |
| 1039 | }, |
| 1040 | config.color_mode(), |
| 1041 | ); |
| 1042 | |
| 1043 | // reverse all attachments, to make it more logical relative to the attachment order |
| 1044 | body.reverse(); |
| 1045 | let body = debug_attachments( |
| 1046 | // This makes sure that we use `╰─` instead of `├─`, |
| 1047 | // this is true whenever we only have a single context and no sources, |
| 1048 | // **or** if our idx is larger than `0`, this might sound false, |
| 1049 | // but this is because contexts other than the first context create a new |
| 1050 | // "indentation", in this indentation we are considered last. |
| 1051 | // |
| 1052 | // Context A |
| 1053 | // ├╴Attachment B |
| 1054 | // ├╴Attachment C <- not last, because we are not the only context |
| 1055 | // | |
| 1056 | // ╰─▶ Context D <- indentation here is handled by `debug_render`! |
| 1057 | // ├╴Attachment E |
| 1058 | // ╰╴Attachment F <- last because it's the last of the parent context! |
| 1059 | if (len == 1 && sources.is_empty()) || idx > 0 { |
| 1060 | Position::Final |
| 1061 | } else { |
| 1062 | Position::Inner |
| 1063 | }, |
| 1064 | once(head).chain(body), |
| 1065 | config, |
| 1066 | ); |
| 1067 | head_context.then(body) |
| 1068 | }) |
| 1069 | .collect(); |
| 1070 | |
| 1071 | let sources = sources |
| 1072 | .iter() |
| 1073 | .flat_map( |
| 1074 | // if the group is "transparent" (has no context), it will return all it's parents |
| 1075 | // rendered this is why we must first flat_map. |
| 1076 | |source| debug_frame(source, &prefix, config), |
| 1077 | ) |
| 1078 | .collect::<Vec<_>>(); |
| 1079 |
no test coverage detected