2023-08-09 16:56:17 +02:00
|
|
|
// pay-respects: Press F to correct your command
|
2023-08-09 00:14:54 +02:00
|
|
|
// Copyright (C) 2023 iff
|
|
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
2024-11-13 16:31:31 +01:00
|
|
|
use sys_locale::get_locale;
|
2023-07-31 14:27:44 +02:00
|
|
|
|
2023-07-31 14:12:45 +02:00
|
|
|
mod args;
|
2023-08-03 21:26:41 +02:00
|
|
|
mod files;
|
2024-11-23 22:51:43 +01:00
|
|
|
mod modes;
|
2024-11-15 15:32:05 +01:00
|
|
|
mod rules;
|
2023-07-30 18:40:18 +02:00
|
|
|
mod shell;
|
|
|
|
|
mod style;
|
2023-08-01 20:29:02 +02:00
|
|
|
mod suggestions;
|
2024-11-27 20:38:37 +01:00
|
|
|
mod system;
|
2023-07-30 18:40:18 +02:00
|
|
|
|
2024-11-15 15:43:04 +01:00
|
|
|
#[cfg(feature = "runtime-rules")]
|
|
|
|
|
mod replaces;
|
|
|
|
|
#[cfg(feature = "runtime-rules")]
|
|
|
|
|
mod runtime_rules;
|
|
|
|
|
|
2024-11-19 14:59:15 +01:00
|
|
|
#[cfg(feature = "request-ai")]
|
|
|
|
|
mod requests;
|
|
|
|
|
|
2024-09-25 17:55:55 +02:00
|
|
|
#[macro_use]
|
|
|
|
|
extern crate rust_i18n;
|
|
|
|
|
i18n!("i18n", fallback = "en", minify_key = true);
|
|
|
|
|
|
2024-12-06 17:35:48 +01:00
|
|
|
fn main() -> Result<(), std::io::Error>{
|
2023-08-12 22:39:00 +02:00
|
|
|
colored::control::set_override(true);
|
2024-12-06 17:35:48 +01:00
|
|
|
let mut data = {
|
|
|
|
|
let init = init();
|
|
|
|
|
if init.is_none() {
|
|
|
|
|
return Ok(());
|
|
|
|
|
} else {
|
|
|
|
|
init.unwrap()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
data.expand_command();
|
|
|
|
|
use shell::Mode;
|
|
|
|
|
match data.mode {
|
|
|
|
|
Mode::Suggestion => modes::suggestion(&mut data),
|
|
|
|
|
Mode::CNF => modes::cnf(&mut data),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init() -> Option<shell::Data> {
|
2024-11-23 00:02:34 +01:00
|
|
|
let locale = {
|
|
|
|
|
let sys_locale = get_locale().unwrap_or("en-US".to_string());
|
|
|
|
|
if sys_locale.len() < 2 {
|
|
|
|
|
"en_US".to_string()
|
|
|
|
|
} else {
|
|
|
|
|
sys_locale
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-09-26 03:02:00 +02:00
|
|
|
rust_i18n::set_locale(&locale[0..2]);
|
2023-08-12 22:39:00 +02:00
|
|
|
|
2024-12-06 17:35:48 +01:00
|
|
|
let exit = args::handle_args();
|
|
|
|
|
if exit {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 14:59:15 +01:00
|
|
|
#[cfg(feature = "request-ai")]
|
|
|
|
|
{
|
2024-11-20 21:16:14 +01:00
|
|
|
if std::env::var("_PR_AI_LOCALE").is_err() {
|
|
|
|
|
std::env::set_var("_PR_AI_LOCALE", &locale);
|
|
|
|
|
}
|
2024-11-19 14:59:15 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-06 17:35:48 +01:00
|
|
|
Some(shell::Data::init())
|
2023-07-30 18:40:18 +02:00
|
|
|
}
|