MCPcopy Create free account
hub / github.com/GCWing/BitFun / visual_line_count_with_prefix

Method visual_line_count_with_prefix

src/apps/cli/src/ui/text_input.rs:222–238  ·  view source on GitHub ↗

Compute the total visual line count, accounting for wrap. `prefix_w` is the display width of the line prefix (e.g. 2 for "> ").

(&self, inner_width: u16, prefix_w: usize)

Source from the content-addressed store, hash-verified

220 /// Compute the total visual line count, accounting for wrap.
221 /// `prefix_w` is the display width of the line prefix (e.g. 2 for "> ").
222 pub fn visual_line_count_with_prefix(&self, inner_width: u16, prefix_w: usize) -> usize {
223 if self.input.is_empty() {
224 return 1;
225 }
226 let avail = Self::avail_width(inner_width, prefix_w);
227 self.input
228 .split('\n')
229 .map(|line_text| {
230 let text_w = line_text.width();
231 if text_w == 0 {
232 1
233 } else {
234 (text_w + avail - 1) / avail
235 }
236 })
237 .sum()
238 }
239
240 /// Convenience: compute visual line count using default prefix width of 2.
241 pub fn visual_line_count(&self, inner_width: u16) -> usize {

Callers 3

visual_line_countMethod · 0.80
ensure_cursor_visibleMethod · 0.80
render_mainMethod · 0.80

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected