Repository: sxyazi/yazi
File: yazi-config/src/keymap/key.rs (Rust)

Code before:
				"up" => key.code = KeyCode::Up,
				"down" => key.code = KeyCode::Down,
				"home" => key.code = KeyCode::Home,
				"end" => key.code = KeyCode::End,
				"pageup" => key.code = KeyCode::PageUp,
				"pagedown" => key.code = KeyCode::PageDown,
				"tab" => key.code = KeyCode::Tab,
				"backtab" => key.code = KeyCode::BackTab,
				"delete" => key.code = KeyCode::Delete,
				"insert" => key.code = KeyCode::Insert,
				"f1" => key.code = KeyCode::F(1),
				"f2" => key.code = KeyCode::F(2),
				"f3" => key.code = KeyCode::F(3),
				"f4" => key.code = KeyCode::F(4),
				"f5" => key.code = KeyCode::F(5),
				"f6" => key.code = KeyCode::F(6),
				"f7" => key.code = KeyCode::F(7),
				"f8" => key.code = KeyCode::F(8),
				"f9" => key.code = KeyCode::F(9),
				"f10" => key.code = KeyCode::F(10),
				"f11" => key.code = KeyCode::F(11),
				"f12" => key.code = KeyCode::F(12),
				"esc" => key.code = KeyCode::Esc,

				c if it.peek().is_none() => {
					key.code = KeyCode::Char(c.chars().next().unwrap());
				}
				k => bail!("unknown key: {k}"),
			}
		}

		if key.code == KeyCode::Null {
			bail!("empty key")
		}
		Ok(key)
	}
}

impl TryFrom<String> for Key {
	type Error = anyhow::Error;

	fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(&s) }
}

impl Display for Key {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		if let Some(c) = self.plain() {
			let c = if self.shift { c.to_ascii_uppercase() } else { c };
			return if c == ' ' { write!(f, "<Space>") } else { f.write_char(c) };
		}


Review comment (suggestion):
This will cause `KeyCode::Char` to be converted to lowercase as well

Code after:
				"up" => key.code = KeyCode::Up,
				"down" => key.code = KeyCode::Down,
				"home" => key.code = KeyCode::Home,
				"end" => key.code = KeyCode::End,
				"pageup" => key.code = KeyCode::PageUp,
				"pagedown" => key.code = KeyCode::PageDown,
				"tab" => key.code = KeyCode::Tab,
				"backtab" => key.code = KeyCode::BackTab,
				"delete" => key.code = KeyCode::Delete,
				"insert" => key.code = KeyCode::Insert,
				"f1" => key.code = KeyCode::F(1),
				"f2" => key.code = KeyCode::F(2),
				"f3" => key.code = KeyCode::F(3),
				"f4" => key.code = KeyCode::F(4),
				"f5" => key.code = KeyCode::F(5),
				"f6" => key.code = KeyCode::F(6),
				"f7" => key.code = KeyCode::F(7),
				"f8" => key.code = KeyCode::F(8),
				"f9" => key.code = KeyCode::F(9),
				"f10" => key.code = KeyCode::F(10),
				"f11" => key.code = KeyCode::F(11),
				"f12" => key.code = KeyCode::F(12),
				"esc" => key.code = KeyCode::Esc,

				_ => match next {
					s if it.peek().is_none() => key.code = KeyCode::Char(s.chars().next().unwrap()),
					s => bail!("unknown key: {s}"),
				},
			}
		}

		if key.code == KeyCode::Null {
			bail!("empty key")
		}
		Ok(key)
	}
}

impl TryFrom<String> for Key {
	type Error = anyhow::Error;

	fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(&s) }
}

impl Display for Key {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		if let Some(c) = self.plain() {
			let c = if self.shift { c.to_ascii_uppercase() } else { c };
			return if c == ' ' { write!(f, "<Space>") } else { f.write_char(c) };
		}