ctl_layout/frame.rs
1//! How a table or a record is framed.
2
3use crate::widths::Framing;
4
5/// What a table draws around and between its columns.
6///
7/// Rules are drawn with box characters, or with ASCII for
8/// [`BoxChars::Ascii`](ctl_text::BoxChars::Ascii). The frame decides how a
9/// table treats a word wider than its column: [`Grid`](Self::Grid) folds it,
10/// and the other two let it run past the width.
11#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
12#[non_exhaustive]
13pub enum Frame {
14 /// An outer frame, column rules, and a rule under the header. A word
15 /// wider than its column folds, so the frame stays aligned.
16 #[default]
17 Grid,
18 /// One rule under the header and nothing else. A table with no header
19 /// draws no rule.
20 HeaderRule,
21 /// No rules at all. Columns are separated by two spaces, and no line
22 /// ends in a space.
23 Plain,
24}
25
26impl Frame {
27 /// Whether the frame has an outer border that a wide word would break.
28 /// One match here keeps every width decision of a table in step.
29 pub(crate) fn framing(self) -> Framing {
30 match self {
31 Self::Grid => Framing::Framed,
32 Self::HeaderRule | Self::Plain => Framing::Unframed,
33 }
34 }
35}
36
37/// What separates consecutive rows of a table.
38///
39/// The separator goes between rows only. It is never drawn above the first
40/// row, below the last, or between the header and the first row.
41#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
42#[non_exhaustive]
43pub enum RowSeparation {
44 /// Rows print on consecutive lines.
45 #[default]
46 None,
47 /// A horizontal rule between each pair of rows, as wide as the table.
48 Rule,
49 /// A blank row between each pair of rows. In a grid it keeps the column
50 /// rules.
51 Blank,
52}
53
54/// How a [`Record`](crate::Record) of key and value rows is drawn.
55#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
56#[non_exhaustive]
57pub enum RecordStyle {
58 /// No frame. Keys are right-aligned in one column.
59 #[default]
60 KeysRight,
61 /// No frame. Keys are left-aligned in one column.
62 KeysLeft,
63 /// An outer frame with one rule between the keys and the values. Keys are
64 /// left-aligned.
65 Boxed,
66}