Skip to content

Commit

Permalink
feat(clafrica): allow user specified characters
Browse files Browse the repository at this point in the history
Unlike (#56) who included whitespaces by default, now the user can specify some additional characters that should be included in the cursor.
!help
  • Loading branch information
pythonbrad committed Jul 11, 2023
1 parent fd2336a commit dbd8363
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Implement the auto capitalization. [(#56)](https://github.com/pythonbrad/clafrica/pull/56)
- Allow user specified characters.

### Fixed
- Allowed whitespaces usage. [(#63)](https://github.com/pythonbrad/clafrica/pull/63)
- Improve the pause/resume way via double pressing of CTRL key. [(#54)](https://github.com/pythonbrad/clafrica/pull/54)
- Drop function key F1-12 which was reserved for special purposes. [(#62)](https://github.com/pythonbrad/clafrica/pull/62)

Expand Down
1 change: 1 addition & 0 deletions clafrica/data/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "Test code for testing purpose."
[core]
buffer_size = 128
auto_capitalize = true
allow_chars = [ "\t" ]

[data]
af = "ɑ"
Expand Down
2 changes: 2 additions & 0 deletions clafrica/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Config {
pub struct CoreConfig {
pub buffer_size: usize,
pub auto_capitalize: bool,
pub allow_chars: Option<Vec<char>>,
}

#[derive(Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -116,6 +117,7 @@ mod tests {

let conf = Config::from_file(Path::new("./data/config_sample.toml")).unwrap();
assert_eq!(conf.core.clone().unwrap().buffer_size, 12);
assert_eq!(conf.core.clone().unwrap().allow_chars, None);
assert!(!conf.core.clone().unwrap().auto_capitalize);

let data = conf.extract_data();
Expand Down
8 changes: 6 additions & 2 deletions clafrica/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ pub fn run(config: config::Config, mut frontend: impl Frontend) -> Result<(), io
.map(|(k, v)| [k.as_str(), v.as_str()])
.collect(),
);
let mut cursor = text_buffer::Cursor::new(map, config.core.map(|e| e.buffer_size).unwrap_or(8));

let mut cursor = text_buffer::Cursor::new(map, config.core.as_ref().map(|e| e.buffer_size).unwrap_or(8));

let allowed_chars = config.core.map(|e| e.allow_chars.unwrap_or_default()).unwrap_or_default();

let mut keyboard = Enigo::new();

Expand Down Expand Up @@ -61,7 +64,8 @@ pub fn run(config: config::Config, mut frontend: impl Frontend) -> Result<(), io
for event in rx.iter() {
let character = event.name.and_then(|s| s.chars().next());
let is_valid = character
.map(|c| c.is_alphanumeric() || c.is_ascii_punctuation() || c.is_whitespace())
.as_ref()
.map(|c| c.is_alphanumeric() || c.is_ascii_punctuation() || allowed_chars.contains(c))
.unwrap_or(false);

match event.event_type {
Expand Down

0 comments on commit dbd8363

Please sign in to comment.