@@ -150,7 +150,7 @@ impl<'a> InteractivePrinter<'a> {
150150 Ok(())
151151 }
152152
153− fn preprocess(&self, text: &str, cursor: usize) -> String {
153+ fn preprocess(&self, text: &str, cursor: &mut usize) -> String {
154154 if self.config.tab_width > 0 {
155155 expand(text, self.config.tab_width, cursor)
156156 } else {
@@ -243,19 +243,15 @@ impl<'a> Printer for InteractivePrinter<'a> {
243243 let true_color = self.config.true_color;
244244 let colored_output = self.config.colored_output;
245245
246− write!(
247− handle,
248− "{}",
249− regions
250− .iter()
251− .map(|&(style, text)| as_terminal_escaped(
252− style,
253− &*self.preprocess(text, 0),
254− true_color,
255− colored_output,
256− )).collect::<Vec<_>>()
257− .join("")
258− )?;
246+ for &(style, region) in regions.iter() {
247+ let text = &*self.preprocess(region, &mut cursor_total);
248+ write!(handle, "{}", as_terminal_escaped(
249+ style,
250+ &*text,
251+ true_color,
252+ colored_output,
253+ ))?;
254+ }
259255 } else {
260256 for &(style, region) in regions.iter() {
261257 let mut ansi_iterator = AnsiCodeIterator::new(region);
@@ -280,8 +276,9 @@ impl<'a> Printer for InteractivePrinter<'a> {
280276 (text, false) => {
281277 let text = self.preprocess(
282278 text.trim_right_matches(|c| c == '\r' || c == '\n'),
283− cursor_total,
279+ &mut cursor_total,
284280 );
281+
285282 let mut chars = text.chars();
286283 let mut remaining = text.chars().count();
287284
@@ -292,7 +289,6 @@ impl<'a> Printer for InteractivePrinter<'a> {
292289 if remaining <= available {
293290 let text = chars.by_ref().take(remaining).collect::<String>();
294291 cursor += remaining;
295− cursor_total += remaining;
296292
297293 write!(
298294 handle,
@@ -330,7 +326,6 @@ impl<'a> Printer for InteractivePrinter<'a> {
330326 // It wraps.
331327 let text = chars.by_ref().take(available).collect::<String>();
332328 cursor = 0;
333− cursor_total += available;
334329 remaining -= available;
335330
336331 write!(