emit_color is unconditionally called within emit_image, and itself unconditionally emits the color codes. If the previous character cell had the same colors, this is redundant.
Proposed: emit_color maintains a copy of the last foreground and background used, possibly as simply as keeping the string that was emitted. If it's about to emit the same one, return without emitting anything.
Challenges:
Need to initialize the last_foreground/last_background to something that cannot happen, or add a flag to indicate that it's uninitialized
What happens at the line ending, especially if -c starts applying to full image mode? Probably need to do a full reset on reaching the end of the line and set the last_* variables to their initial states.
For real-world data, the benefits might be too trivial to justify the increase in code complexity.
(This is really stefanhaustein's idea, mentioned to me in an email. I'm adding it because it sounds like a fun little project to me, not because I need it. So unless someone else has a more specific requirement, I'd consider this "wishlist" level.)
emit_color
is unconditionally called withinemit_image
, and itself unconditionally emits the color codes. If the previous character cell had the same colors, this is redundant.Proposed:
emit_color
maintains a copy of the last foreground and background used, possibly as simply as keeping the string that was emitted. If it's about to emit the same one, return without emitting anything.Challenges:
-c
starts applying to full image mode? Probably need to do a full reset on reaching the end of the line and set the last_* variables to their initial states.(This is really stefanhaustein's idea, mentioned to me in an email. I'm adding it because it sounds like a fun little project to me, not because I need it. So unless someone else has a more specific requirement, I'd consider this "wishlist" level.)