aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/hbb_common/src/keyboard.rs
diff options
context:
space:
mode:
authorrustdesk <[email protected]>2023-01-27 11:00:59 +0800
committerrustdesk <[email protected]>2023-01-27 11:00:59 +0800
commit17ddc89bd025dd0304b858f39a264fe707ea40bc (patch)
treeaf08cca0ed11bd69f4bd8b565383e38754dd57a1 /libs/hbb_common/src/keyboard.rs
parent2314783d4284a94711e48620e8fd9f315d1154dc (diff)
downloadrustdesk-server-17ddc89bd025dd0304b858f39a264fe707ea40bc.tar.gz
rustdesk-server-17ddc89bd025dd0304b858f39a264fe707ea40bc.zip
sync rustdesk's hbb_common here
Diffstat (limited to 'libs/hbb_common/src/keyboard.rs')
-rw-r--r--libs/hbb_common/src/keyboard.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/libs/hbb_common/src/keyboard.rs b/libs/hbb_common/src/keyboard.rs
new file mode 100644
index 0000000..10979f5
--- /dev/null
+++ b/libs/hbb_common/src/keyboard.rs
@@ -0,0 +1,39 @@
+use std::{fmt, slice::Iter, str::FromStr};
+
+use crate::protos::message::KeyboardMode;
+
+impl fmt::Display for KeyboardMode {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ KeyboardMode::Legacy => write!(f, "legacy"),
+ KeyboardMode::Map => write!(f, "map"),
+ KeyboardMode::Translate => write!(f, "translate"),
+ KeyboardMode::Auto => write!(f, "auto"),
+ }
+ }
+}
+
+impl FromStr for KeyboardMode {
+ type Err = ();
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "legacy" => Ok(KeyboardMode::Legacy),
+ "map" => Ok(KeyboardMode::Map),
+ "translate" => Ok(KeyboardMode::Translate),
+ "auto" => Ok(KeyboardMode::Auto),
+ _ => Err(()),
+ }
+ }
+}
+
+impl KeyboardMode {
+ pub fn iter() -> Iter<'static, KeyboardMode> {
+ static KEYBOARD_MODES: [KeyboardMode; 4] = [
+ KeyboardMode::Legacy,
+ KeyboardMode::Map,
+ KeyboardMode::Translate,
+ KeyboardMode::Auto,
+ ];
+ KEYBOARD_MODES.iter()
+ }
+}