| 1 | use codewhale_localization::Locale; |
| 2 | use serde_json::{Value, json}; |
| 3 | |
| 4 | use crate::tui::shell_key_routing::SHELL_BINDINGS; |
| 5 | |
| 6 | #[must_use] |
| 7 | pub fn slash_commands() -> Value { |
| 8 | let mut infos: Vec<_> = crate::commands::command_infos() |
| 9 | .into_iter() |
| 10 | .filter(|info| !info.is_unlisted()) |
| 11 | .collect(); |
| 12 | infos.sort_by_key(|info| info.name); |
| 13 | Value::Array( |
| 14 | infos |
| 15 | .into_iter() |
| 16 | .map(|info| { |
| 17 | json!({ |
| 18 | "name": info.name, |
| 19 | "aliases": info.aliases, |
| 20 | "usage": info.usage, |
| 21 | "subcommands": info.subcommands(), |
| 22 | "description": info.description_for(Locale::En), |
| 23 | "discovery": format!("{:?}", info.discovery()).to_ascii_lowercase(), |
| 24 | }) |
| 25 | }) |
| 26 | .collect(), |
| 27 | ) |
| 28 | } |
| 29 | |
| 30 | #[must_use] |
| 31 | pub fn keybindings() -> Value { |
| 32 | Value::Array( |
| 33 | SHELL_BINDINGS |
| 34 | .iter() |
| 35 | .map(|binding| { |
| 36 | json!({ |
| 37 | "id": format!("{:?}", binding.id), |
| 38 | "chord": binding.catalog_chord, |
| 39 | "focus": format!("{:?}", binding.focus), |
| 40 | }) |
| 41 | }) |
| 42 | .collect(), |
| 43 | ) |
| 44 | } |
| 45 |