Skip to content

Commit

Permalink
docs: document string templating
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Dec 10, 2024
1 parent d5ec225 commit 0bfc19d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 26 additions & 3 deletions wiki/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ require('cord').setup {
| `buttons` | `table \| nil` | `nil` | Configure [presence buttons](#buttons) |
| `assets` | `table \| nil` | `nil` | Custom [file icons](#assets) configuration |

## 🧩 Variables

| Option | Type | Default | Description |
| ----------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `variables` | `table` | `nil` | Define [custom variables](#custom-variables) for use in string templates. Functions can be used to dynamically generate values. |

## 🪝 Hooks

| Option | Type | Description |
Expand Down Expand Up @@ -146,6 +152,23 @@ Smart idle ensures that:
- When an instance goes idle, it switches to show the most recent active one
- You're only shown as idle when all instances are actually idle

### Custom Variables

The `variables` option allows you to define custom variables to be used in string templates. These variables can be static values or functions that dynamically generate values based on the current context. By default, the table is populated with the [options table](#options-table) but they can be overridden by user-defined variables.

Example configuration:

```lua
require('cord').setup {
variables = {
filename = 'a file',
problems = function(opts) return #vim.diagnostic.get(0) end,
},
text = {
viewing = 'Viewing ${filename} - ${problems} problems',
}
}

### User Commands

- `:CordTogglePresence` - Toggle presence visibility
Expand All @@ -164,7 +187,7 @@ The `advanced.cursor_update_mode` option controls how cursor position updates ar
- `'on_hold'` - Uses `CursorHold[I]` autocmd, updating only after the cursor has been stationary for `'updatetime'` milliseconds. Better performance but less accurate
- `'none'` - Disables cursor position updates entirely

### Activity Options
### Options Table

The `opts` parameter passed to all functions and hooks contains the following information:

Expand Down Expand Up @@ -195,7 +218,7 @@ The `opts` parameter passed to all functions and hooks contains the following in
buttons = table, -- List of configured presence buttons

-- Asset Information
type = string, -- Which category the asset belongs to
type = string, -- Which category the asset belongs to, e.g. 'language' or 'docs'
name = string, -- Asset name, if any
icon = string, -- Asset icon URL or name, if any
tooltip = string, -- Hover text for the asset, if any
Expand Down Expand Up @@ -223,7 +246,7 @@ The `ActivityManager` contains useful methods:
| `set_activity(activity)` | Sets the rich presence to the provided [activity](#activity-options), offering complete control over the presence. |
| `clear_activity(force)` | Clears the current activity from the Discord presence. If `force` is true, it completely clears the presence. |

### `set_activity` Parameters
### Activity Options

| Parameter | Type | Description |
| ------------ | -------- | ---------------------------------------------------------------------------------------------------- |
Expand Down
4 changes: 3 additions & 1 deletion wiki/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ The plugin in question, **cord.nvim**, has been rewritten from scratch with a ne

- The plugin is now event-driven, meaning changes are reflected instantly without any polling delays. When all instances disconnect, the server, as well as the connection to Discord, stay alive for a minute (configurable) before shutting down, which helps to avoid rate limiting issues.

- A new `variables` option allows users to define custom variables, including functions, for dynamic text templates. This enhances the flexibility and customization of the Rich Presence display.

> [!IMPORTANT]
> A nightly version of the Rust compiler is required to build the server component. The latest version of `rustup` can be downloaded from [here](https://rustup.rs/). Then, install the nightly toolchain using `rustup install nightly`.
> If you're using a plugin manager such as lazy.nvim, set the `build` key to `cargo build --release` to automatically rebuild the server on plugin updates.
## 🔧 Configuration Changes

The config structure has been updated to be more flexible. Most notably, the majority of string options now support functions, giving you full control over the Rich Presence display.
The config structure has been updated to be more flexible. Most notably, the majority of string options now support functions, giving you full control over the Rich Presence display. Additionally, a new `variables` option has been introduced to allow custom dynamic values in text templates.

> [!NOTE]
> Full configuration options can be found [here](CONFIGURATION.md).
Expand Down

0 comments on commit 0bfc19d

Please sign in to comment.