| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
#![forbid(unsafe_code)] |
| 74 |
|
| 75 |
use makeover_layout::{Bevel, Depth, Edge, Fill}; |
| 76 |
use ratatui::buffer::Buffer; |
| 77 |
use ratatui::layout::Rect; |
| 78 |
use ratatui::style::Color; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
pub use makeover_layout; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
#[cfg(feature = "theme")] |
| 93 |
pub mod theme; |
| 94 |
|
| 95 |
#[cfg(feature = "theme")] |
| 96 |
pub use theme::{Mode, Theme, ThemeError}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 106 |
pub enum Fidelity { |
| 107 |
|
| 108 |
|
| 109 |
Ansi16, |
| 110 |
|
| 111 |
Ansi256, |
| 112 |
|
| 113 |
#[default] |
| 114 |
TrueColor, |
| 115 |
} |
| 116 |
|
| 117 |
impl Fidelity { |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
#[must_use] |
| 136 |
pub fn detect() -> Self { |
| 137 |
Self::from_env( |
| 138 |
&std::env::var("COLORTERM").unwrap_or_default(), |
| 139 |
&std::env::var("TERM").unwrap_or_default(), |
| 140 |
) |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
#[must_use] |
| 147 |
pub fn from_env(colorterm: &str, term: &str) -> Self { |
| 148 |
if colorterm.contains("truecolor") || colorterm.contains("24bit") { |
| 149 |
return Self::TrueColor; |
| 150 |
} |
| 151 |
match term { |
| 152 |
"linux" | "vt100" | "vt220" | "ansi" | "dumb" => Self::Ansi16, |
| 153 |
_ if term.contains("256color") || term.contains("direct") => Self::Ansi256, |
| 154 |
_ => Self::TrueColor, |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
#[must_use] |
| 160 |
pub const fn separates_depth(self) -> bool { |
| 161 |
!matches!(self, Self::Ansi16) |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 172 |
pub struct Palette { |
| 173 |
|
| 174 |
pub page: Color, |
| 175 |
|
| 176 |
pub raised: Color, |
| 177 |
|
| 178 |
pub overlay: Color, |
| 179 |
|
| 180 |
pub well: Option<Color>, |
| 181 |
|
| 182 |
pub bevel_light: Color, |
| 183 |
|
| 184 |
pub bevel_dark: Color, |
| 185 |
|
| 186 |
pub fidelity: Fidelity, |
| 187 |
} |
| 188 |
|
| 189 |
impl Palette { |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
#[must_use] |
| 200 |
pub const fn fill(&self, fill: Fill) -> Option<Color> { |
| 201 |
match fill { |
| 202 |
Fill::Page => Some(self.page), |
| 203 |
Fill::Raised => Some(self.raised), |
| 204 |
Fill::Overlay => Some(self.overlay), |
| 205 |
Fill::Well => self.well, |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
_ => None, |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
#[must_use] |
| 216 |
pub const fn edge(&self, edge: Edge) -> Color { |
| 217 |
match edge { |
| 218 |
Edge::Light => self.bevel_light, |
| 219 |
Edge::Dark => self.bevel_dark, |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
#[must_use] |
| 229 |
pub fn shows(fill: Color, behind: Color) -> bool { |
| 230 |
fill != behind |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
#[must_use] |
| 241 |
pub fn two_tone(&self) -> bool { |
| 242 |
self.bevel_light != self.bevel_dark |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
#[must_use] |
| 250 |
pub const fn needs_glyph_depth(&self) -> bool { |
| 251 |
!self.fidelity.separates_depth() |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 271 |
pub(crate) struct GlyphSet { |
| 272 |
pub(crate) top: &'static str, |
| 273 |
pub(crate) bottom: &'static str, |
| 274 |
pub(crate) left: &'static str, |
| 275 |
pub(crate) right: &'static str, |
| 276 |
pub(crate) top_left: &'static str, |
| 277 |
pub(crate) top_right: &'static str, |
| 278 |
pub(crate) bottom_left: &'static str, |
| 279 |
pub(crate) bottom_right: &'static str, |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
pub(crate) split_corners: bool, |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
pub(crate) const BEVEL: GlyphSet = GlyphSet { |
| 304 |
top: "▀", |
| 305 |
bottom: "▄", |
| 306 |
left: "▌", |
| 307 |
right: "▐", |
| 308 |
top_left: "▛", |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
top_right: "▀", |
| 313 |
bottom_left: "▄", |
| 314 |
bottom_right: "▟", |
| 315 |
split_corners: true, |
| 316 |
}; |
| 317 |
|
| 318 |
pub(crate) const LIGHT: GlyphSet = GlyphSet { |
| 319 |
top: "─", |
| 320 |
bottom: "─", |
| 321 |
left: "│", |
| 322 |
right: "│", |
| 323 |
top_left: "┌", |
| 324 |
top_right: "┐", |
| 325 |
bottom_left: "└", |
| 326 |
bottom_right: "┘", |
| 327 |
split_corners: false, |
| 328 |
}; |
| 329 |
|
| 330 |
pub(crate) const DOUBLE: GlyphSet = GlyphSet { |
| 331 |
top: "═", |
| 332 |
bottom: "═", |
| 333 |
left: "║", |
| 334 |
right: "║", |
| 335 |
top_left: "╔", |
| 336 |
top_right: "╗", |
| 337 |
bottom_left: "╚", |
| 338 |
bottom_right: "╝", |
| 339 |
split_corners: false, |
| 340 |
}; |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
pub fn paint_bevel(buf: &mut Buffer, area: Rect, bevel: Bevel, palette: &Palette) { |
| 353 |
paint_bevel_with(buf, area, bevel, palette, set_for(palette, None)); |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
fn set_for(palette: &Palette, depth: Option<Depth>) -> GlyphSet { |
| 365 |
if !palette.needs_glyph_depth() { |
| 366 |
return BEVEL; |
| 367 |
} |
| 368 |
match depth { |
| 369 |
Some(Depth::Raised) => DOUBLE, |
| 370 |
_ => LIGHT, |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
fn paint_bevel_with(buf: &mut Buffer, area: Rect, bevel: Bevel, palette: &Palette, set: GlyphSet) { |
| 375 |
if area.width < 2 || area.height < 2 { |
| 376 |
return; |
| 377 |
} |
| 378 |
let (top_left, bottom_right) = bevel.edges(); |
| 379 |
let light = palette.edge(top_left); |
| 380 |
let dark = palette.edge(bottom_right); |
| 381 |
|
| 382 |
let (x0, y0) = (area.x, area.y); |
| 383 |
let (x1, y1) = (area.right() - 1, area.bottom() - 1); |
| 384 |
|
| 385 |
|
| 386 |
for x in x0..=x1 { |
| 387 |
buf[(x, y0)].set_symbol(set.top).set_fg(light); |
| 388 |
} |
| 389 |
for y in y0..=y1 { |
| 390 |
buf[(x0, y)].set_symbol(set.left).set_fg(light); |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
for x in x0..=x1 { |
| 395 |
buf[(x, y1)].set_symbol(set.bottom).set_fg(dark); |
| 396 |
} |
| 397 |
for y in y0..=y1 { |
| 398 |
buf[(x1, y)].set_symbol(set.right).set_fg(dark); |
| 399 |
} |
| 400 |
|
| 401 |
buf[(x0, y0)].set_symbol(set.top_left).set_fg(light); |
| 402 |
buf[(x1, y1)].set_symbol(set.bottom_right).set_fg(dark); |
| 403 |
|
| 404 |
if set.split_corners { |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
buf[(x1, y0)] |
| 410 |
.set_symbol(set.top_right) |
| 411 |
.set_fg(light) |
| 412 |
.set_bg(dark); |
| 413 |
buf[(x0, y1)] |
| 414 |
.set_symbol(set.bottom_left) |
| 415 |
.set_fg(dark) |
| 416 |
.set_bg(light); |
| 417 |
} else { |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
buf[(x1, y0)].set_symbol(set.top_right).set_fg(dark); |
| 425 |
buf[(x0, y1)].set_symbol(set.bottom_left).set_fg(dark); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
pub fn frame(buf: &mut Buffer, area: Rect, depth: Depth, palette: &Palette) -> Rect { |
| 435 |
if area.is_empty() { |
| 436 |
return area; |
| 437 |
} |
| 438 |
let behind = buf[(area.x, area.y)].bg; |
| 439 |
|
| 440 |
if let Some(color) = depth.fill().and_then(|f| palette.fill(f)) |
| 441 |
&& Palette::shows(color, behind) |
| 442 |
{ |
| 443 |
for y in area.top()..area.bottom() { |
| 444 |
for x in area.left()..area.right() { |
| 445 |
buf[(x, y)].set_bg(color); |
| 446 |
} |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
match depth.bevel() { |
| 451 |
Some(bevel) if area.width >= 2 && area.height >= 2 => { |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
let set = set_for(palette, Some(depth)); |
| 456 |
paint_bevel_with(buf, area, bevel, palette, set); |
| 457 |
Rect::new(area.x + 1, area.y + 1, area.width - 2, area.height - 2) |
| 458 |
} |
| 459 |
_ => area, |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
#[cfg(test)] |
| 464 |
mod tests { |
| 465 |
use super::*; |
| 466 |
|
| 467 |
fn palette(well: Option<Color>) -> Palette { |
| 468 |
Palette { |
| 469 |
page: Color::Indexed(7), |
| 470 |
raised: Color::Indexed(15), |
| 471 |
overlay: Color::Indexed(8), |
| 472 |
well, |
| 473 |
bevel_light: Color::Indexed(15), |
| 474 |
bevel_dark: Color::Indexed(0), |
| 475 |
fidelity: Fidelity::TrueColor, |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
fn buffer() -> Buffer { |
| 480 |
Buffer::empty(Rect::new(0, 0, 6, 4)) |
| 481 |
} |
| 482 |
|
| 483 |
#[test] |
| 484 |
fn a_well_that_cannot_be_coloured_is_still_drawn() { |
| 485 |
|
| 486 |
let p = palette(None); |
| 487 |
let mut buf = buffer(); |
| 488 |
frame(&mut buf, Rect::new(0, 0, 6, 4), Depth::Well, &p); |
| 489 |
|
| 490 |
assert_eq!(buf[(0, 0)].symbol(), BEVEL.top_left); |
| 491 |
assert_eq!(buf[(0, 0)].bg, Color::Reset); |
| 492 |
} |
| 493 |
|
| 494 |
#[test] |
| 495 |
fn a_fill_that_matches_its_surroundings_is_not_painted() { |
| 496 |
let p = palette(Some(Color::Indexed(7))); |
| 497 |
let mut buf = buffer(); |
| 498 |
|
| 499 |
|
| 500 |
for y in 0..4 { |
| 501 |
for x in 0..6 { |
| 502 |
buf[(x, y)].set_bg(Color::Indexed(7)); |
| 503 |
} |
| 504 |
} |
| 505 |
frame(&mut buf, Rect::new(0, 0, 6, 4), Depth::Well, &p); |
| 506 |
assert!(!Palette::shows(Color::Indexed(7), Color::Indexed(7))); |
| 507 |
|
| 508 |
assert_eq!(buf[(5, 3)].symbol(), BEVEL.bottom_right); |
| 509 |
} |
| 510 |
|
| 511 |
#[test] |
| 512 |
fn a_visible_fill_is_painted() { |
| 513 |
let p = palette(Some(Color::Indexed(4))); |
| 514 |
let mut buf = buffer(); |
| 515 |
frame(&mut buf, Rect::new(0, 0, 6, 4), Depth::Well, &p); |
| 516 |
assert_eq!(buf[(2, 2)].bg, Color::Indexed(4)); |
| 517 |
} |
| 518 |
|
| 519 |
#[test] |
| 520 |
fn the_light_falls_from_the_top_left() { |
| 521 |
let p = palette(None); |
| 522 |
let mut buf = buffer(); |
| 523 |
paint_bevel(&mut buf, Rect::new(0, 0, 6, 4), Bevel::Raised, &p); |
| 524 |
assert_eq!(buf[(0, 0)].fg, p.bevel_light); |
| 525 |
assert_eq!(buf[(3, 0)].fg, p.bevel_light); |
| 526 |
assert_eq!(buf[(0, 2)].fg, p.bevel_light); |
| 527 |
assert_eq!(buf[(5, 3)].fg, p.bevel_dark); |
| 528 |
assert_eq!(buf[(3, 3)].fg, p.bevel_dark); |
| 529 |
assert_eq!(buf[(5, 2)].fg, p.bevel_dark); |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
#[test] |
| 535 |
fn the_shared_corners_carry_both_tones_when_the_glyph_can_split() { |
| 536 |
let p = palette(None); |
| 537 |
let mut buf = buffer(); |
| 538 |
paint_bevel(&mut buf, Rect::new(0, 0, 6, 4), Bevel::Raised, &p); |
| 539 |
let top_right = &buf[(5, 0)]; |
| 540 |
assert_eq!(top_right.fg, p.bevel_light); |
| 541 |
assert_eq!(top_right.bg, p.bevel_dark); |
| 542 |
let bottom_left = &buf[(0, 3)]; |
| 543 |
assert_eq!(bottom_left.fg, p.bevel_dark); |
| 544 |
assert_eq!(bottom_left.bg, p.bevel_light); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
#[test] |
| 552 |
fn box_drawing_corners_stay_dark_and_match_the_immediate_renderer() { |
| 553 |
let p = Palette { |
| 554 |
fidelity: Fidelity::Ansi16, |
| 555 |
..palette(None) |
| 556 |
}; |
| 557 |
let mut buf = buffer(); |
| 558 |
paint_bevel(&mut buf, Rect::new(0, 0, 6, 4), Bevel::Raised, &p); |
| 559 |
assert_eq!(buf[(5, 0)].symbol(), LIGHT.top_right); |
| 560 |
assert_eq!(buf[(5, 0)].fg, p.bevel_dark); |
| 561 |
assert_eq!(buf[(5, 0)].bg, Color::Reset, "a stroke has no second tone"); |
| 562 |
assert_eq!(buf[(0, 3)].fg, p.bevel_dark); |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
#[test] |
| 569 |
fn a_bevel_draws_an_even_outline_and_leaves_the_middle_alone() { |
| 570 |
let p = palette(None); |
| 571 |
let mut buf = Buffer::empty(Rect::new(0, 0, 5, 4)); |
| 572 |
paint_bevel(&mut buf, Rect::new(0, 0, 5, 4), Bevel::Raised, &p); |
| 573 |
let rows: Vec<String> = (0..4) |
| 574 |
.map(|y| (0..5).map(|x| buf[(x, y)].symbol()).collect()) |
| 575 |
.collect(); |
| 576 |
assert_eq!(rows, vec!["▛▀▀▀▀", "▌ ▐", "▌ ▐", "▄▄▄▄▟"]); |
| 577 |
} |
| 578 |
|
| 579 |
#[test] |
| 580 |
fn pressing_swaps_the_lit_side() { |
| 581 |
let p = palette(None); |
| 582 |
let mut buf = buffer(); |
| 583 |
paint_bevel(&mut buf, Rect::new(0, 0, 6, 4), Bevel::Raised.pressed(), &p); |
| 584 |
assert_eq!(buf[(0, 0)].fg, p.bevel_dark); |
| 585 |
} |
| 586 |
|
| 587 |
#[test] |
| 588 |
fn a_sixteen_colour_terminal_can_lose_the_second_tone() { |
| 589 |
|
| 590 |
|
| 591 |
let flat = Palette { |
| 592 |
bevel_dark: Color::Indexed(15), |
| 593 |
..palette(None) |
| 594 |
}; |
| 595 |
assert!(!flat.two_tone()); |
| 596 |
assert!(palette(None).two_tone()); |
| 597 |
} |
| 598 |
|
| 599 |
#[test] |
| 600 |
fn an_edge_costs_a_cell_on_every_side() { |
| 601 |
let p = palette(None); |
| 602 |
let mut buf = buffer(); |
| 603 |
let inner = frame(&mut buf, Rect::new(0, 0, 6, 4), Depth::Raised, &p); |
| 604 |
assert_eq!(inner, Rect::new(1, 1, 4, 2)); |
| 605 |
|
| 606 |
let same = frame(&mut buf, Rect::new(0, 0, 6, 4), Depth::Flat, &p); |
| 607 |
assert_eq!(same, Rect::new(0, 0, 6, 4)); |
| 608 |
} |
| 609 |
|
| 610 |
#[test] |
| 611 |
fn sixteen_colours_carries_depth_in_the_glyphs_instead() { |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
let p = Palette { |
| 616 |
fidelity: Fidelity::Ansi16, |
| 617 |
..palette(None) |
| 618 |
}; |
| 619 |
assert!(p.needs_glyph_depth()); |
| 620 |
let mut raised = buffer(); |
| 621 |
frame(&mut raised, Rect::new(0, 0, 6, 4), Depth::Raised, &p); |
| 622 |
let mut well = buffer(); |
| 623 |
frame(&mut well, Rect::new(0, 0, 6, 4), Depth::Well, &p); |
| 624 |
assert_eq!(raised[(0, 0)].symbol(), DOUBLE.top_left); |
| 625 |
assert_eq!(well[(0, 0)].symbol(), LIGHT.top_left); |
| 626 |
assert_ne!(raised[(0, 0)].symbol(), well[(0, 0)].symbol()); |
| 627 |
} |
| 628 |
|
| 629 |
#[test] |
| 630 |
fn above_sixteen_colours_the_glyphs_stay_out_of_it() { |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
for f in [Fidelity::Ansi256, Fidelity::TrueColor] { |
| 635 |
let p = Palette { |
| 636 |
fidelity: f, |
| 637 |
..palette(Some(Color::Indexed(4))) |
| 638 |
}; |
| 639 |
assert!(!p.needs_glyph_depth()); |
| 640 |
let mut buf = buffer(); |
| 641 |
frame(&mut buf, Rect::new(0, 0, 6, 4), Depth::Raised, &p); |
| 642 |
assert_eq!( |
| 643 |
buf[(0, 0)].symbol(), |
| 644 |
BEVEL.top_left, |
| 645 |
"{f:?} got a heavier frame" |
| 646 |
); |
| 647 |
assert_ne!(buf[(0, 0)].symbol(), DOUBLE.top_left); |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
#[test] |
| 656 |
fn colour_alone_separates_raised_from_well_where_it_can() { |
| 657 |
let p = palette(Some(Color::Indexed(4))); |
| 658 |
let mut raised = buffer(); |
| 659 |
frame(&mut raised, Rect::new(0, 0, 6, 4), Depth::Raised, &p); |
| 660 |
let mut well = buffer(); |
| 661 |
frame(&mut well, Rect::new(0, 0, 6, 4), Depth::Well, &p); |
| 662 |
assert_eq!(raised[(0, 0)].symbol(), well[(0, 0)].symbol()); |
| 663 |
assert_eq!(raised[(0, 0)].fg, p.bevel_light); |
| 664 |
assert_eq!(well[(0, 0)].fg, p.bevel_dark); |
| 665 |
} |
| 666 |
|
| 667 |
#[test] |
| 668 |
fn detection_defaults_generously_and_only_downgrades_on_evidence() { |
| 669 |
assert!(Fidelity::default().separates_depth()); |
| 670 |
assert!(Fidelity::TrueColor.separates_depth()); |
| 671 |
assert!(Fidelity::Ansi256.separates_depth()); |
| 672 |
assert!(!Fidelity::Ansi16.separates_depth()); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
#[test] |
| 681 |
fn an_unrecognised_terminal_is_assumed_capable() { |
| 682 |
let f = Fidelity::from_env; |
| 683 |
assert_eq!(f("", "foot"), Fidelity::TrueColor); |
| 684 |
assert_eq!(f("", "xterm"), Fidelity::TrueColor); |
| 685 |
assert_eq!(f("", "screen"), Fidelity::TrueColor); |
| 686 |
assert_eq!(f("", ""), Fidelity::TrueColor); |
| 687 |
} |
| 688 |
|
| 689 |
#[test] |
| 690 |
fn a_console_that_really_has_sixteen_colours_is_named() { |
| 691 |
let f = Fidelity::from_env; |
| 692 |
assert_eq!(f("", "linux"), Fidelity::Ansi16); |
| 693 |
assert_eq!(f("", "vt100"), Fidelity::Ansi16); |
| 694 |
assert_eq!(f("", "dumb"), Fidelity::Ansi16); |
| 695 |
} |
| 696 |
|
| 697 |
#[test] |
| 698 |
fn a_terminal_naming_its_depth_is_taken_at_its_word() { |
| 699 |
let f = Fidelity::from_env; |
| 700 |
assert_eq!(f("", "xterm-256color"), Fidelity::Ansi256); |
| 701 |
assert_eq!(f("", "screen-256color"), Fidelity::Ansi256); |
| 702 |
assert_eq!(f("", "xterm-direct"), Fidelity::Ansi256); |
| 703 |
|
| 704 |
assert_eq!(f("truecolor", "xterm-256color"), Fidelity::TrueColor); |
| 705 |
assert_eq!(f("24bit", "linux"), Fidelity::TrueColor); |
| 706 |
} |
| 707 |
|
| 708 |
#[test] |
| 709 |
fn a_region_too_small_for_an_edge_is_left_alone() { |
| 710 |
let p = palette(None); |
| 711 |
let mut buf = buffer(); |
| 712 |
let inner = frame(&mut buf, Rect::new(0, 0, 1, 1), Depth::Raised, &p); |
| 713 |
assert_eq!(inner, Rect::new(0, 0, 1, 1)); |
| 714 |
} |
| 715 |
} |
| 716 |
|