diff --git a/README.md b/README.md index 3392a193..914282ca 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ require('cord').setup({ file_browser = 'Browsing files in {}', -- Text to display when browsing files (Empty string to disable) plugin_manager = 'Managing plugins in {}', -- Text to display when managing plugins (Empty string to disable) lsp_manager = 'Configuring LSP in {}', -- Text to display when managing LSP servers (Empty string to disable) + vcs = 'Committing changes in {}', -- Text to display when using Git or Git-related plugin (Empty string to disable) workspace = 'In {}', -- Text to display when in a workspace (Empty string to disable) }, buttons = { diff --git a/assets/vcs/default.png b/assets/vcs/default.png new file mode 100644 index 00000000..9dca2e5f Binary files /dev/null and b/assets/vcs/default.png differ diff --git a/lua/cord.lua b/lua/cord.lua index 627cc128..e307ffa5 100644 --- a/lua/cord.lua +++ b/lua/cord.lua @@ -42,6 +42,7 @@ cord.config = { file_browser = 'Browsing files in {}', plugin_manager = 'Managing plugins in {}', lsp_manager = 'Configuring LSP in {}', + vcs = 'Committing changes in {}', workspace = 'In {}', }, buttons = { @@ -78,6 +79,7 @@ local function connect(config) config.text.file_browser, config.text.plugin_manager, config.text.lsp_manager, + config.text.vcs, config.text.workspace, vim.fn.getcwd(), config.display.swap_fields diff --git a/lua/cord/utils.lua b/lua/cord/utils.lua index a4265630..c8eb868a 100644 --- a/lua/cord/utils.lua +++ b/lua/cord/utils.lua @@ -43,6 +43,7 @@ local function init_discord(ffi) const char* file_browser_text; const char* plugin_manager_text; const char* lsp_manager_text; + const char* vcs_text; const char* workspace_text; const char* initial_path; const bool swap; diff --git a/src/lib.rs b/src/lib.rs index ecb15745..043a308e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,6 +39,7 @@ struct Config { file_browser_text: String, plugin_manager_text: String, lsp_manager_text: String, + vcs_text: String, workspace_text: String, workspace: String, buttons: Vec, @@ -65,6 +66,7 @@ pub struct InitArgs { pub file_browser_text: *const c_char, pub plugin_manager_text: *const c_char, pub lsp_manager_text: *const c_char, + pub vcs_text: *const c_char, pub workspace_text: *const c_char, pub initial_path: *const c_char, pub swap_fields: bool, @@ -113,6 +115,7 @@ pub unsafe extern "C" fn init( let file_browser_text = ptr_to_string(args.file_browser_text); let plugin_manager_text = ptr_to_string(args.plugin_manager_text); let lsp_manager_text = ptr_to_string(args.lsp_manager_text); + let vcs_text = ptr_to_string(args.vcs_text); let workspace_text = ptr_to_string(args.workspace_text); let swap_fields = args.swap_fields; let workspace = find_workspace(&ptr_to_string(args.initial_path)); @@ -152,6 +155,7 @@ pub unsafe extern "C" fn init( file_browser_text, plugin_manager_text, lsp_manager_text, + vcs_text, workspace_text, workspace, buttons, @@ -375,6 +379,31 @@ pub unsafe extern "C" fn update_presence_with_assets( (details, icon, tooltip) } + Some(AssetType::Vcs) => { + let details = config.vcs_text.replace("{}", &name); + + if icon.is_empty() || tooltip.is_empty() { + if let Some((default_icon, default_tooltip)) = + mappings::vcs::get(&filetype) + { + if icon.is_empty() { + icon = get_asset("vcs", default_icon); + } + if tooltip.is_empty() { + tooltip = default_tooltip.to_string(); + } + } else { + if icon.is_empty() { + return false; + } + if tooltip.is_empty() { + tooltip = name; + } + } + } + + (details, icon, tooltip) + } None => return false, }; diff --git a/src/mappings/language.rs b/src/mappings/language.rs index 8553f340..872f7135 100644 --- a/src/mappings/language.rs +++ b/src/mappings/language.rs @@ -21,7 +21,8 @@ pub fn get<'a>( "elixir" => ("elixir", "Elixir"), "erlang" => ("erlang", "Erlang"), "fsharp" => ("fsharp", "F#"), - "git" | "gitignore" => ("git", "Git"), + "git" | "gitattributes" | "gitconfig" | "gitignore" + | "gitsendemail" => ("git", "Git"), "go" => ("go", "Go"), "groovy" => { if filename == "build.gradle" { diff --git a/src/mappings/mod.rs b/src/mappings/mod.rs index 324d0bdc..11e14144 100644 --- a/src/mappings/mod.rs +++ b/src/mappings/mod.rs @@ -2,6 +2,7 @@ pub mod file_browser; pub mod language; pub mod lsp_manager; pub mod plugin_manager; +pub mod vcs; pub fn get_by_filetype<'a>(filetype: &'a str, filename: &str) -> Filetype<'a> { if let Some(language) = language::get(filetype, filename) { @@ -16,6 +17,9 @@ pub fn get_by_filetype<'a>(filetype: &'a str, filename: &str) -> Filetype<'a> { if let Some(lsp_manager) = lsp_manager::get(filetype) { return Filetype::Lsp(lsp_manager.0, lsp_manager.1); } + if let Some(vcs) = vcs::get(filetype) { + return Filetype::Vcs(vcs.0, vcs.1); + } Filetype::Language("text", filetype) } @@ -24,4 +28,5 @@ pub enum Filetype<'a> { FileBrowser(&'a str, &'a str), PluginManager(&'a str, &'a str), Lsp(&'a str, &'a str), + Vcs(&'a str, &'a str), } diff --git a/src/mappings/vcs.rs b/src/mappings/vcs.rs new file mode 100644 index 00000000..1571f970 --- /dev/null +++ b/src/mappings/vcs.rs @@ -0,0 +1,18 @@ +pub fn get(filetype: &str) -> Option<(&str, &str)> { + let vcs = match filetype { + "gitcommit" | "gitrebase" => ("default", "Git"), + "fugitive" | "fugitiveblame" => ("default", "Fugitive"), + "magit" => ("default", "Magit"), + "git.nvim" => ("default", "Git.nvim"), + "lazygit" => ("default", "Lazygit"), + _ => { + if filetype.starts_with("Neogit") { + ("default", "Neogit") + } else { + return None; + } + } + }; + + Some(vcs) +} diff --git a/src/util/types.rs b/src/util/types.rs index 9540ab17..2db1cf08 100644 --- a/src/util/types.rs +++ b/src/util/types.rs @@ -3,6 +3,7 @@ pub enum AssetType { FileBrowser, PluginManager, Lsp, + Vcs, } impl AssetType { @@ -13,6 +14,7 @@ impl AssetType { 1 => Some(AssetType::FileBrowser), 2 => Some(AssetType::PluginManager), 3 => Some(AssetType::Lsp), + 4 => Some(AssetType::Vcs), _ => None, } } diff --git a/src/util/utils.rs b/src/util/utils.rs index 70ee339e..c77adb20 100644 --- a/src/util/utils.rs +++ b/src/util/utils.rs @@ -190,6 +190,10 @@ pub fn build_presence( lsp_manager_presence(config, tooltip, icon); (details, Some(icon), tooltip) } + Filetype::Vcs(icon, tooltip) => { + let (details, icon, tooltip) = vcs_presence(config, tooltip, icon); + (details, Some(icon), tooltip) + } } } @@ -282,6 +286,19 @@ fn lsp_manager_presence( (presence_details, presence_large_image, presence_large_text) } +#[inline(always)] +fn vcs_presence( + config: &Config, + tooltip: &str, + icon: &str, +) -> (String, String, String) { + let presence_details = config.vcs_text.replace("{}", tooltip); + let presence_large_image = get_asset("vcs", icon); + let presence_large_text = tooltip.to_string(); + + (presence_details, presence_large_image, presence_large_text) +} + #[inline(always)] fn find_git_repository(workspace_path: &str) -> Option { let config_path = format!("{workspace_path}/.git/config");