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
//! These control functions change the format.
use std::fmt::{Display, Formatter};
use crate::control::ControlSequence;
/// # 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") }