summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-04-06 00:46:16 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:43 +0300
commitce2317da9566d0aa9fbe97286fe097e57867102a (patch)
treef270f996933fa084a516aa2b9d747d0ef20fb30d
parent4bf1f6b9c920182c5ba0bae85a5192be14a7a9dc (diff)
ui: print tabs as two spaces
closes #88
-rw-r--r--ui/src/terminal/cells.rs47
1 files changed, 33 insertions, 14 deletions
diff --git a/ui/src/terminal/cells.rs b/ui/src/terminal/cells.rs
index a4c92e21..498347bc 100644
--- a/ui/src/terminal/cells.rs
+++ b/ui/src/terminal/cells.rs
@@ -695,6 +695,23 @@ pub fn change_colors(grid: &mut CellBuffer, area: Area, fg_color: Color, bg_colo
}
}
+macro_rules! inspect_bounds {
+ ($grid:ident, $area:ident, $x: ident, $y: ident, $line_break:ident) => {
+ let bounds = $grid.size();
+ let (upper_left, bottom_right) = $area;
+ if $x == (get_x(bottom_right)) + 1 || $x > get_x(bounds) {
+ $x = get_x(upper_left);
+ $y += 1;
+ if $y > (get_y(bottom_right)) || $y > get_y(bounds) {
+ return ($x, $y - 1);
+ }
+ if !$line_break {
+ break;
+ }
+ }
+ };
+}
+
/// Write an `&str` to a `CellBuffer` in a specified `Area` with the passed colors.
pub fn write_string_to_grid(
s: &str,
@@ -722,25 +739,27 @@ pub fn write_string_to_grid(
}
return (x, y);
}
- 'char: for c in s.chars() {
+ for c in s.chars() {
if c == '\r' {
continue;
}
- grid[(x, y)].set_ch(c);
- grid[(x, y)].set_fg(fg_color);
- grid[(x, y)].set_bg(bg_color);
+ if c == '\t' {
+ grid[(x, y)].set_ch(' ');
+ grid[(x, y)].set_fg(fg_color);
+ grid[(x, y)].set_bg(bg_color);
+ x += 1;
+ inspect_bounds!(grid, area, x, y, line_break);
+ grid[(x, y)].set_ch(' ');
+ grid[(x, y)].set_fg(fg_color);
+ grid[(x, y)].set_bg(bg_color);
+ } else {
+ grid[(x, y)].set_ch(c);
+ grid[(x, y)].set_fg(fg_color);
+ grid[(x, y)].set_bg(bg_color);
+ }
x += 1;
- if x == (get_x(bottom_right)) + 1 || x > get_x(bounds) {
- x = get_x(upper_left);
- y += 1;
- if y > (get_y(bottom_right)) || y > get_y(bounds) {
- return (x, y - 1);
- }
- if !line_break {
- break 'char;
- }
- }
+ inspect_bounds!(grid, area, x, y, line_break);
}
(x, y)
}