SHA256
Compare commits
5
Commits
5597b56538
...
myaster
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
c80ffc897c | ||
|
|
2321d06af1 | ||
|
|
1186932625 | ||
|
|
740bbdb4d8 | ||
|
|
7c57193bf1 |
No files matched your search
Generated
+53
-43
@@ -88,9 +88,9 @@ checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.104"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902"
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
@@ -132,9 +132,9 @@ checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.8"
|
||||
version = "0.7.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
|
||||
checksum = "47a64a0fd06e123e9e3cf3ad01432af17dcab8185e8023edcf184fe696f9675d"
|
||||
|
||||
[[package]]
|
||||
name = "as-raw-xcb-connection"
|
||||
@@ -514,9 +514,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.11.3"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69"
|
||||
checksum = "95e45cf2980b2d467be49a9ed942c9179b701063a7ca3d037de7ee9bd67f8d66"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"jobserver",
|
||||
@@ -701,9 +701,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.5"
|
||||
version = "1.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64"
|
||||
checksum = "fd9ae8fcb3ea71b0b26338b4ffb13006bb175de8fd07921089a906ce7e5e6945"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
@@ -989,9 +989,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.15"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
||||
checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
@@ -1237,9 +1237,9 @@ checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
|
||||
|
||||
[[package]]
|
||||
name = "globset"
|
||||
version = "0.4.21"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f98b0d85522dc0a824cfebbc9594ff4a9b289c568bea0370319dfbdf20ccdd2d"
|
||||
checksum = "71217a07f20b48b4938c14203b77b610f8a7fa6762c3f75394a10c5f31e5aee0"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"bstr",
|
||||
@@ -1315,9 +1315,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.1"
|
||||
version = "0.17.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
@@ -1553,9 +1553,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ignore"
|
||||
version = "0.4.34"
|
||||
version = "0.4.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "484be5657551d7868d67587df967fb4fcbe9d266a761cc855aaa148fda0b3cc7"
|
||||
checksum = "df0a7d5f105e76bda602bed0a44af048542d3c9af12ec35aaf16f106c6f34270"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"globset",
|
||||
@@ -1614,7 +1614,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.17.1",
|
||||
"hashbrown 0.17.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1754,6 +1754,8 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"time-format",
|
||||
"unicode-segmentation",
|
||||
"xkbcommon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1845,9 +1847,9 @@ checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "litrs"
|
||||
version = "1.0.1"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4744e383959f0db86ede514b809b1c53251889093803c05267acc7d4e7030d70"
|
||||
checksum = "02b614978e47ce529faee66579f2b2fe19c94aa96d910a6a9a8043b2b02d8175"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
@@ -2704,7 +2706,7 @@ version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
|
||||
dependencies = [
|
||||
"toml_edit 0.25.19+spec-1.1.0",
|
||||
"toml_edit 0.25.21+spec-1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2825,9 +2827,9 @@ checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||
|
||||
[[package]]
|
||||
name = "rangemap"
|
||||
version = "1.8.0"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a611d15b50743feb4c76b7d03edcb0e64f399c26961e4efe6975bc398be6aa3d"
|
||||
checksum = "f2d43a8c8c74056248124068fde0df374d1ddf9039e747d190f01c36faeaab08"
|
||||
|
||||
[[package]]
|
||||
name = "rav1e"
|
||||
@@ -3249,12 +3251,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "simd_helpers"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6"
|
||||
dependencies = [
|
||||
"quote",
|
||||
]
|
||||
checksum = "f48ea32978b7ad365bd1ecce83827746d5d50dc006a8c85112b7acc3c716e3e7"
|
||||
|
||||
[[package]]
|
||||
name = "simdutf8"
|
||||
@@ -3606,9 +3605,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.19+spec-1.1.0"
|
||||
version = "0.25.21+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218"
|
||||
checksum = "88497dab46de5bf343ec66b05c251e48c6213f3e9170c70a70a823f7abe886a4"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime 1.1.3+spec-1.1.0",
|
||||
@@ -3618,9 +3617,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.1.5+spec-1.1.0"
|
||||
version = "1.1.7+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c"
|
||||
checksum = "0bb28d6e049a9766c3bd91a8326e6179f5b132dec87906bb97018ef7a2f3431a"
|
||||
dependencies = [
|
||||
"winnow 1.0.5",
|
||||
]
|
||||
@@ -3759,9 +3758,9 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
version = "2.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
checksum = "b42e295b7452c4604982280d8586001fcad9b8b201cac67bca9771e7a7475403"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
@@ -4290,6 +4289,17 @@ version = "0.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
|
||||
|
||||
[[package]]
|
||||
name = "xkbcommon"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7a974f48060a14e95705c01f24ad9c3345022f4d97441b8a36beb7ed5c4a02d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"memmap2",
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xkbcommon-dl"
|
||||
version = "0.4.2"
|
||||
@@ -4384,9 +4394,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zcheapstr"
|
||||
version = "1.3.0"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2347b6f50c4f669a282af57bf950debeacb9ce86de21b5b12932178dda691315"
|
||||
checksum = "2da34e7164b75d803c3197b86e6cf61b874106fbd472c5082575a8bc5fbd0907"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -4399,18 +4409,18 @@ checksum = "6df3dc4292935e51816d896edcd52aa30bc297907c26167fec31e2b0c6a32524"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.63"
|
||||
version = "0.8.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8"
|
||||
checksum = "cba8a86aee14fc8cc6c208af60854b3d4ab7185a9a369a12c648faa2716ff42a"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.63"
|
||||
version = "0.8.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f"
|
||||
checksum = "f89bca3b96ceb3cfcb4572790402f977442270d252b9a8504ebc258760c55f94"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -4419,9 +4429,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zlib-rs"
|
||||
version = "0.6.8"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
|
||||
checksum = "aa76918995d776d9dd34d371030be228d021137449771493d56e29f77e4148ac"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
@@ -4431,9 +4441,9 @@ checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
version = "0.5.3"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d56377fd46368984a170bc5aac5567e52ca5da874caa60bea39fcbca78fb658b"
|
||||
checksum = "c1a65ee146f41cb456b005bc898af3ab1495ded4ee61ac3637103f40ccacac18"
|
||||
|
||||
[[package]]
|
||||
name = "zune-inflate"
|
||||
|
||||
+5
-1
@@ -8,8 +8,11 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
blocking = "1.6"
|
||||
iced = { version = "0.14", default-features = false, features = ["crisp", "linux-theme-detection", "tiny-skia", "x11", "smol", "image"] }
|
||||
# smol = "2"
|
||||
unicode-segmentation = "1"
|
||||
iced = { version = "0.14", default-features = false, features = ["crisp", "linux-theme-detection", "tiny-skia", "x11", "smol", "image", "advanced"] }
|
||||
#iced = { git = "https://github.com/iced-rs/iced", branch = "vello_cpu", default-features = false, features = ["crisp", "linux-theme-detection", "vello-cpu", "x11", "smol", "image"]}
|
||||
# zbus = { version = "6", default-features = false, features = ["default-rt", "comms"] }
|
||||
iced_moving_picture = "0"
|
||||
log = "0.4"
|
||||
rust-i18n = "4"
|
||||
@@ -17,6 +20,7 @@ serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
time-format = "1.2"
|
||||
regex-lite = "0.1"
|
||||
xkbcommon = { version = "0.9.0" }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation>
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
Different functions to help with localization, land locales timexone etc
|
||||
*/
|
||||
|
||||
use crate::kira_system::{self, ExecCommandError};
|
||||
use regex_lite::Regex;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LocaleData {
|
||||
pub code: String,
|
||||
pub charset: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for LocaleData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(descr) = &self.description {
|
||||
write!(f, "{} ({})", self.code, descr)
|
||||
} else {
|
||||
write!(f, "{}", self.code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LocaleData {
|
||||
pub fn default() -> Self {
|
||||
Self {
|
||||
code: "C.UTF-8".into(),
|
||||
charset: "UTF-8".into(),
|
||||
description: Some("C locale".into()),
|
||||
}
|
||||
}
|
||||
|
||||
// creates text to be appended to locale.gen file
|
||||
// in case of C locale outputs empty string
|
||||
pub fn locale_gen_line(&self) -> String {
|
||||
format!("{} {}", &self.code, &self.charset)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TimeZoneData {
|
||||
pub region: String,
|
||||
pub zone: String,
|
||||
}
|
||||
|
||||
impl TimeZoneData {
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
let idx = s.find('/')?;
|
||||
let (region, zone) = s.split_at(idx);
|
||||
Some(Self {
|
||||
region: region.into(),
|
||||
zone: zone.trim_start_matches('/').into(),
|
||||
})
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns full path to timezone file
|
||||
/// Example: "/usr/share/zoneinfo/Region/City"
|
||||
///
|
||||
pub fn tz_file_name(&self) -> String {
|
||||
format!("/usr/share/zoneinfo/{}/{}", &self.region, &self.zone)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TimeZoneData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}/{}", self.region, self.zone)
|
||||
}
|
||||
}
|
||||
|
||||
const LOCALES_GEN_FILE_NAME: &str = "/etc/locale.gen";
|
||||
|
||||
/// gets locales list from system "/etc/locale.gen" file
|
||||
/// Filters result by filter_charset cahrset Some("UTF-8") to get only UTF-8 locales
|
||||
pub fn get_locales_blocking(
|
||||
filter_charset: Option<&str>,
|
||||
) -> Result<Vec<LocaleData>, ExecCommandError> {
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
|
||||
//pt_PT@euro ISO-8859-15
|
||||
//ru_UA.UTF-8 UTF-8
|
||||
//#ru_UA KOI8-U
|
||||
//
|
||||
// Example ru_UA.UTF-8 UTF-8
|
||||
// Groups:
|
||||
// 1: code, like ru_UA.UTF-8
|
||||
// 3 charser: UTF-8
|
||||
let key_re = Regex::new(r"^[[:word:]@]+").unwrap();
|
||||
let loc_re = Regex::new(r"^#?([[:word:].@-]+) ([0-9A-Z-]+)$").unwrap();
|
||||
|
||||
let loc_desc = get_loc_descr_blocking()?;
|
||||
|
||||
let mut res: Vec<LocaleData> = Vec::new();
|
||||
let mut file_content = String::new();
|
||||
{
|
||||
let locgen_file = File::open(LOCALES_GEN_FILE_NAME)?;
|
||||
let mut reader = BufReader::new(locgen_file);
|
||||
reader.read_to_string(&mut file_content)?;
|
||||
}
|
||||
for loc_line in file_content.lines() {
|
||||
if let Some(captured) = loc_re.captures(loc_line.trim_end()) {
|
||||
let code = captured[1].to_string();
|
||||
let charset = captured[2].to_string();
|
||||
// filters charset
|
||||
if let Some(flt) = filter_charset
|
||||
&& charset != flt
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let description = key_re
|
||||
.find(&code)
|
||||
.and_then(|m| loc_desc.get(m.as_str()).cloned());
|
||||
|
||||
res.push(LocaleData {
|
||||
code: code,
|
||||
charset: charset,
|
||||
description: description,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.push(LocaleData::default());
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Gets locales description from "/usr/share/i18n/locales/" directory.
|
||||
fn get_loc_descr_blocking() -> Result<HashMap<String, String>, ExecCommandError> {
|
||||
// use std::process::Command;
|
||||
|
||||
// /usr/share/i18n/locales/uz_UZ:title "Uzbek (latin) locale for Uzbekistan"
|
||||
// /usr/share/i18n/locales/uz_UZ@cyrillic:title "Uzbek (cyrillic) locale for Uzbekistan"
|
||||
// 1 group - key code
|
||||
// 2 group - description
|
||||
let descr_re = Regex::new(r#"^/usr/share/i18n/locales/(.+):title[[:space:]]+"(.+)"$"#).unwrap();
|
||||
|
||||
let mut res: HashMap<String, String> = HashMap::new();
|
||||
|
||||
let raw_list =
|
||||
kira_system::exec_command_out("grep", &vec!["-r", "title ", "/usr/share/i18n/locales/"])?;
|
||||
|
||||
for descr_line in raw_list.lines() {
|
||||
if let Some(captured) = descr_re.captures(descr_line.trim_end()) {
|
||||
res.insert(captured[1].to_string(), captured[2].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Getting list of awailable timezones from system.
|
||||
pub fn get_timezones_blocking() -> Result<Vec<TimeZoneData>, kira_system::ExecCommandError> {
|
||||
use std::path::Path;
|
||||
let loc_path: &Path = Path::new("/usr/share/zoneinfo");
|
||||
|
||||
let tz_list = kira_system::ls_dir_rec(loc_path)?;
|
||||
|
||||
Ok(tz_list
|
||||
.iter()
|
||||
.filter(|sb| sb.contains('/'))
|
||||
.filter(|sb| !sb.starts_with("posix")) //filter out posix dir that contains copies
|
||||
.filter_map(|str_t_zone| TimeZoneData::from_str(str_t_zone.trim()))
|
||||
.collect::<Vec<TimeZoneData>>())
|
||||
}
|
||||
|
||||
///
|
||||
/// Function for making wild guess of locale by landguage code and timezone(if provided)
|
||||
/// Ugly, needs some cleanups
|
||||
///
|
||||
pub fn guess_locale(
|
||||
locales: &Vec<LocaleData>,
|
||||
lang_code: &str,
|
||||
maybe_tz: Option<TimeZoneData>,
|
||||
) -> Option<LocaleData> {
|
||||
use crate::tz_to_cc::get_cc;
|
||||
// if we get lang code from wellcome stage, try to fing match with system locales
|
||||
|
||||
let lang = lang_code.replace("-", "_").to_lowercase();
|
||||
|
||||
let locales_filtered: Vec<LocaleData> = locales
|
||||
.iter()
|
||||
.filter(|l| l.code.to_lowercase().starts_with(&lang))
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
if locales_filtered.len() == 0 {
|
||||
None
|
||||
}
|
||||
// return locale if ve found exactly one
|
||||
else if locales_filtered.len() == 1 {
|
||||
locales_filtered.first().cloned()
|
||||
}
|
||||
// else do search
|
||||
else {
|
||||
// try to use country guessed from timezone
|
||||
let loc_country_guess = maybe_tz
|
||||
.and_then(|tz| get_cc(&tz.region, &tz.zone))
|
||||
.and_then(|cc| {
|
||||
// try to search for lang_contry in locales
|
||||
let lang_search = if lang.contains('_') {
|
||||
lang.clone()
|
||||
} else {
|
||||
format!("{}_{}", lang, cc.to_lowercase())
|
||||
};
|
||||
|
||||
locales_filtered
|
||||
.iter()
|
||||
.find(|l| l.code.to_lowercase().starts_with(&lang_search))
|
||||
.cloned()
|
||||
});
|
||||
|
||||
// if we guessed locale by country return it
|
||||
if loc_country_guess.is_some() {
|
||||
loc_country_guess
|
||||
// if language is en - return C locale
|
||||
} else if lang == "en" {
|
||||
Some(LocaleData::default())
|
||||
// else try to gess purely by language code
|
||||
} else {
|
||||
if lang.contains('_') {
|
||||
locales_filtered
|
||||
.iter()
|
||||
.find(|l| l.code.to_lowercase().starts_with(&lang))
|
||||
.cloned()
|
||||
} else {
|
||||
let lang_search = format!("{}_{}", lang, lang);
|
||||
locales_filtered
|
||||
.iter()
|
||||
.find(|l| l.code.to_lowercase().starts_with(&lang_search))
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+95
-1
@@ -15,13 +15,14 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
Functions for creating with disk layout
|
||||
Different functions for interacting with Linux system
|
||||
*/
|
||||
|
||||
use crate::kira_disk_layout::*;
|
||||
use crate::kira_size::KiraSize;
|
||||
use std::fmt::format;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -103,6 +104,51 @@ impl std::fmt::Display for ExecCommandError {
|
||||
// Implement std::error::Error
|
||||
impl std::error::Error for ExecCommandError {}
|
||||
|
||||
/// exec given sommand with arguments, capturing stderr in case or failure
|
||||
pub fn exec_command_stdin(
|
||||
cmd: &str,
|
||||
args: &Vec<&str>,
|
||||
stdin_data: &str,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
use std::io::Write;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread;
|
||||
|
||||
let mut child = Command::new(cmd)
|
||||
.args(args)
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let mut stdin = child
|
||||
.stdin
|
||||
.take()
|
||||
.ok_or("Failed to capture stdin".to_string())?;
|
||||
|
||||
let mut stderr = child
|
||||
.stderr
|
||||
.take()
|
||||
.ok_or("Failed to capture stderr".to_string())?;
|
||||
|
||||
let stderr_handle = thread::spawn(move || {
|
||||
let mut buf = Vec::new();
|
||||
use std::io::Read;
|
||||
let _ = stderr.read_to_end(&mut buf);
|
||||
buf
|
||||
});
|
||||
|
||||
stdin.write_all(stdin_data.as_bytes())?;
|
||||
|
||||
let status = child.wait()?;
|
||||
let stderr_output = stderr_handle.join().unwrap();
|
||||
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(CommandFailed::new(cmd, args, stderr_output).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// exec given sommand with arguments, capturing stderr in case or failure
|
||||
pub fn exec_command(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError> {
|
||||
let out = Command::new(cmd).args(args).output()?;
|
||||
@@ -466,3 +512,51 @@ pub fn fstabgen(mnt_dir: &str) -> Result<(), ExecCommandError> {
|
||||
fs::write(&fstab_file_name, fstab)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Executes passwd --stdin --root chroot_dir root
|
||||
/// To set new root password in specified chroot env
|
||||
///
|
||||
pub fn set_root_passwd(chroot_dir: &str, root_passwd: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command_stdin(
|
||||
"passwd",
|
||||
&vec!["--stdin", "--root", chroot_dir, "root"],
|
||||
root_passwd,
|
||||
)
|
||||
}
|
||||
|
||||
// /
|
||||
// / Sends Dbus message locale1 to change input method
|
||||
// / SetX11Keyboard(layout: s, model: s, variant: s, options: s, convert: b, interactive: b)
|
||||
// /
|
||||
// pub async fn set_input_method(
|
||||
// layout: &str,
|
||||
// model: &str,
|
||||
// variant: &str,
|
||||
// options: &str,
|
||||
// ) -> zbus::Result<()> {
|
||||
// use zbus::Connection;
|
||||
|
||||
// let conn = Connection::system().await?;
|
||||
// log::info!("Sending dbus message to change layout");
|
||||
// log::info!(
|
||||
// "layout: {}, model: {}, variant: {}, options: {}",
|
||||
// layout,
|
||||
// model,
|
||||
// variant,
|
||||
// options
|
||||
// );
|
||||
// let resp = conn
|
||||
// .call_method(
|
||||
// Some("org.freedesktop.locale1"),
|
||||
// "/org/freedesktop/locale1",
|
||||
// Some("org.freedesktop.locale1"),
|
||||
// "SetX11Keyboard",
|
||||
// &(layout, model, variant, options, true, false),
|
||||
// )
|
||||
// .await?;
|
||||
|
||||
// log::info!("Dbus response: {}", resp.to_string());
|
||||
|
||||
// Ok(())
|
||||
// }
|
||||
@@ -0,0 +1,189 @@
|
||||
//! Track the cursor of a text input.
|
||||
use crate::kira_text_input::Value;
|
||||
|
||||
/// The cursor of a text input.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct Cursor {
|
||||
state: State,
|
||||
}
|
||||
|
||||
/// The state of a [`Cursor`].
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum State {
|
||||
/// Cursor without a selection
|
||||
Index(usize),
|
||||
|
||||
/// Cursor selecting a range of text
|
||||
Selection {
|
||||
/// The start of the selection
|
||||
start: usize,
|
||||
/// The end of the selection
|
||||
end: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl Default for Cursor {
|
||||
fn default() -> Self {
|
||||
Cursor {
|
||||
state: State::Index(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
/// Returns the [`State`] of the [`Cursor`].
|
||||
pub fn state(&self, value: &Value) -> State {
|
||||
match self.state {
|
||||
State::Index(index) => State::Index(index.min(value.len())),
|
||||
State::Selection { start, end } => {
|
||||
let start = start.min(value.len());
|
||||
let end = end.min(value.len());
|
||||
|
||||
if start == end {
|
||||
State::Index(start)
|
||||
} else {
|
||||
State::Selection { start, end }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the current selection of the [`Cursor`] for the given [`Value`].
|
||||
///
|
||||
/// `start` is guaranteed to be <= than `end`.
|
||||
pub fn selection(&self, value: &Value) -> Option<(usize, usize)> {
|
||||
match self.state(value) {
|
||||
State::Selection { start, end } => {
|
||||
Some((start.min(end), start.max(end)))
|
||||
}
|
||||
State::Index(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn move_to(&mut self, position: usize) {
|
||||
self.state = State::Index(position);
|
||||
}
|
||||
|
||||
pub(crate) fn move_right(&mut self, value: &Value) {
|
||||
self.move_right_by_amount(value, 1);
|
||||
}
|
||||
|
||||
pub(crate) fn move_right_by_words(&mut self, value: &Value) {
|
||||
self.move_to(value.next_end_of_word(self.right(value)));
|
||||
}
|
||||
|
||||
pub(crate) fn move_right_by_amount(
|
||||
&mut self,
|
||||
value: &Value,
|
||||
amount: usize,
|
||||
) {
|
||||
match self.state(value) {
|
||||
State::Index(index) => {
|
||||
self.move_to(index.saturating_add(amount).min(value.len()));
|
||||
}
|
||||
State::Selection { start, end } => self.move_to(end.max(start)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn move_left(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) if index > 0 => self.move_to(index - 1),
|
||||
State::Selection { start, end } => self.move_to(start.min(end)),
|
||||
State::Index(_) => self.move_to(0),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn move_left_by_words(&mut self, value: &Value) {
|
||||
self.move_to(value.previous_start_of_word(self.left(value)));
|
||||
}
|
||||
|
||||
pub(crate) fn select_range(&mut self, start: usize, end: usize) {
|
||||
if start == end {
|
||||
self.state = State::Index(start);
|
||||
} else {
|
||||
self.state = State::Selection { start, end };
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_left(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) if index > 0 => {
|
||||
self.select_range(index, index - 1);
|
||||
}
|
||||
State::Selection { start, end } if end > 0 => {
|
||||
self.select_range(start, end - 1);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_right(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) if index < value.len() => {
|
||||
self.select_range(index, index + 1);
|
||||
}
|
||||
State::Selection { start, end } if end < value.len() => {
|
||||
self.select_range(start, end + 1);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_left_by_words(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) => {
|
||||
self.select_range(index, value.previous_start_of_word(index));
|
||||
}
|
||||
State::Selection { start, end } => {
|
||||
self.select_range(start, value.previous_start_of_word(end));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_right_by_words(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) => {
|
||||
self.select_range(index, value.next_end_of_word(index));
|
||||
}
|
||||
State::Selection { start, end } => {
|
||||
self.select_range(start, value.next_end_of_word(end));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_all(&mut self, value: &Value) {
|
||||
self.select_range(0, value.len());
|
||||
}
|
||||
|
||||
pub(crate) fn start(&self, value: &Value) -> usize {
|
||||
let start = match self.state {
|
||||
State::Index(index) => index,
|
||||
State::Selection { start, .. } => start,
|
||||
};
|
||||
|
||||
start.min(value.len())
|
||||
}
|
||||
|
||||
pub(crate) fn end(&self, value: &Value) -> usize {
|
||||
let end = match self.state {
|
||||
State::Index(index) => index,
|
||||
State::Selection { end, .. } => end,
|
||||
};
|
||||
|
||||
end.min(value.len())
|
||||
}
|
||||
|
||||
fn left(&self, value: &Value) -> usize {
|
||||
match self.state(value) {
|
||||
State::Index(index) => index,
|
||||
State::Selection { start, end } => start.min(end),
|
||||
}
|
||||
}
|
||||
|
||||
fn right(&self, value: &Value) -> usize {
|
||||
match self.state(value) {
|
||||
State::Index(index) => index,
|
||||
State::Selection { start, end } => start.max(end),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
use crate::kira_text_input::{Cursor, Value};
|
||||
|
||||
pub struct Editor<'a> {
|
||||
value: &'a mut Value,
|
||||
cursor: &'a mut Cursor,
|
||||
}
|
||||
|
||||
impl<'a> Editor<'a> {
|
||||
pub fn new(value: &'a mut Value, cursor: &'a mut Cursor) -> Editor<'a> {
|
||||
Editor { value, cursor }
|
||||
}
|
||||
|
||||
pub fn contents(&self) -> String {
|
||||
self.value.to_string()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, character: char) {
|
||||
if let Some((left, right)) = self.cursor.selection(self.value) {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove_many(left, right);
|
||||
}
|
||||
|
||||
self.value.insert(self.cursor.end(self.value), character);
|
||||
self.cursor.move_right(self.value);
|
||||
}
|
||||
|
||||
pub fn paste(&mut self, content: Value) {
|
||||
let length = content.len();
|
||||
if let Some((left, right)) = self.cursor.selection(self.value) {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove_many(left, right);
|
||||
}
|
||||
|
||||
self.value.insert_many(self.cursor.end(self.value), content);
|
||||
|
||||
self.cursor.move_right_by_amount(self.value, length);
|
||||
}
|
||||
|
||||
pub fn backspace(&mut self) {
|
||||
match self.cursor.selection(self.value) {
|
||||
Some((start, end)) => {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove_many(start, end);
|
||||
}
|
||||
None => {
|
||||
let start = self.cursor.start(self.value);
|
||||
|
||||
if start > 0 {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove(start - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete(&mut self) {
|
||||
match self.cursor.selection(self.value) {
|
||||
Some(_) => {
|
||||
self.backspace();
|
||||
}
|
||||
None => {
|
||||
let end = self.cursor.end(self.value);
|
||||
|
||||
if end < self.value.len() {
|
||||
self.value.remove(end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,136 @@
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
/// The value of a [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: super::TextInput
|
||||
// TODO: Reduce allocations, cache results (?)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Value {
|
||||
graphemes: Vec<String>,
|
||||
}
|
||||
|
||||
impl Value {
|
||||
/// Creates a new [`Value`] from a string slice.
|
||||
pub fn new(string: &str) -> Self {
|
||||
let graphemes = UnicodeSegmentation::graphemes(string, true)
|
||||
.map(String::from)
|
||||
.collect();
|
||||
|
||||
Self { graphemes }
|
||||
}
|
||||
|
||||
/// Returns whether the [`Value`] is empty or not.
|
||||
///
|
||||
/// A [`Value`] is empty when it contains no graphemes.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// Returns the total amount of graphemes in the [`Value`].
|
||||
pub fn len(&self) -> usize {
|
||||
self.graphemes.len()
|
||||
}
|
||||
|
||||
/// Returns the position of the previous start of a word from the given
|
||||
/// grapheme `index`.
|
||||
pub fn previous_start_of_word(&self, index: usize) -> usize {
|
||||
let previous_string =
|
||||
&self.graphemes[..index.min(self.graphemes.len())].concat();
|
||||
|
||||
UnicodeSegmentation::split_word_bound_indices(previous_string as &str)
|
||||
.filter(|(_, word)| !word.trim_start().is_empty())
|
||||
.next_back()
|
||||
.map(|(i, previous_word)| {
|
||||
index
|
||||
- UnicodeSegmentation::graphemes(previous_word, true)
|
||||
.count()
|
||||
- UnicodeSegmentation::graphemes(
|
||||
&previous_string[i + previous_word.len()..] as &str,
|
||||
true,
|
||||
)
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Returns the position of the next end of a word from the given grapheme
|
||||
/// `index`.
|
||||
pub fn next_end_of_word(&self, index: usize) -> usize {
|
||||
let next_string = &self.graphemes[index..].concat();
|
||||
|
||||
UnicodeSegmentation::split_word_bound_indices(next_string as &str)
|
||||
.find(|(_, word)| !word.trim_start().is_empty())
|
||||
.map(|(i, next_word)| {
|
||||
index
|
||||
+ UnicodeSegmentation::graphemes(next_word, true).count()
|
||||
+ UnicodeSegmentation::graphemes(
|
||||
&next_string[..i] as &str,
|
||||
true,
|
||||
)
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(self.len())
|
||||
}
|
||||
|
||||
/// Returns a new [`Value`] containing the graphemes from `start` until the
|
||||
/// given `end`.
|
||||
pub fn select(&self, start: usize, end: usize) -> Self {
|
||||
let graphemes =
|
||||
self.graphemes[start.min(self.len())..end.min(self.len())].to_vec();
|
||||
|
||||
Self { graphemes }
|
||||
}
|
||||
|
||||
/// Returns a new [`Value`] containing the graphemes until the given
|
||||
/// `index`.
|
||||
pub fn until(&self, index: usize) -> Self {
|
||||
let graphemes = self.graphemes[..index.min(self.len())].to_vec();
|
||||
|
||||
Self { graphemes }
|
||||
}
|
||||
|
||||
/// Inserts a new `char` at the given grapheme `index`.
|
||||
pub fn insert(&mut self, index: usize, c: char) {
|
||||
self.graphemes.insert(index, c.to_string());
|
||||
|
||||
self.graphemes =
|
||||
UnicodeSegmentation::graphemes(&self.to_string() as &str, true)
|
||||
.map(String::from)
|
||||
.collect();
|
||||
}
|
||||
|
||||
/// Inserts a bunch of graphemes at the given grapheme `index`.
|
||||
pub fn insert_many(&mut self, index: usize, mut value: Value) {
|
||||
let _ = self
|
||||
.graphemes
|
||||
.splice(index..index, value.graphemes.drain(..));
|
||||
}
|
||||
|
||||
/// Removes the grapheme at the given `index`.
|
||||
pub fn remove(&mut self, index: usize) {
|
||||
let _ = self.graphemes.remove(index);
|
||||
}
|
||||
|
||||
/// Removes the graphemes from `start` to `end`.
|
||||
pub fn remove_many(&mut self, start: usize, end: usize) {
|
||||
let _ = self.graphemes.splice(start..end, std::iter::empty());
|
||||
}
|
||||
|
||||
/// Returns a new [`Value`] with all its graphemes replaced with the
|
||||
/// dot ('•') character.
|
||||
pub fn secure(&self) -> Self {
|
||||
Self {
|
||||
graphemes: std::iter::repeat_n(
|
||||
String::from("•"),
|
||||
self.graphemes.len(),
|
||||
)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Value {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&self.graphemes.concat())
|
||||
}
|
||||
}
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
// We need this file because wayland broke Linux desktop.
|
||||
|
||||
use iced::keyboard::key::{Code, NativeCode, Physical};
|
||||
|
||||
const XKB_OFFSET: u32 = 8;
|
||||
|
||||
///
|
||||
/// Converts iced key::Physical to xkb numeric keycode
|
||||
///
|
||||
pub fn physical_to_xkb_keycode(physical: &Physical) -> Option<u32> {
|
||||
match physical {
|
||||
Physical::Unidentified(NativeCode::Xkb(code)) => Some(code.clone()),
|
||||
Physical::Unidentified(_) => None,
|
||||
Physical::Code(code) => code_to_xkb(code),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Converts iced key::Code to xkb numeric keycode
|
||||
///
|
||||
pub fn code_to_xkb(code: &Code) -> Option<u32> {
|
||||
let evdev: u32 = match code {
|
||||
// Alphanumeric & main typing block
|
||||
Code::Backquote => 41,
|
||||
Code::Backslash => 43,
|
||||
Code::BracketLeft => 26,
|
||||
Code::BracketRight => 27,
|
||||
Code::Comma => 51,
|
||||
Code::Digit0 => 11,
|
||||
Code::Digit1 => 2,
|
||||
Code::Digit2 => 3,
|
||||
Code::Digit3 => 4,
|
||||
Code::Digit4 => 5,
|
||||
Code::Digit5 => 6,
|
||||
Code::Digit6 => 7,
|
||||
Code::Digit7 => 8,
|
||||
Code::Digit8 => 9,
|
||||
Code::Digit9 => 10,
|
||||
Code::Equal => 13,
|
||||
Code::IntlBackslash => 86, // KEY_102ND
|
||||
Code::IntlRo => 89, // KEY_RO
|
||||
Code::IntlYen => 124, // KEY_YEN
|
||||
Code::KeyA => 30,
|
||||
Code::KeyB => 48,
|
||||
Code::KeyC => 46,
|
||||
Code::KeyD => 32,
|
||||
Code::KeyE => 18,
|
||||
Code::KeyF => 33,
|
||||
Code::KeyG => 34,
|
||||
Code::KeyH => 35,
|
||||
Code::KeyI => 23,
|
||||
Code::KeyJ => 36,
|
||||
Code::KeyK => 37,
|
||||
Code::KeyL => 38,
|
||||
Code::KeyM => 50,
|
||||
Code::KeyN => 49,
|
||||
Code::KeyO => 24,
|
||||
Code::KeyP => 25,
|
||||
Code::KeyQ => 16,
|
||||
Code::KeyR => 19,
|
||||
Code::KeyS => 31,
|
||||
Code::KeyT => 20,
|
||||
Code::KeyU => 22,
|
||||
Code::KeyV => 47,
|
||||
Code::KeyW => 17,
|
||||
Code::KeyX => 45,
|
||||
Code::KeyY => 21,
|
||||
Code::KeyZ => 44,
|
||||
Code::Minus => 12,
|
||||
Code::Period => 52,
|
||||
Code::Quote => 40,
|
||||
Code::Semicolon => 39,
|
||||
Code::Slash => 53,
|
||||
|
||||
// Modifiers, whitespace & editing
|
||||
Code::AltLeft => 56,
|
||||
Code::AltRight => 100,
|
||||
Code::Backspace => 14,
|
||||
Code::CapsLock => 58,
|
||||
Code::ContextMenu => 139, // KEY_MENU
|
||||
Code::ControlLeft => 29,
|
||||
Code::ControlRight => 97,
|
||||
Code::Enter => 28,
|
||||
Code::SuperLeft => 125, // KEY_LEFTMETA
|
||||
Code::SuperRight => 126, // KEY_RIGHTMETA
|
||||
Code::ShiftLeft => 42,
|
||||
Code::ShiftRight => 54,
|
||||
Code::Space => 57,
|
||||
Code::Tab => 15,
|
||||
|
||||
// CJK / IME keys
|
||||
Code::Convert => 92, // KEY_HENKAN
|
||||
Code::KanaMode => 93, // KEY_KATAKANAHIRAGANA
|
||||
Code::Lang1 => 122, // KEY_HANGEUL / KEY_HANGUEL
|
||||
Code::Lang2 => 123, // KEY_HANJA
|
||||
Code::Lang3 => 90, // KEY_KATAKANA
|
||||
Code::Lang4 => 91, // KEY_HIRAGANA
|
||||
Code::Lang5 => 93, // KEY_KATAKANAHIRAGANA
|
||||
Code::NonConvert => 94, // KEY_MUHENKAN
|
||||
Code::Hiragana => 91, // KEY_HIRAGANA
|
||||
Code::Katakana => 90, // KEY_KATAKANA
|
||||
|
||||
// Navigation & cluster
|
||||
Code::Delete => 111,
|
||||
Code::End => 107,
|
||||
Code::Help => 138, // KEY_HELP
|
||||
Code::Home => 102,
|
||||
Code::Insert => 110,
|
||||
Code::PageDown => 109,
|
||||
Code::PageUp => 104,
|
||||
Code::ArrowDown => 108,
|
||||
Code::ArrowLeft => 105,
|
||||
Code::ArrowRight => 106,
|
||||
Code::ArrowUp => 103,
|
||||
|
||||
// Numpad
|
||||
Code::NumLock => 69,
|
||||
Code::Numpad0 => 82,
|
||||
Code::Numpad1 => 79,
|
||||
Code::Numpad2 => 80,
|
||||
Code::Numpad3 => 81,
|
||||
Code::Numpad4 => 75,
|
||||
Code::Numpad5 => 76,
|
||||
Code::Numpad6 => 77,
|
||||
Code::Numpad7 => 71,
|
||||
Code::Numpad8 => 72,
|
||||
Code::Numpad9 => 73,
|
||||
Code::NumpadAdd => 78,
|
||||
Code::NumpadComma => 121, // KEY_KPCOMMA
|
||||
Code::NumpadDecimal => 83,
|
||||
Code::NumpadDivide => 98,
|
||||
Code::NumpadEnter => 96,
|
||||
Code::NumpadEqual => 117, // KEY_KPEQUAL
|
||||
Code::NumpadMultiply => 55,
|
||||
Code::NumpadParenLeft => 179, // KEY_KPLEFTPAREN
|
||||
Code::NumpadParenRight => 180, // KEY_KPRIGHTPAREN
|
||||
Code::NumpadSubtract => 74,
|
||||
|
||||
// System, lock & media keys
|
||||
Code::Escape => 1,
|
||||
Code::PrintScreen => 99,
|
||||
Code::ScrollLock => 70,
|
||||
Code::Pause => 119,
|
||||
Code::BrowserBack => 158, // KEY_BACK
|
||||
Code::BrowserFavorites => 156, // KEY_BOOKMARKS
|
||||
Code::BrowserForward => 159, // KEY_FORWARD
|
||||
Code::BrowserHome => 172, // KEY_HOMEPAGE
|
||||
Code::BrowserRefresh => 173, // KEY_REFRESH
|
||||
Code::BrowserSearch => 217, // KEY_SEARCH
|
||||
Code::BrowserStop => 128, // KEY_STOP
|
||||
Code::Eject => 161, // KEY_EJECTCD
|
||||
Code::LaunchApp1 => 157, // KEY_COMPUTER
|
||||
Code::LaunchApp2 => 140, // KEY_CALC
|
||||
Code::LaunchMail => 155, // KEY_MAIL
|
||||
Code::MediaPlayPause => 164, // KEY_PLAYPAUSE
|
||||
Code::MediaSelect => 179, // varies by device; None is safer if ambiguous
|
||||
Code::MediaStop => 166, // KEY_STOPCD
|
||||
Code::MediaTrackNext => 163, // KEY_NEXTSONG
|
||||
Code::MediaTrackPrevious => 165, // KEY_PREVIOUSSONG
|
||||
Code::Power => 116, // KEY_POWER
|
||||
Code::Sleep => 142, // KEY_SLEEP
|
||||
Code::AudioVolumeDown => 114, // KEY_VOLUMEDOWN
|
||||
Code::AudioVolumeMute => 113, // KEY_MUTE
|
||||
Code::AudioVolumeUp => 115, // KEY_VOLUMEUP
|
||||
Code::WakeUp => 143, // KEY_WAKEUP
|
||||
|
||||
Code::Suspend => 205, // KEY_SUSPEND
|
||||
Code::Again => 129, // KEY_AGAIN
|
||||
Code::Copy => 133, // KEY_COPY
|
||||
Code::Cut => 137, // KEY_CUT
|
||||
Code::Find => 136, // KEY_FIND
|
||||
Code::Open => 134, // KEY_OPEN
|
||||
Code::Paste => 135, // KEY_PASTE
|
||||
Code::Props => 130, // KEY_PROPS
|
||||
Code::Select => 353, // KEY_SELECT (0x161)
|
||||
Code::Undo => 131, // KEY_UNDO
|
||||
|
||||
// Function keys F1–F35
|
||||
Code::F1 => 59,
|
||||
Code::F2 => 60,
|
||||
Code::F3 => 61,
|
||||
Code::F4 => 62,
|
||||
Code::F5 => 63,
|
||||
Code::F6 => 64,
|
||||
Code::F7 => 65,
|
||||
Code::F8 => 66,
|
||||
Code::F9 => 67,
|
||||
Code::F10 => 68,
|
||||
Code::F11 => 87,
|
||||
Code::F12 => 88,
|
||||
Code::F13 => 183, // KEY_F13
|
||||
Code::F14 => 184, // KEY_F14
|
||||
Code::F15 => 185, // KEY_F15
|
||||
Code::F16 => 186, // KEY_F16
|
||||
Code::F17 => 187,
|
||||
Code::F18 => 188,
|
||||
Code::F19 => 189,
|
||||
Code::F20 => 190,
|
||||
Code::F21 => 191,
|
||||
Code::F22 => 192,
|
||||
Code::F23 => 193,
|
||||
Code::F24 => 194, // KEY_F24
|
||||
|
||||
// Catch-all in case your `iced_core::keyboard::key::Code` has additional variants
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Some(evdev + XKB_OFFSET)
|
||||
}
|
||||
+28
-14
@@ -33,17 +33,21 @@ use crate::stages::welcome;
|
||||
use crate::stages::welcome::WelcomeStage;
|
||||
|
||||
rust_i18n::i18n!("src/locales", fallback = "en");
|
||||
mod kira_include;
|
||||
mod kira_color_bar;
|
||||
mod kira_disk_layout;
|
||||
mod kira_system;
|
||||
mod kira_include;
|
||||
mod kira_locales;
|
||||
mod kira_logger;
|
||||
mod kira_scroll_list;
|
||||
mod kira_size;
|
||||
mod kira_sysinfo;
|
||||
mod kira_system;
|
||||
mod kira_text_input;
|
||||
mod kira_theming;
|
||||
mod kira_xkb;
|
||||
mod stage;
|
||||
mod stages;
|
||||
mod tz_to_cc;
|
||||
|
||||
enum Views {
|
||||
Start,
|
||||
@@ -97,7 +101,7 @@ impl KiraState {
|
||||
(
|
||||
Self {
|
||||
current_view: Views::Start,
|
||||
k_config: KiraConfig ::default(),
|
||||
k_config: KiraConfig::default(),
|
||||
stages_save: Vec::new(),
|
||||
},
|
||||
Task::done(Message::Start),
|
||||
@@ -123,10 +127,10 @@ fn view(k_state: &KiraState) -> Element<'_, Message> {
|
||||
fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::Start => {
|
||||
log::info!("Starting!");
|
||||
k_state.current_view = Views::Welcome(WelcomeStage::new(k_state.k_config.clone()));
|
||||
Task::none()
|
||||
},
|
||||
log::info!("Starting!");
|
||||
k_state.current_view = Views::Welcome(WelcomeStage::new(k_state.k_config.clone()));
|
||||
Task::none()
|
||||
}
|
||||
Message::Welcome(wlc_msg) => {
|
||||
if let Views::Welcome(wlc_view) = &mut k_state.current_view {
|
||||
match wlc_view.update(wlc_msg) {
|
||||
@@ -164,7 +168,7 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
StageAction::None => Task::none(),
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
@@ -180,7 +184,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
k_state.k_config = network_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::TimeZone(stages::timezone::TimeZoneStage::new(k_state.k_config.clone())),
|
||||
Views::TimeZone(stages::timezone::TimeZoneStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
@@ -204,7 +210,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
k_state.k_config = tz_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Locale(stages::locale::LocaleStage::new(k_state.k_config.clone())),
|
||||
Views::Locale(stages::locale::LocaleStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
@@ -214,7 +222,7 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
StageAction::None => Task::none(),
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
@@ -227,7 +235,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
k_state.k_config = locale_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Keyboard(stages::keyboard::KeyboardStage::new(k_state.k_config.clone())),
|
||||
Views::Keyboard(stages::keyboard::KeyboardStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
@@ -278,7 +288,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
k_state.k_config = partition_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Security(stages::security::SecurityStage::new(k_state.k_config.clone())),
|
||||
Views::Security(stages::security::SecurityStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
@@ -300,7 +312,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
k_state.k_config = security_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Install(stages::install::InstallStage::new(k_state.k_config.clone())),
|
||||
Views::Install(stages::install::InstallStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
|
||||
+2
-3
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
use crate::stages;
|
||||
|
||||
use iced::Task;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct KiraConfig {
|
||||
@@ -50,8 +50,7 @@ impl Default for KiraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub enum StageAction {
|
||||
Back,
|
||||
None,
|
||||
|
||||
@@ -314,14 +314,68 @@ fn config_stuff(k_config: KiraConfig) -> Result<(), ExecCommandError> {
|
||||
|
||||
locale_gen_write(&loc_gen_fn, &loc_lines)?;
|
||||
}
|
||||
// Running locale-gen
|
||||
kira_system::exec_cmd_chroot(MNT_DIR, "locale-gen", &vec![])?;
|
||||
|
||||
log::info!("Konfiguring keyboard...");
|
||||
log::info!("Kayboard conf: {}", k_config.res_keyboard.as_ref().unwrap());
|
||||
|
||||
//Simpler said.. it adds missing values for XKBLAYOUT=XX
|
||||
//and XKBMODEL=XXXX to /etc/vconsole.conf
|
||||
// dinit reads /etc/vconsole.conf
|
||||
// but
|
||||
// config /etc/conf.d/keymaps as a backup
|
||||
log::info!("Writing /etc/conf.d/keymaps");
|
||||
let kbd_conf = k_config.res_keyboard.as_ref().unwrap();
|
||||
let console_keymap = kbd_conf.crazy_bonker_console_keymap();
|
||||
fs::write(
|
||||
"/etc/conf.d/keymaps",
|
||||
format!(
|
||||
"# Autogeneradet by Kira Installer\nkeymap={}",
|
||||
console_keymap
|
||||
),
|
||||
)?;
|
||||
|
||||
log::info!("Writing /etc/vconsole.conf");
|
||||
let vconsole_content = format!(
|
||||
"Autogeneradet by Kira Installer \
|
||||
FONT={} \
|
||||
KEYMAP={} \
|
||||
XKBMODEL={} \
|
||||
XKBLAYOUT={} \
|
||||
XKBVARIANT={}\n",
|
||||
CONSOLE_FONT,
|
||||
&console_keymap,
|
||||
kbd_conf.xkb_model(),
|
||||
kbd_conf.xkb_layout(),
|
||||
kbd_conf.xkb_variant()
|
||||
);
|
||||
fs::write("/etc/vconsole.conf", vconsole_content)?;
|
||||
|
||||
//kira_system::exec_cmd_chroot(chroot_dir, cmd, args)
|
||||
|
||||
//locale-gen
|
||||
//Configure the system clock
|
||||
|
||||
// Set the time zone:
|
||||
// ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
|
||||
// Run hwclock to generate /etc/adjtime:
|
||||
// hwclock --systohc
|
||||
log::info!("Configuring timezone...");
|
||||
let time_conf = k_config.res_timezone.as_ref().unwrap();
|
||||
let tz_file_name = time_conf.time_zone.tz_file_name();
|
||||
kira_system::exec_cmd_chroot(
|
||||
MNT_DIR,
|
||||
"ln",
|
||||
&vec!["-sf", tz_file_name.as_ref(), "/etc/localtime"],
|
||||
)?;
|
||||
// Run hwclock to generate /etc/adjtime:
|
||||
// hwclock --systohc
|
||||
kira_system::exec_cmd_chroot(MNT_DIR, "hwclock", &vec!["--systohc"])?;
|
||||
|
||||
// set root password
|
||||
log::info!("Setting root password...");
|
||||
let sec_conf = k_config.res_security.as_ref().unwrap();
|
||||
kira_system::set_root_passwd(MNT_DIR, &sec_conf.root_password)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+163
-8
@@ -19,11 +19,14 @@
|
||||
*/
|
||||
|
||||
use crate::kira_scroll_list::{self, ListViewMessage};
|
||||
use crate::kira_system;
|
||||
use crate::kira_text_input;
|
||||
use crate::stage::{KiraConfig, StageAction};
|
||||
use iced::{Alignment, Length, widget};
|
||||
use iced::{Alignment, Length, Task, widget};
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
use xkbcommon::xkb;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Layout {
|
||||
@@ -82,6 +85,19 @@ impl KeyboarLayout {
|
||||
pub fn to_result(&self) -> String {
|
||||
format!("{}||{}", self.layout.layout, self.variant.variant)
|
||||
}
|
||||
pub fn xkb_layout(&self) -> String {
|
||||
self.layout.layout.clone()
|
||||
}
|
||||
///
|
||||
/// Returns string variant or empty string if variant is "default"
|
||||
///
|
||||
pub fn xkb_variant(&self) -> String {
|
||||
if self.variant.variant == "default" {
|
||||
"".into()
|
||||
} else {
|
||||
self.variant.variant.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -102,6 +118,9 @@ impl KeyboarModel {
|
||||
description: v.1.trim().to_string(),
|
||||
}
|
||||
}
|
||||
pub fn xkb_model(&self) -> String {
|
||||
self.model.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for KeyboarLayout {
|
||||
@@ -110,7 +129,7 @@ impl std::fmt::Display for KeyboarLayout {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct KeyboardStage {
|
||||
models: Vec<KeyboarModel>,
|
||||
model: Option<KeyboarModel>,
|
||||
@@ -122,6 +141,8 @@ pub struct KeyboardStage {
|
||||
keyboard_layout: Option<KeyboarLayout>,
|
||||
// selected_kbd_layout_id: Option<usize>,
|
||||
k_config: KiraConfig,
|
||||
test_text: String,
|
||||
xkb_keymap: Option<xkb::Keymap>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -130,9 +151,55 @@ pub struct KeyboardStageResult {
|
||||
pub keyboard_layout: KeyboarLayout,
|
||||
}
|
||||
|
||||
impl KeyboardStageResult {
|
||||
///
|
||||
/// doing crazy guess of console keymap
|
||||
///
|
||||
pub fn crazy_bonker_console_keymap(&self) -> String {
|
||||
const LAT_MAP: [&str; 13] = [
|
||||
"us", "fr", "it", "es", "pt", "pl", "cz", "no", "se", "fi", "dk", "nl", "hu",
|
||||
];
|
||||
const DE_MAP: &str = "de-latin1-nodeadkeys";
|
||||
const DEAFULT_MAP: &str = "us";
|
||||
|
||||
let layout = self.keyboard_layout.layout.layout.as_str();
|
||||
let model = self.keyboard_model.model.as_str();
|
||||
if layout == "de" {
|
||||
DE_MAP.to_string()
|
||||
} else if LAT_MAP.contains(&layout) {
|
||||
layout.to_string()
|
||||
}
|
||||
// if xkb_layout is non-Latin
|
||||
else if model == "pc105" {
|
||||
DE_MAP.to_string()
|
||||
} else {
|
||||
DEAFULT_MAP.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn xkb_model(&self) -> String {
|
||||
self.keyboard_model.xkb_model()
|
||||
}
|
||||
|
||||
pub fn xkb_layout(&self) -> String {
|
||||
self.keyboard_layout.xkb_layout()
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns string variant or empty string if variant is "default"
|
||||
///
|
||||
pub fn xkb_variant(&self) -> String {
|
||||
self.keyboard_layout.xkb_variant()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for KeyboardStageResult {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "keyboard_model: {} | keyboard_layout: {}", &self.keyboard_model, &self.keyboard_layout)
|
||||
write!(
|
||||
f,
|
||||
"keyboard_model: {} | keyboard_layout: {}",
|
||||
&self.keyboard_model, &self.keyboard_layout
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +208,7 @@ pub enum Message {
|
||||
SelectKeyboardModel(KeyboarModel),
|
||||
SelectLayout(kira_scroll_list::ListViewMessage),
|
||||
SelectVariant(kira_scroll_list::ListViewMessage),
|
||||
TestTextChange(String),
|
||||
|
||||
// AddLayout(usize),
|
||||
// RemoveLayout(usize),
|
||||
@@ -265,6 +333,8 @@ impl KeyboardStage {
|
||||
variant: Some(0),
|
||||
keyboard_layout: keyboard_layout,
|
||||
k_config: k_config,
|
||||
test_text: String::new(),
|
||||
xkb_keymap: None,
|
||||
}
|
||||
}
|
||||
Err(ex) => {
|
||||
@@ -282,11 +352,72 @@ impl KeyboardStage {
|
||||
variant: None,
|
||||
keyboard_layout: None,
|
||||
k_config: k_config,
|
||||
test_text: String::new(),
|
||||
xkb_keymap: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fn set_input_method(&self) -> Task<Message> {
|
||||
// log::info!("Preparing task!");
|
||||
// let (layout, variant) = if let Some(kb_layout) = &self.keyboard_layout {
|
||||
// (kb_layout.xkb_layout(), kb_layout.xkb_variant())
|
||||
// } else {
|
||||
// (String::new(), String::new())
|
||||
// };
|
||||
// let model = if let Some(kb_model) = &self.model {
|
||||
// kb_model.xkb_model()
|
||||
// } else {
|
||||
// String::new()
|
||||
// };
|
||||
// log::info!("Task perform!");
|
||||
// Task::perform(
|
||||
// async move {
|
||||
// let a = kira_system::set_input_method(&layout, &model, &variant, "").await;
|
||||
// log::info!("Result: {:?}", a);
|
||||
// },
|
||||
// |_| Message::SysLayoutChanged,
|
||||
// )
|
||||
// }s
|
||||
|
||||
fn gen_keymap(&mut self) -> () {
|
||||
log::debug!("Generating keyboard keymap!");
|
||||
let (layout, variant) = if let Some(kb_layout) = &self.keyboard_layout {
|
||||
(kb_layout.xkb_layout(), kb_layout.xkb_variant())
|
||||
} else {
|
||||
(String::new(), String::new())
|
||||
};
|
||||
let model = if let Some(kb_model) = &self.model {
|
||||
kb_model.xkb_model()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
log::debug!(
|
||||
"model:{:?}, layout:{:?}, variant:{:?}",
|
||||
model,
|
||||
layout,
|
||||
variant
|
||||
);
|
||||
|
||||
// create context
|
||||
let ctx = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
|
||||
let xkb_keymap = xkb::Keymap::new_from_names(
|
||||
&ctx,
|
||||
"evdev",
|
||||
&model,
|
||||
&layout,
|
||||
&variant,
|
||||
None,
|
||||
xkb::COMPILE_NO_FLAGS,
|
||||
);
|
||||
if xkb_keymap.is_none() {
|
||||
log::error!("Cannot compile XKB keymap!");
|
||||
} else {
|
||||
self.xkb_keymap = xkb_keymap;
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_keyboard = Some(KeyboardStageResult {
|
||||
keyboard_model: self.model.clone().expect("Keyboard model must be choosed!"),
|
||||
@@ -308,10 +439,15 @@ impl KeyboardStage {
|
||||
self.variants = self.variants_map[self.layouts[l_id].layout.as_str()].clone();
|
||||
self.variant = Some(0);
|
||||
|
||||
let layout = self.layouts[l_id].clone();
|
||||
let variant = self.variants[0].clone();
|
||||
|
||||
self.keyboard_layout = Some(KeyboarLayout {
|
||||
layout: self.layouts[l_id].clone(),
|
||||
variant: self.variants[0].clone(),
|
||||
layout: layout,
|
||||
variant: variant,
|
||||
});
|
||||
|
||||
self.gen_keymap();
|
||||
}
|
||||
StageAction::None
|
||||
}
|
||||
@@ -321,10 +457,18 @@ impl KeyboardStage {
|
||||
layout: self.layouts[self.layout.unwrap()].clone(),
|
||||
variant: self.variants[v_id].clone(),
|
||||
});
|
||||
self.gen_keymap();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SelectKeyboardModel(k_m) => {
|
||||
self.model = Some(k_m);
|
||||
self.gen_keymap();
|
||||
StageAction::None
|
||||
}
|
||||
Message::TestTextChange(test_text) => {
|
||||
let mut res: String = test_text;
|
||||
res.retain(|c: char| !c.is_control());
|
||||
self.test_text = res;
|
||||
StageAction::None
|
||||
}
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
@@ -356,7 +500,7 @@ impl KeyboardStage {
|
||||
crate::kira_scroll_list::list_view(
|
||||
&self.layouts,
|
||||
self.layout,
|
||||
Length::Shrink
|
||||
Length::Fill
|
||||
)
|
||||
.map(Message::SelectLayout)
|
||||
],
|
||||
@@ -365,15 +509,26 @@ impl KeyboardStage {
|
||||
crate::kira_scroll_list::list_view(
|
||||
&self.variants,
|
||||
self.variant,
|
||||
Length::FillPortion(1)
|
||||
Length::Fill
|
||||
)
|
||||
.map(Message::SelectVariant)
|
||||
],
|
||||
]
|
||||
.spacing(10)
|
||||
.height(Length::Shrink),
|
||||
.height(Length::Fill),
|
||||
widget::row![
|
||||
widget::text("Test Keyboard:"),
|
||||
//widget::text_input("", &self.test_text).on_input(Message::TestTextChange),
|
||||
kira_text_input::TextInput::new("", &self.test_text)
|
||||
.keymap(self.xkb_keymap.clone())
|
||||
.on_input(Message::TestTextChange),
|
||||
]
|
||||
.spacing(2)
|
||||
.align_y(Alignment::Center)
|
||||
.width(Length::Fill),
|
||||
]
|
||||
.spacing(10)
|
||||
.height(Length::Fill)
|
||||
.align_x(Alignment::Center),
|
||||
)
|
||||
} else {
|
||||
|
||||
+9
-127
@@ -19,126 +19,13 @@
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
kira_system::{self, ExecCommandError},
|
||||
kira_theming,
|
||||
stage::{KiraConfig, StageAction},
|
||||
};
|
||||
use iced::{Alignment, widget};
|
||||
use regex_lite::Regex;
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
const LOCALES_GEN_FILE_NAME: &str = "/etc/locale.gen";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LocaleData {
|
||||
pub code: String,
|
||||
pub charset: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for LocaleData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(descr) = &self.description {
|
||||
write!(f, "{} ({})", self.code, descr)
|
||||
} else {
|
||||
write!(f, "{}", self.code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LocaleData {
|
||||
pub fn default() -> Self {
|
||||
Self {
|
||||
code: "C.UTF-8".into(),
|
||||
charset: "UTF-8".into(),
|
||||
description: Some("C locale".into()),
|
||||
}
|
||||
}
|
||||
|
||||
// creates text to be appended to locale.gen file
|
||||
// in case of C locale outputs empty string
|
||||
pub fn locale_gen_line(&self) -> String {
|
||||
format!("{} {}", &self.code, &self.charset)
|
||||
}
|
||||
}
|
||||
|
||||
/// gets locales list from system "/etc/locale.gen" file
|
||||
/// Filters result by filter_charset cahrset Some("UTF-8") to get only UTF-8 locales
|
||||
fn get_locales_blocking(filter_charset: Option<&str>) -> Result<Vec<LocaleData>, ExecCommandError> {
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
|
||||
//pt_PT@euro ISO-8859-15
|
||||
//ru_UA.UTF-8 UTF-8
|
||||
//#ru_UA KOI8-U
|
||||
//
|
||||
// Example ru_UA.UTF-8 UTF-8
|
||||
// Groups:
|
||||
// 1: code, like ru_UA.UTF-8
|
||||
// 3 charser: UTF-8
|
||||
let key_re = Regex::new(r"^[[:word:]@]+").unwrap();
|
||||
let loc_re = Regex::new(r"^#?([[:word:].@-]+) ([0-9A-Z-]+)$").unwrap();
|
||||
|
||||
let loc_desc = get_loc_descr_blocking()?;
|
||||
|
||||
let mut res: Vec<LocaleData> = Vec::new();
|
||||
let mut file_content = String::new();
|
||||
{
|
||||
let locgen_file = File::open(LOCALES_GEN_FILE_NAME)?;
|
||||
let mut reader = BufReader::new(locgen_file);
|
||||
reader.read_to_string(&mut file_content)?;
|
||||
}
|
||||
for loc_line in file_content.lines() {
|
||||
if let Some(captured) = loc_re.captures(loc_line.trim_end()) {
|
||||
let code = captured[1].to_string();
|
||||
let charset = captured[2].to_string();
|
||||
// filters charset
|
||||
if let Some(flt) = filter_charset
|
||||
&& charset != flt
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let description = key_re
|
||||
.find(&code)
|
||||
.and_then(|m| loc_desc.get(m.as_str()).cloned());
|
||||
|
||||
res.push(LocaleData {
|
||||
code: code,
|
||||
charset: charset,
|
||||
description: description,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.push(LocaleData::default());
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Gets locales description from "/usr/share/i18n/locales/" directory.
|
||||
fn get_loc_descr_blocking() -> Result<HashMap<String, String>, ExecCommandError> {
|
||||
// use std::process::Command;
|
||||
|
||||
// /usr/share/i18n/locales/uz_UZ:title "Uzbek (latin) locale for Uzbekistan"
|
||||
// /usr/share/i18n/locales/uz_UZ@cyrillic:title "Uzbek (cyrillic) locale for Uzbekistan"
|
||||
// 1 group - key code
|
||||
// 2 group - description
|
||||
let descr_re = Regex::new(r#"^/usr/share/i18n/locales/(.+):title[[:space:]]+"(.+)"$"#).unwrap();
|
||||
|
||||
let mut res: HashMap<String, String> = HashMap::new();
|
||||
|
||||
let raw_list =
|
||||
kira_system::exec_command_out("grep", &vec!["-r", "title ", "/usr/share/i18n/locales/"])?;
|
||||
|
||||
for descr_line in raw_list.lines() {
|
||||
if let Some(captured) = descr_re.captures(descr_line.trim_end()) {
|
||||
res.insert(captured[1].to_string(), captured[2].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
use crate::kira_locales::{self, LocaleData, get_locales_blocking};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LocaleStage {
|
||||
@@ -172,21 +59,16 @@ impl LocaleStage {
|
||||
.as_ref()
|
||||
.and_then(|rw| Some(rw.loc_code.clone()));
|
||||
|
||||
let maybe_tz = k_config
|
||||
.res_timezone
|
||||
.as_ref()
|
||||
.and_then(|tzr| Some(tzr.time_zone.clone()));
|
||||
|
||||
let locales: Vec<LocaleData> = get_locales_blocking(Some("UTF-8")).unwrap();
|
||||
|
||||
// if we get lang code from wellcome stage, try to fing match with system locales
|
||||
let lang_match = if let Some(lang) = maybe_lang
|
||||
&& lang != "en"
|
||||
{
|
||||
let lang = lang.replace("-", "_").to_lowercase();
|
||||
locales
|
||||
.iter()
|
||||
.find(|l| l.code.to_lowercase().starts_with(&lang))
|
||||
.cloned()
|
||||
.unwrap_or_else(LocaleData::default)
|
||||
} else {
|
||||
LocaleData::default()
|
||||
};
|
||||
let lang_match = maybe_lang
|
||||
.and_then(|lang| kira_locales::guess_locale(&locales, &lang, maybe_tz))
|
||||
.unwrap_or_else(LocaleData::default);
|
||||
|
||||
let lang_locale_text = format!(
|
||||
"{}: {}",
|
||||
|
||||
@@ -22,33 +22,11 @@ use crate::stage::{KiraConfig, StageAction};
|
||||
use iced::{Alignment, Length, widget};
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use std::{collections::HashMap, fs, path::Path};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::kira_scroll_list;
|
||||
use crate::kira_system;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TimeZoneData {
|
||||
region: String,
|
||||
zone: String,
|
||||
}
|
||||
|
||||
impl TimeZoneData {
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
let idx = s.find('/')?;
|
||||
let (region, zone) = s.split_at(idx);
|
||||
Some(Self {
|
||||
region: region.into(),
|
||||
zone: zone.trim_start_matches('/').into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TimeZoneData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}/{}", self.region, self.zone)
|
||||
}
|
||||
}
|
||||
use crate::kira_locales::{TimeZoneData, get_timezones_blocking};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TimeZoneStage {
|
||||
@@ -75,20 +53,6 @@ pub enum Message {
|
||||
Back,
|
||||
}
|
||||
|
||||
/// Getting list of awailable timezones from system.
|
||||
fn get_timezones_blocking() -> Result<Vec<TimeZoneData>, kira_system::ExecCommandError> {
|
||||
let loc_path: &Path = Path::new("/usr/share/zoneinfo");
|
||||
|
||||
let tz_list = kira_system::ls_dir_rec(loc_path)?;
|
||||
|
||||
Ok(tz_list
|
||||
.iter()
|
||||
.filter(|sb| sb.contains('/'))
|
||||
.filter(|sb| !sb.starts_with("posix")) //filter out posix dir that contains copies
|
||||
.filter_map(|str_t_zone| TimeZoneData::from_str(str_t_zone.trim()))
|
||||
.collect::<Vec<TimeZoneData>>())
|
||||
}
|
||||
|
||||
/// Getting list of awailable timezones from system.
|
||||
// fn get_timezones_blocking_depr() -> Result<Vec<TimeZoneData>, String> {
|
||||
// use std::process::Command;
|
||||
|
||||
+1167
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user