coded_chars/format.rs
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
//! These control functions change the format.
use std::fmt::{Display, Formatter};
use crate::control::ControlSequence;
use crate::escape::{escape, EscapeSequence};
/// # Backspace
///
/// BS causes the active data position to be moved one character position in the data component in the
/// direction opposite to that of the implicit movement.
///
/// The direction of the implicit movement depends on the parameter value of SELECT IMPLICIT
/// MOVEMENT DIRECTION (SIMD).
pub const BS: char = '\x08';
/// # Horizontal tabulation
///
/// HT causes the active presentation position to be moved to the following character tabulation stop in the
/// presentation component.
///
/// In addition, if that following character tabulation stop has been set by TABULATION ALIGN CENTRE
/// (TAC), TABULATION ALIGN LEADING EDGE (TALE), TABULATION ALIGN TRAILING EDGE
/// (TATE) or TABULATION CENTRED ON CHARACTER (TCC), HT indicates the beginning of a string
/// of text which is to be positioned within a line according to the properties of that tabulation stop. The end
/// of the string is indicated by the next occurrence of HT or CARRIAGE RETURN (CR) or NEXT LINE
/// (NEL) in the data stream.
pub const HT: char = '\x09';
/// # Line feed
///
/// If the DEVICE COMPONENT SELECT MODE (DCSM) is set to PRESENTATION, LF causes the
/// active presentation position to be moved to the corresponding character position of the following line in
/// the presentation component.
///
/// If the DEVICE COMPONENT SELECT MODE (DCSM) is set to DATA, LF causes the active data
/// position to be moved to the corresponding character position of the following line in the data
/// component
pub const LF: char = '\x0A';
/// # Vertical tabulation
///
/// VT causes the active presentation position to be moved in the presentation component to the
/// corresponding character position on the line at which the following line tabulation stop is set.
pub const VT: char = '\x0B';
/// # Form feed
///
/// FF causes the active presentation position to be moved to the corresponding character position of the
/// line at the page home position of the next form or page in the presentation component. The page home
/// position is established by the parameter value of SET PAGE HOME (SPH).
pub const FF: char = '\x0C';
/// # Carriage return
///
/// The effect of CR depends on the setting of the DEVICE COMPONENT SELECT MODE (DCSM) and
/// on the parameter value of SELECT IMPLICIT MOVEMENT DIRECTION (SIMD).
///
/// If the DEVICE COMPONENT SELECT MODE (DCSM) is set to PRESENTATION and with the
/// parameter value of SIMD equal to 0, CR causes the active presentation position to be moved to the line
/// home position of the same line in the presentation component. The line home position is established by
/// the parameter value of SET LINE HOME (SLH).
///
/// With a parameter value of SIMD equal to 1, CR causes the active presentation position to be moved to
/// the line limit position of the same line in the presentation component. The line limit position is
/// established by the parameter value of SET LINE LIMIT (SLL).
///
/// If the DEVICE COMPONENT SELECT MODE (DCSM) is set to DATA and with a parameter value of
/// SIMD equal to 0, CR causes the active data position to be moved to the line home position of the same
/// line in the data component. The line home position is established by the parameter value of SET LINE
/// HOME (SLH).
///
/// With a parameter value of SIMD equal to 1, CR causes the active data position to be moved to the line
/// limit position of the same line in the data component. The line limit position is established by the
/// parameter value of SET LINE LIMIT (SLL).
pub const CR: char = '\x0D';
/// # Character tabulation with justification
///
/// HTJ causes the contents of the active field (the field in the presentation component that contains the
/// active presentation position) to be shifted forward so that it ends at the character position preceding the
/// following character tabulation stop. The active presentation position is moved to that following character
/// tabulation stop. The character positions which precede the beginning of the shifted string are put into the
/// erased state.
pub const HTJ: EscapeSequence = escape('I');
/// # Character tabulation set
///
/// HTS causes a character tabulation stop to be set at the active presentation position in the presentation component.
///
/// The number of lines affected depends on the setting of the TABULATION STOP MODE (TSM).
pub const HTS: EscapeSequence = escape('H');
/// # Next line
///
/// The effect of NEL depends on the setting of the DEVICE COMPONENT SELECT MODE (DCSM) and
/// on the parameter value of SELECT IMPLICIT MOVEMENT DIRECTION (SIMD).
///
/// If the DEVICE COMPONENT SELECT MODE (DCSM) is set to PRESENTATION and with a
/// parameter value of SIMD equal to 0, NEL causes the active presentation position to be moved to the line
/// home position of the following line in the presentation component. The line home position is established
/// by the parameter value of SET LINE HOME (SLH).
///
/// With a parameter value of SIMD equal to 1, NEL causes the active presentation position to be moved to
/// the line limit position of the following line in the presentation component. The line limit position is
/// established by the parameter value of SET LINE LIMIT (SLL).
///
/// If the DEVICE COMPONENT SELECT MODE (DCSM) is set to DATA and with a parameter value of
/// SIMD equal to 0, NEL causes the active data position to be moved to the line home position of the
/// following line in the data component. The line home position is established by the parameter value of
/// SET LINE HOME (SLH).
///
/// With a parameter value of SIMD equal to 1, NEL causes the active data position to be moved to the line
/// limit position of the following line in the data component. The line limit position is established by the
/// parameter value of SET LINE LIMIT (SLL).
pub const NEL: EscapeSequence = escape('E');
/// # Partial line forward
///
/// PLD causes the active presentation position to be moved in the presentation component to the
/// corresponding position of an imaginary line with a partial offset in the direction of the line progression.
/// This offset should be sufficient either to image following characters as subscripts until the first
/// following occurrence of PARTIAL LINE BACKWARD (PLU) in the data stream, or, if preceding
/// characters were imaged as superscripts, to restore imaging of following characters to the active line (the
/// line that contains the active presentation position).
///
/// Any interactions between PLD and format effectors other than PLU are not defined by this Standard.
pub const PLD: EscapeSequence = escape('K');
/// # Partial line backward
///
/// PLU causes the active presentation position to be moved in the presentation component to the
/// corresponding position of an imaginary line with a partial offset in the direction opposite to that of the
/// line progression. This offset should be sufficient either to image following characters as superscripts
/// until the first following occurrence of PARTIAL LINE FORWARD (PLD) in the data stream, or, if
/// preceding characters were imaged as subscripts, to restore imaging of following characters to the active
/// line (the line that contains the active presentation position).
///
/// Any interactions between PLU and format effectors other than PLD are not defined by this Standard.
pub const PLU: EscapeSequence = escape('L');
/// Reserve line feed
pub const RI: EscapeSequence = escape('M');
/// # Line tabulation set
///
/// VTS causes a line tabulation stop to be set at the active line (the line that contains the active presentation position).
pub const VTS: EscapeSequence = escape('J');
/// # HPA - Character position absolute
///
/// HPA causes the active data position to be moved to character position `n` in the active line (the line in the
/// data component that contains the active data position).
pub fn character_absolute(n: usize) -> ControlSequence {
ControlSequence::new(&[&n.to_string()], "`")
}
/// # HPB - Character position backward
///
/// HPB causes the active data position to be moved by `n` character positions in the data component in the
/// direction opposite to that of the character progression.
pub fn character_backward(n: usize) -> ControlSequence {
ControlSequence::new(&[&n.to_string()], "j")
}
/// # HPR - Character position forward
///
/// HPR causes the active data position to be moved by `n` character positions in the data component in the
/// direction of the character progression.
pub fn character_forward(n: usize) -> ControlSequence {
ControlSequence::new(&[&n.to_string()], "a")
}
/// # HVP - Character and line position
///
/// HVP causes the active data position to be moved in the data component to the `l`-th line position
/// according to the line progression and to the `c`-th character position according to the character
/// progression.
pub fn character_and_line_position(l: usize, c: usize) -> ControlSequence {
ControlSequence::new(&[&l.to_string(), &c.to_string()], "f")
}
/// # PPA - Page position absolute
///
/// PPA causes the active data position to be moved in the data component to the corresponding character
/// position on the `n`-th page.
pub fn page_position(n: usize) -> ControlSequence {
ControlSequence::new(&[&n.to_string()], " P")
}
/// # PPB - Page position backward
///
/// PPB causes the active data position to be moved in the data component to the corresponding character
/// position on the `n`-th preceding page.
pub fn page_backward(n: usize) -> ControlSequence {
ControlSequence::new(&[&n.to_string()], " R")
}
/// # PPR - Page position forward
///
/// PPR causes the active data position to be moved in the data component to the corresponding character
/// position on the `n`-th following page.
pub fn page_forward(n: usize) -> ControlSequence {
ControlSequence::new(&[&n.to_string()], " Q")
}
/// # TBC - Tabulation clear
///
/// TBC causes one or more tabulation stops in the presentation component to be cleared.
pub fn clear_tabulation(tabulation_control: TabulationControl) -> ControlSequence {
ControlSequence::new(&[&tabulation_control.to_string()], "g")
}
#[derive(Copy, Clone, Debug)]
pub enum TabulationControl {
/// A character tabulation stop is set at the active presentation position.
Character,
/// A line tabulation stop is set at the active line (the line that contains the active presentation position).
Line,
/// The character tabulation stop at the active presentation position is cleared.
CharacterRemove,
/// The line tabulation stop at the active line is cleared.
LineRemove,
/// All character tabulation stops in the active line are cleared.
CharacterClearLine,
/// All character tabulation stops are cleared.
CharacterClearAll,
/// All line tabulation stops are cleared.
LineClearAll,
}
impl Display for TabulationControl {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
TabulationControl::Character => "0",
TabulationControl::Line => "1",
TabulationControl::CharacterRemove => "2",
TabulationControl::LineRemove => "3",
TabulationControl::CharacterClearLine => "4",
TabulationControl::CharacterClearAll => "5",
TabulationControl::LineClearAll => "6",
})
}
}
/// # TSR - Tabulation stop remove
///
/// TSR causes any character tabulation stop at character position n in the active line (the line that contains
/// the active presentation position) and lines of subsequent text in the presentation component to be
/// cleared, but does not affect other tabulation stops.
pub fn remove_tabulation_stop(n: usize) -> ControlSequence {
ControlSequence::new(&[&n.to_string()], " d")
}
/// # VPA - Line position absolute
///
/// VPA causes the active data position to be moved to line position n in the data component in a direction
/// parallel to the line progression.
pub fn line_position(n: usize) -> ControlSequence { ControlSequence::new(&[&n.to_string()], "d") }
/// # VPB - Line position backward
///
/// VPB causes the active data position to be moved by n line positions in the data component in a direction
/// opposite to that of the line progression.
pub fn line_backward(n: usize) -> ControlSequence { ControlSequence::new(&[&n.to_string()], "k") }
/// # VPR - Line position forward
///
/// VPR causes the active data position to be moved by n line positions in the data component in a direction
/// parallel to the line progression.
pub fn line_forward(n: usize) -> ControlSequence { ControlSequence::new(&[&n.to_string()], "e") }