Skip to content

Commit

Permalink
Merge pull request #395 from xrelkd/release/0.17.0
Browse files Browse the repository at this point in the history
Release `0.17.0`
  • Loading branch information
xrelkd authored Apr 21, 2024
2 parents 9028caa + 783bd28 commit ec87c57
Show file tree
Hide file tree
Showing 29 changed files with 850 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

# will have compiled files and executables
**/target/

Expand Down
41 changes: 22 additions & 19 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.16.6"
version = "0.17.0"
authors = ["xrelkd <46590321+xrelkd@users.noreply.github.com>"]
homepage = "https://github.com/xrelkd/clipcat"
repository = "https://github.com/xrelkd/clipcat"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [x] Support snippets
- [x] Support `X11`
- [x] Support `Wayland` (experimentally)
- [x] Support `macOS`
- [x] Support `gRPC`
- [x] gRPC over `HTTP`
- [x] gRPC over `Unix domain socket`
Expand Down
3 changes: 2 additions & 1 deletion clipcat-menu/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ impl Cli {
_ => {}
}

let mut config = Config::load_or_default(config_file.unwrap_or_else(Config::default_path));
let mut config =
Config::load_or_default(config_file.unwrap_or_else(Config::search_config_file_path));
if let Some(log_level) = log_level {
config.log.level = log_level;
}
Expand Down
105 changes: 103 additions & 2 deletions clipcat-menu/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct Config {
#[serde(default)]
pub dmenu: Option<Dmenu>,

#[serde(default)]
pub choose: Option<Choose>,

#[serde(default)]
pub custom_finder: Option<CustomFinder>,

Expand All @@ -35,6 +38,27 @@ pub struct Config {
}

impl Config {
pub fn search_config_file_path() -> PathBuf {
let paths = vec![Self::default_path()]
.into_iter()
.chain(clipcat_base::fallback_project_config_directories().into_iter().map(
|mut path| {
path.push(clipcat_base::MENU_CONFIG_NAME);
path
},
))
.collect::<Vec<_>>();
for path in paths {
let Ok(exists) = path.try_exists() else {
continue;
};
if exists {
return path;
}
}
Self::default_path()
}

#[inline]
pub fn default_path() -> PathBuf {
[
Expand Down Expand Up @@ -104,10 +128,25 @@ impl Default for Config {
server_endpoint: clipcat_base::config::default_server_endpoint(),
access_token: None,
access_token_file_path: None,

#[cfg(all(
unix,
not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "emscripten"
))
))]
finder: FinderType::Rofi,

#[cfg(target_os = "macos")]
finder: FinderType::Choose,

preview_length: 80,
rofi: Some(Rofi::default()),
dmenu: Some(Dmenu::default()),
choose: Some(Choose::default()),
custom_finder: Some(CustomFinder::default()),
log: clipcat_cli::config::LogConfig::default(),
}
Expand Down Expand Up @@ -144,6 +183,21 @@ pub struct Dmenu {
pub extra_arguments: Vec<String>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Choose {
#[serde(default = "default_line_length")]
pub line_length: usize,

#[serde(default = "default_menu_length")]
pub menu_length: usize,

#[serde(default = "default_menu_prompt")]
pub menu_prompt: String,

#[serde(default)]
pub extra_arguments: Vec<String>,
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct CustomFinder {
pub program: String,
Expand Down Expand Up @@ -173,15 +227,62 @@ impl Default for Dmenu {
}
}

impl Default for Choose {
fn default() -> Self {
Self {
menu_prompt: default_menu_prompt(),
menu_length: default_menu_length(),
line_length: default_line_length(),
extra_arguments: Vec::new(),
}
}
}

impl Default for CustomFinder {
fn default() -> Self { Self { program: "fzf".to_string(), args: Vec::new() } }
}

fn default_menu_prompt() -> String { clipcat_base::DEFAULT_MENU_PROMPT.to_string() }

const fn default_menu_length() -> usize { 30 }
const fn default_menu_length() -> usize {
#[cfg(all(
unix,
not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "emscripten"
))
))]
{
30
}

#[cfg(target_os = "macos")]
{
15
}
}

const fn default_line_length() -> usize {
#[cfg(all(
unix,
not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "emscripten"
))
))]
{
100
}

const fn default_line_length() -> usize { 100 }
#[cfg(target_os = "macos")]
{
70
}
}

#[derive(Debug, Snafu)]
pub enum Error {
Expand Down
Loading

0 comments on commit ec87c57

Please sign in to comment.