Skip to content

Commit

Permalink
refactor out core logic of tui app to engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Apr 13, 2024
1 parent 0cc1a7a commit d764952
Show file tree
Hide file tree
Showing 14 changed files with 1,087 additions and 1,018 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/ferrite-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ detect-indent = { workspace = true }
directories = { workspace = true }
dunce = { workspace = true }
encoding_rs = { workspace = true }
ferrite-cli = { workspace = true }
ferrite-tree-sitter = { workspace = true }
ferrite-utility = { workspace = true }
flume = { workspace = true, default-features = false }
Expand Down
17 changes: 12 additions & 5 deletions crates/ferrite-core/src/buffer/case.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::str::FromStr;

use anyhow::bail;
use heck::{
ToKebabCase, ToLowerCamelCase, ToPascalCase, ToShoutyKebabCase, ToShoutySnakeCase, ToSnakeCase,
ToTitleCase, ToTrainCase,
Expand All @@ -19,9 +22,11 @@ pub enum Case {
ScreamingKebab,
}

impl Case {
pub fn from_str(s: &str) -> Self {
match s {
impl FromStr for Case {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"lower" => Case::Lower,
"upper" => Case::Upper,
"snake" => Case::Snake,
Expand All @@ -32,10 +37,12 @@ impl Case {
"train" => Case::Train,
"screaming-snake" => Case::ScreamingSnake,
"screaming-kebab" => Case::ScreamingKebab,
_ => panic!("'{s}' is not valid case"),
}
_ => bail!("'{s}' is not valid case"),
})
}
}

impl Case {
pub fn transform(&self, s: &str) -> String {
match self {
Case::Lower => s.to_lowercase(),
Expand Down
Loading

0 comments on commit d764952

Please sign in to comment.