summaryrefslogtreecommitdiff
path: root/utils/src/env
diff options
context:
space:
mode:
Diffstat (limited to 'utils/src/env')
-rw-r--r--utils/src/env/editor.rs19
-rw-r--r--utils/src/env/locales.rs28
-rw-r--r--utils/src/env/pager.rs15
3 files changed, 62 insertions, 0 deletions
diff --git a/utils/src/env/editor.rs b/utils/src/env/editor.rs
new file mode 100644
index 0000000..c7bd446
--- /dev/null
+++ b/utils/src/env/editor.rs
@@ -0,0 +1,19 @@
+/// Gets the default text editor based on environment variables.
+///
+/// The function checks the JV_TEXT_EDITOR and EDITOR environment variables
+/// and returns their values if they are set. If neither variable is set,
+/// it returns "jvii" as the default editor.
+///
+/// # Returns
+/// A String containing the default text editor
+pub async fn get_default_editor() -> String {
+ if let Ok(editor) = std::env::var("JV_TEXT_EDITOR") {
+ return editor;
+ }
+
+ if let Ok(editor) = std::env::var("EDITOR") {
+ return editor;
+ }
+
+ "jvii".to_string()
+}
diff --git a/utils/src/env/locales.rs b/utils/src/env/locales.rs
new file mode 100644
index 0000000..302c874
--- /dev/null
+++ b/utils/src/env/locales.rs
@@ -0,0 +1,28 @@
+/// Returns the current locale string based on environment variables.
+///
+/// The function checks for locale settings in the following order:
+/// 1. JV_LANG environment variable
+/// 2. APP_LANG environment variable
+/// 3. LANG environment variable (extracts base language before dot and replaces underscores with hyphens)
+/// 4. Defaults to "en" if no locale environment variables are found
+///
+/// # Returns
+/// A String containing the detected locale code
+pub fn current_locales() -> String {
+ if let Ok(lang) = std::env::var("JV_LANG") {
+ return lang;
+ }
+
+ if let Ok(lang) = std::env::var("APP_LANG") {
+ return lang;
+ }
+
+ if let Ok(lang) = std::env::var("LANG") {
+ if let Some(base_lang) = lang.split('.').next() {
+ return base_lang.replace('_', "-");
+ }
+ return lang;
+ }
+
+ "en".to_string()
+}
diff --git a/utils/src/env/pager.rs b/utils/src/env/pager.rs
new file mode 100644
index 0000000..3fdb1c3
--- /dev/null
+++ b/utils/src/env/pager.rs
@@ -0,0 +1,15 @@
+/// Gets the default pager based on environment variables.
+///
+/// The function checks the JV_PAGER environment variable
+/// and returns its value if it is set. If the variable is not set,
+/// it returns "less" as the default pager.
+///
+/// # Returns
+/// A String containing the default pager
+pub async fn get_default_pager() -> String {
+ if let Ok(pager) = std::env::var("JV_PAGER") {
+ return pager;
+ }
+
+ "less".to_string()
+}