(
position: Position,
frames: impl IntoIterator<Item = &'a Frame>,
config: &mut Config,
)
| 892 | } |
| 893 | |
| 894 | fn debug_attachments<'a>( |
| 895 | position: Position, |
| 896 | frames: impl IntoIterator<Item = &'a Frame>, |
| 897 | config: &mut Config, |
| 898 | ) -> Lines { |
| 899 | let last = matches!(position, Position::Final); |
| 900 | |
| 901 | let (opaque, entries) = debug_attachments_invoke(frames, config); |
| 902 | let opaque = opaque.render(); |
| 903 | |
| 904 | // Calculate the expected end length, by adding all values that have would contribute to the |
| 905 | // line count later. |
| 906 | let len = entries.len() + opaque.as_ref().map_or(0, |_| 1); |
| 907 | let lines = entries.into_iter().map(|value| { |
| 908 | value |
| 909 | .lines() |
| 910 | .map(ToOwned::to_owned) |
| 911 | .map(|line| { |
| 912 | Line::new().push(Instruction::Value { |
| 913 | value: line, |
| 914 | style: Style::new(), |
| 915 | }) |
| 916 | }) |
| 917 | .collect::<Vec<_>>() |
| 918 | }); |
| 919 | |
| 920 | // indentation for every first line, use `Instruction::Attachment`, otherwise use minimal |
| 921 | // indent omit that indent when we're the last value |
| 922 | lines |
| 923 | .chain(opaque.into_iter().map(|line| line.into_lines().into_vec())) |
| 924 | .enumerate() |
| 925 | .flat_map(|(idx, lines)| { |
| 926 | let position = match idx { |
| 927 | pos if pos + 1 == len && last => Position::Final, |
| 928 | 0 => Position::First, |
| 929 | _ => Position::Inner, |
| 930 | }; |
| 931 | |
| 932 | lines.into_iter().enumerate().map(move |(idx, line)| { |
| 933 | if idx == 0 { |
| 934 | line.push(Instruction::Attachment { position }) |
| 935 | } else { |
| 936 | line.push( |
| 937 | Indent::no_group() |
| 938 | .visible(!matches!(position, Position::Final)) |
| 939 | .spacing(Spacing::Minimal) |
| 940 | .into(), |
| 941 | ) |
| 942 | } |
| 943 | }) |
| 944 | }) |
| 945 | .collect() |
| 946 | } |
| 947 | |
| 948 | fn debug_render(head: Lines, contexts: VecDeque<Lines>, sources: Vec<Lines>) -> Lines { |
| 949 | let len = sources.len(); |
no test coverage detected