control_code/csi/
tabulation_control.rs

1//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                    Version 2, December 2004
3//
4// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14
15use nom;
16
17#[derive(Eq, PartialEq, Copy, Clone, Debug)]
18pub enum TabulationControl {
19	Character,
20	Line,
21	ClearCharacter,
22	ClearLine,
23	ClearCharacters,
24	ClearAllCharacters,
25	ClearAllLines,
26}
27
28impl TabulationControl {
29	#[inline]
30	pub fn parse<'a>(value: u32) -> Result<Self, nom::ErrorKind> {
31		match value {
32			0 => Ok(TabulationControl::Character),
33			1 => Ok(TabulationControl::Line),
34			2 => Ok(TabulationControl::ClearCharacter),
35			3 => Ok(TabulationControl::ClearLine),
36			4 => Ok(TabulationControl::ClearCharacters),
37			5 => Ok(TabulationControl::ClearAllCharacters),
38			6 => Ok(TabulationControl::ClearAllLines),
39			_ => Err(nom::ErrorKind::Custom(9003)),
40		}
41	}
42}
43
44impl Into<u32> for TabulationControl {
45	#[inline]
46	fn into(self) -> u32 {
47		match self {
48			TabulationControl::Character          => 0,
49			TabulationControl::Line               => 1,
50			TabulationControl::ClearCharacter     => 2,
51			TabulationControl::ClearLine          => 3,
52			TabulationControl::ClearCharacters    => 4,
53			TabulationControl::ClearAllCharacters => 5,
54			TabulationControl::ClearAllLines      => 6,
55		}
56	}
57}