1use comfy_table::{Table, presets::UTF8_FULL};
2use core_types::{EventKind, SecurityLevel};
3use owo_colors::OwoColorize;
4
5use crate::ipc::{connect, rpc};
6
7pub(crate) async fn cmd_input_layers() -> anyhow::Result<()> {
8 let client = connect().await?;
9
10 match rpc(&client, EventKind::InputLayersList, SecurityLevel::Internal).await? {
11 EventKind::InputLayersListResponse { layers } => {
12 if layers.is_empty() {
13 println!("{}", "No input layers configured.".dimmed());
14 } else {
15 let mut table = Table::new();
16 table.load_preset(UTF8_FULL);
17 table.set_header(vec!["Layer", "Active", "Remaps"]);
18
19 for l in &layers {
20 let active = if l.is_active {
21 "yes".green().to_string()
22 } else {
23 "no".dimmed().to_string()
24 };
25 table.add_row(vec![&l.name, &active, &l.remap_count.to_string()]);
26 }
27
28 println!("{table}");
29 }
30 }
31 other => anyhow::bail!("unexpected response: {other:?}"),
32 }
33
34 Ok(())
35}
36
37pub(crate) async fn cmd_input_status() -> anyhow::Result<()> {
38 let client = connect().await?;
39
40 match rpc(&client, EventKind::InputStatus, SecurityLevel::Internal).await? {
41 EventKind::InputStatusResponse {
42 active_layer,
43 grabbed_devices,
44 remapping_active,
45 } => {
46 let status = if remapping_active {
47 "active".green().to_string()
48 } else {
49 "inactive".yellow().to_string()
50 };
51
52 println!("Remapping: {status}");
53 println!("Active layer: {}", active_layer.bold());
54 if grabbed_devices.is_empty() {
55 println!("Grabbed devices: {}", "none".dimmed());
56 } else {
57 println!("Grabbed devices:");
58 for d in &grabbed_devices {
59 println!(" - {d}");
60 }
61 }
62 }
63 other => anyhow::bail!("unexpected response: {other:?}"),
64 }
65
66 Ok(())
67}