Skip to content

Commit

Permalink
feat: Add a user command for changing the workspace name
Browse files Browse the repository at this point in the history
feat: Add a user command for changing the workspace name
  • Loading branch information
vyfor authored May 22, 2024
2 parents 63bb9c9 + d3d469b commit fa1a47b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,16 @@ require('cord').setup({
> \* [Wiki: Add or change file icons](https://github.com/vyfor/cord.nvim/wiki/Add-or-change-file-icons)
### ⌨️ User commands
- `:CordConnect` - Initialize presence client internally and connect to Discord
- `:CordReconnect` - Reconnect to Discord
- `:CordDisconnect` - Disconnect from Discord
- `:CordTogglePresence` - Toggle presence
- `:CordShowPresence` - Show presence
- `:CordHidePresence` - Hide presence
- `:CordToggleIdle` - Toggle idle status
- `:CordIdle` - Show idle status
- `:CordUnidle` - Hide idle status and reset the timeout
- `:CordConnect` - Initialize presence client internally and connect to Discord
- `:CordReconnect` - Reconnect to Discord
- `:CordDisconnect` - Disconnect from Discord
- `:CordTogglePresence` - Toggle presence
- `:CordShowPresence` - Show presence
- `:CordHidePresence` - Hide presence
- `:CordToggleIdle` - Toggle idle status
- `:CordIdle` - Show idle status
- `:CordUnidle` - Hide idle status and reset the timeout
- `:CordWorkspace <name>` - Change the name of the workspace (visually)

## 🌱 Contributing
This project is in beta. Feel free to open an issue or pull request for missing icons or features. You can also contact me on Discord (**[vyfor](https://discord.com/users/446729269872427018)**) if you have any questions.
5 changes: 5 additions & 0 deletions lua/cord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ function cord.setup_usercmds(config)
last_updated = os.clock()
last_presence = nil
end, {})

vim.api.nvim_create_user_command('CordWorkspace', function(args)
discord.set_workspace(args.args)
last_presence = nil
end, { nargs = 1 })
end

return cord
1 change: 1 addition & 0 deletions lua/cord/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ local function init_discord(ffi)
);
void clear_presence();
void disconnect();
void set_workspace(const char* workspace);
const char* update_workspace(const char* workspace);
void update_time();
const char* get_workspace();
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ pub unsafe extern "C" fn update_time() {
);
}

#[no_mangle]
pub unsafe extern "C" fn set_workspace(value: *mut c_char) {
if let Some(config) = CONFIG.as_mut() {
config.workspace = ptr_to_string(value);
}
}

#[no_mangle]
pub unsafe extern "C" fn update_workspace(value: *mut c_char) -> *const c_char {
let mut ws = String::new();
Expand Down

0 comments on commit fa1a47b

Please sign in to comment.