| ... | @@ -1106,6 +1106,7 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) struct { []u8, usize } { | ... | @@ -1106,6 +1106,7 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) struct { []u8, usize } { |
| 1106 | fn computePrefix( | 1106 | fn computePrefix( |
| 1107 | buf: []u8, | 1107 | buf: []u8, |
| 1108 | start_i: usize, | 1108 | start_i: usize, |
| | 1109 | nl_n: usize, |
| 1109 | serialized: Serialized, | 1110 | serialized: Serialized, |
| 1110 | children: []const Children, | 1111 | children: []const Children, |
| 1111 | node_index: Node.Index, | 1112 | node_index: Node.Index, |
| ... | @@ -1118,25 +1119,29 @@ fn computePrefix( | ... | @@ -1118,25 +1119,29 @@ fn computePrefix( |
| 1118 | { | 1119 | { |
| 1119 | return i; | 1120 | return i; |
| 1120 | } | 1121 | } |
| 1121 | i = computePrefix(buf, i, serialized, children, parent_index); | 1122 | i = computePrefix(buf, i, nl_n, serialized, children, parent_index); |
| 1122 | if (children[@intFromEnum(parent_index)].sibling == .none) { | 1123 | if (children[@intFromEnum(parent_index)].sibling == .none) { |
| 1123 | const prefix = " "; | 1124 | const prefix = " "; |
| 1124 | const upper_bound_len = prefix.len + line_upper_bound_len; | 1125 | const upper_bound_len = prefix.len + lineUpperBoundLen(nl_n); |
| 1125 | if (i + upper_bound_len > buf.len) return buf.len; | 1126 | if (i + upper_bound_len > buf.len) return buf.len; |
| 1126 | buf[i..][0..prefix.len].* = prefix.*; | 1127 | buf[i..][0..prefix.len].* = prefix.*; |
| 1127 | i += prefix.len; | 1128 | i += prefix.len; |
| 1128 | } else { | 1129 | } else { |
| 1129 | const upper_bound_len = comptime (TreeSymbol.line.maxByteLen() + line_upper_bound_len); | 1130 | const upper_bound_len = TreeSymbol.line.maxByteLen() + lineUpperBoundLen(nl_n); |
| 1130 | if (i + upper_bound_len > buf.len) return buf.len; | 1131 | if (i + upper_bound_len > buf.len) return buf.len; |
| 1131 | i = appendTreeSymbol(.line, buf, i); | 1132 | i = appendTreeSymbol(.line, buf, i); |
| 1132 | } | 1133 | } |
| 1133 | return i; | 1134 | return i; |
| 1134 | } | 1135 | } |
| 1135 | | 1136 | |
| 1136 | // \r\n on Windows, \n otherwise. | 1137 | fn lineUpperBoundLen(nl_n: usize) usize { |
| 1137 | const nl_len = if (is_windows) 2 else 1; | 1138 | // \r\n on Windows, \n otherwise. |
| 1138 | const line_upper_bound_len = @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) + | 1139 | const nl_len = if (is_windows) 2 else 1; |
| 1139 | "[4294967296/4294967296] ".len + Node.max_name_len + nl_len + (1 + up_one_line.len) + finish_sync.len; | 1140 | return @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) + |
| | 1141 | "[4294967296/4294967296] ".len + Node.max_name_len + nl_len + |
| | 1142 | (1 + (nl_n + 1) * up_one_line.len) + |
| | 1143 | finish_sync.len; |
| | 1144 | } |
| 1140 | | 1145 | |
| 1141 | fn computeNode( | 1146 | fn computeNode( |
| 1142 | buf: []u8, | 1147 | buf: []u8, |
| ... | @@ -1149,9 +1154,9 @@ fn computeNode( | ... | @@ -1149,9 +1154,9 @@ fn computeNode( |
| 1149 | var i = start_i; | 1154 | var i = start_i; |
| 1150 | var nl_n = start_nl_n; | 1155 | var nl_n = start_nl_n; |
| 1151 | | 1156 | |
| 1152 | i = computePrefix(buf, i, serialized, children, node_index); | 1157 | i = computePrefix(buf, i, nl_n, serialized, children, node_index); |
| 1153 | | 1158 | |
| 1154 | if (i + line_upper_bound_len > buf.len) | 1159 | if (i + lineUpperBoundLen(nl_n) > buf.len) |
| 1155 | return .{ start_i, start_nl_n }; | 1160 | return .{ start_i, start_nl_n }; |
| 1156 | | 1161 | |
| 1157 | const storage = &serialized.storage[@intFromEnum(node_index)]; | 1162 | const storage = &serialized.storage[@intFromEnum(node_index)]; |