mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-23 20:16:41 +02:00
Merge pull request #518 from kdheepak/support-multi-byte-chars
Support multi byte chars for key config
This commit is contained in:
commit
77b755ce70
1 changed files with 12 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::{collections::HashSet, error::Error, hash::Hash};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use log::{error, info, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::event::KeyCode;
|
||||
|
@ -198,13 +199,17 @@ impl KeyConfig {
|
|||
for line in data.split('\n') {
|
||||
if line.starts_with(config) {
|
||||
let line = line.trim_start_matches(config).trim_start().trim_end().to_string();
|
||||
if line.len() == 1 {
|
||||
if has_just_one_char(&line) {
|
||||
return Some(KeyCode::Char(line.chars().next().unwrap()));
|
||||
} else {
|
||||
error!("Found multiple characters in {} for {}", line, config);
|
||||
}
|
||||
} else if line.starts_with(&config.replace('-', "_")) {
|
||||
let line = line.trim_start_matches(&config.replace('-', "_")).trim_start().trim_end().to_string();
|
||||
if line.len() == 1 {
|
||||
if has_just_one_char(&line) {
|
||||
return Some(KeyCode::Char(line.chars().next().unwrap()));
|
||||
} else {
|
||||
error!("Found multiple characters in {} for {}", line, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -212,6 +217,11 @@ impl KeyConfig {
|
|||
}
|
||||
}
|
||||
|
||||
fn has_just_one_char(s: &str) -> bool {
|
||||
let mut chars = s.chars();
|
||||
chars.next().is_some() && chars.next().is_none()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue