control_code/csi/
mode.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 Mode {
19	GuardedAreaTransfer,
20	KeyboardLock,
21	ControlRepresentation,
22	InsertionReplacement,
23	StatusReportTransfer,
24	Erasure,
25	LineEditing,
26	BidirectionalSupport,
27	DeviceComponentSelect,
28	CharacterEditing,
29	PositioningUnit,
30	SendReceive,
31	FormatEffectorAction,
32	FormatEffectorTransfer,
33	MultipleAreaTransfer,
34	TransferTermination,
35	SelectedAreaTransfer,
36	TabulationStop,
37	LineFeed,
38	GraphicRenditionCombination,
39	ZeroDefault,
40}
41
42impl Mode {
43	#[inline]
44	pub fn parse<'a>(value: u32) -> Result<Self, nom::ErrorKind> {
45		match value {
46			1  => Ok(Mode::GuardedAreaTransfer),
47			2  => Ok(Mode::KeyboardLock),
48			3  => Ok(Mode::ControlRepresentation),
49			4  => Ok(Mode::InsertionReplacement),
50			5  => Ok(Mode::StatusReportTransfer),
51			6  => Ok(Mode::Erasure),
52			7  => Ok(Mode::LineEditing),
53			8  => Ok(Mode::BidirectionalSupport),
54			9  => Ok(Mode::DeviceComponentSelect),
55			10 => Ok(Mode::CharacterEditing),
56			11 => Ok(Mode::PositioningUnit),
57			12 => Ok(Mode::SendReceive),
58			13 => Ok(Mode::FormatEffectorAction),
59			14 => Ok(Mode::FormatEffectorTransfer),
60			15 => Ok(Mode::MultipleAreaTransfer),
61			16 => Ok(Mode::TransferTermination),
62			17 => Ok(Mode::SelectedAreaTransfer),
63			18 => Ok(Mode::TabulationStop),
64			20 => Ok(Mode::LineFeed),
65			21 => Ok(Mode::GraphicRenditionCombination),
66			22 => Ok(Mode::ZeroDefault),
67			_  => Err(nom::ErrorKind::Custom(9004)),
68		}
69	}
70}
71
72impl Into<u32> for Mode {
73	#[inline]
74	fn into(self) -> u32 {
75		match self {
76			Mode::GuardedAreaTransfer         => 1,
77			Mode::KeyboardLock                => 2,
78			Mode::ControlRepresentation       => 3,
79			Mode::InsertionReplacement        => 4,
80			Mode::StatusReportTransfer        => 5,
81			Mode::Erasure                     => 6,
82			Mode::LineEditing                 => 7,
83			Mode::BidirectionalSupport        => 8,
84			Mode::DeviceComponentSelect       => 9,
85			Mode::CharacterEditing            => 10,
86			Mode::PositioningUnit             => 11,
87			Mode::SendReceive                 => 12,
88			Mode::FormatEffectorAction        => 13,
89			Mode::FormatEffectorTransfer      => 14,
90			Mode::MultipleAreaTransfer        => 15,
91			Mode::TransferTermination         => 16,
92			Mode::SelectedAreaTransfer        => 17,
93			Mode::TabulationStop              => 18,
94			Mode::LineFeed                    => 20,
95			Mode::GraphicRenditionCombination => 21,
96			Mode::ZeroDefault                 => 22,
97		}
98	}
99}