rusticity_term/
lib.rs

1pub mod app;
2pub mod aws;
3pub mod cfn;
4pub mod common;
5pub mod cw;
6pub mod ecr;
7pub mod event;
8pub mod iam;
9pub mod keymap;
10pub mod lambda;
11pub mod s3;
12pub mod session;
13pub mod sqs;
14pub mod table;
15pub mod ui;
16
17pub use app::{
18    App, DetailTab, EventColumn, EventFilterFocus, LogGroupColumn, Service, StreamSort, ViewMode,
19};
20pub use cw::insights::{DateRangeType, InsightsFocus, InsightsState, QueryLanguage, TimeUnit};
21use std::collections::HashMap;
22
23/// Initialize all services (i18n, etc.)
24pub fn init() {
25    // Load column customizations from config.toml
26    let mut i18n = HashMap::new();
27    if let Some(home) = std::env::var_os("HOME") {
28        let config_path = std::path::Path::new(&home)
29            .join(".config")
30            .join("rusticity")
31            .join("config.toml");
32
33        if let Ok(contents) = std::fs::read_to_string(&config_path) {
34            if let Ok(toml_map) = contents.parse::<toml::Table>() {
35                if let Some(columns_section) = toml_map.get("columns").and_then(|v| v.as_table()) {
36                    flatten_toml(columns_section, "column", &mut i18n);
37                }
38            }
39        }
40    }
41
42    // Initialize each service to populate their column defaults
43    lambda::init(&mut i18n);
44    ecr::init(&mut i18n);
45    s3::init(&mut i18n);
46    cw::init(&mut i18n);
47    sqs::init(&mut i18n);
48    cfn::init(&mut i18n);
49    iam::init(&mut i18n);
50
51    // Set shared i18n map after all defaults are added
52    common::set_i18n(i18n);
53}
54
55fn flatten_toml(
56    table: &toml::Table,
57    prefix: &str,
58    map: &mut std::collections::HashMap<String, String>,
59) {
60    for (key, value) in table {
61        let full_key = format!("{}.{}", prefix, key);
62        match value {
63            toml::Value::String(s) => {
64                map.insert(full_key, s.clone());
65            }
66            toml::Value::Table(t) => {
67                flatten_toml(t, &full_key, map);
68            }
69            _ => {}
70        }
71    }
72}
73
74pub use event::EventHandler;
75pub use session::Session;