Skip to content

Commit

Permalink
merge #165
Browse files Browse the repository at this point in the history
feat(manager): allow disabling text categories via boolean values
  • Loading branch information
vyfor authored Jan 12, 2025
2 parents 1f440c7 + 7527afc commit ef31070
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 37 deletions.
53 changes: 36 additions & 17 deletions .github/wiki/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,22 @@ require('cord').setup {

## 📝 Text

| Option | Type | Default | Description |
| ---------------- | -------------------------- | --------------------------------- | -------------------------------------------------- |
| `workspace` | `string \| function(opts)` | `In {workspace_name}` | Text shown when in a workspace |
| `viewing` | `string \| function(opts)` | `Viewing {filename}` | Text shown when viewing a file |
| `editing` | `string \| function(opts)` | `Editing {filename}` | Text shown when editing a file |
| `file_browser` | `string \| function(opts)` | `Browsing files in {tooltip}` | Text shown when in a file browser |
| `plugin_manager` | `string \| function(opts)` | `Managing plugins in {tooltip}` | Text shown when in a plugin manager |
| `lsp` | `string \| function(opts)` | `Configuring LSP in {tooltip}` | Text shown when in an LSP manager |
| `docs` | `string \| function(opts)` | `Reading {tooltip}` | Text shown when in a docs buffer |
| `vcs` | `string \| function(opts)` | `Committing changes in {tooltip}` | Text shown when in a VCS buffer |
| `notes` | `string \| function(opts)` | `Taking notes in {tooltip}` | Text shown when in a notes buffer |
| `debug` | `string \| function(opts)` | `Debugging in {tooltip}` | Text shown when in a debug-related plugin buffer |
| `test` | `string \| function(opts)` | `Testing in {tooltip}` | Text shown when in a testing-related plugin buffer |
| `diagnostics` | `string \| function(opts)` | `Fixing problems in {tooltip}` | Text shown when in a diagnostics buffer |
| `games` | `string \| function(opts)` | `Playing {tooltip}` | Text shown when in a game buffer |
| `dashboard` | `string` | `Home` | Text shown when in a dashboard buffer |
| Option | Type | Default | Description |
| ---------------- | ------------------------------------- | --------------------------------- | -------------------------------------------------- |
| `workspace` | `string \| function(opts) \| boolean` | `In {workspace_name}` | Text shown when in a workspace |
| `viewing` | `string \| function(opts) \| boolean` | `Viewing {filename}` | Text shown when viewing a file |
| `editing` | `string \| function(opts) \| boolean` | `Editing {filename}` | Text shown when editing a file |
| `file_browser` | `string \| function(opts) \| boolean` | `Browsing files in {tooltip}` | Text shown when in a file browser |
| `plugin_manager` | `string \| function(opts) \| boolean` | `Managing plugins in {tooltip}` | Text shown when in a plugin manager |
| `lsp` | `string \| function(opts) \| boolean` | `Configuring LSP in {tooltip}` | Text shown when in an LSP manager |
| `docs` | `string \| function(opts) \| boolean` | `Reading {tooltip}` | Text shown when in a docs buffer |
| `vcs` | `string \| function(opts) \| boolean` | `Committing changes in {tooltip}` | Text shown when in a VCS buffer |
| `notes` | `string \| function(opts) \| boolean` | `Taking notes in {tooltip}` | Text shown when in a notes buffer |
| `debug` | `string \| function(opts) \| boolean` | `Debugging in {tooltip}` | Text shown when in a debug-related plugin buffer |
| `test` | `string \| function(opts) \| boolean` | `Testing in {tooltip}` | Text shown when in a testing-related plugin buffer |
| `diagnostics` | `string \| function(opts) \| boolean` | `Fixing problems in {tooltip}` | Text shown when in a diagnostics buffer |
| `games` | `string \| function(opts) \| boolean` | `Playing {tooltip}` | Text shown when in a game buffer |
| `dashboard` | `string \| function(opts) \| boolean` | `'Home'` | `Home` | Text shown when in a dashboard buffer |

> Also see [Text Options](#text-options)
Expand Down Expand Up @@ -228,7 +228,26 @@ text = {
}
```

To see all available options, refer to the [default configuration](#default-config).
> To see all available options, refer to the [default configuration](#default-config).
It is also possible to use boolean values to completely disable a category:

```lua
text = {
workspace = '', -- Omit the text from the activity, meaning it will only have one row of text
games = function() end, -- Returning `nil` is the same as above

file_browser = true, -- Ignore these types of buffers and the current activity will remain unchanged
plugin_manager = false, -- Hide the activity for these types of buffers

-- Also applicable to functions
diagnostics = function(opts)
-- Only show diagnostics activity if there are problems, otherwise do nothing
return #vim.diagnostics.get(vim.api.nvim_get_current_buf()) > 0 and 'Fixing problems in ' .. opts.tooltip or true
end,
}
```


### Buttons

Expand Down
4 changes: 4 additions & 0 deletions .github/wiki/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ text = {
### Omitting Fields
```lua
text = {
workspace = '',
-- or
workspace = function() end,
-- or
workspace = function() return '' end
}
```

Expand Down
22 changes: 17 additions & 5 deletions lua/cord/plugin/activity/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local text_config = {
dashboard = config.text.dashboard,
}

---@return Activity|boolean
local function build_activity(opts)
if opts.filetype == '' then
if opts.filename == '' then
Expand Down Expand Up @@ -73,22 +74,32 @@ local function build_activity(opts)
else
if opts.type == 'language' then
if opts.is_read_only then
file_text = config_utils:get(text_config.viewing, opts)
local text = config_utils:get(text_config.viewing, opts)
if text == true or text == false then return text end
if text ~= '' then file_text = text end
else
file_text = config_utils:get(text_config.editing, opts)
local text = config_utils:get(text_config.editing, opts)
if text == true or text == false then return text end
if text ~= '' then file_text = text end
end
else
file_text = config_utils:get(text_config[opts.type], opts)
local text = config_utils:get(text_config[opts.type], opts)
if text == true or text == false then return text end
if text ~= '' then file_text = text end
end
end

local details, state
if config.display.swap_fields then
details = config_utils:get(text_config.workspace, opts)
local workspace = config_utils:get(text_config.workspace, opts)
if workspace == true or workspace == false then return workspace end
if workspace ~= '' then details = workspace end
state = file_text
else
local workspace = config_utils:get(text_config.workspace, opts)
if workspace == true or workspace == false then return workspace end
if workspace ~= '' then state = workspace end
details = file_text
state = config_utils:get(text_config.workspace, opts)
end

local large_image, large_text, small_image, small_text
Expand Down Expand Up @@ -123,6 +134,7 @@ local function build_activity(opts)
}
end

---@return Activity
local function build_idle_activity(opts)
local details, state
if config.display.swap_fields then
Expand Down
3 changes: 3 additions & 0 deletions lua/cord/plugin/activity/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ function ActivityManager:update_activity()
if self.config.hooks.on_update then self.config.hooks.on_update(self.opts) end

local activity = activities.build_activity(self.opts)
if activity == true then return end
if activity == false then return self:clear_activity() end

---@diagnostic disable-next-line: param-type-mismatch -- ensured to be of type Activity
if self.config.hooks.on_activity then self.config.hooks.on_activity(self.opts, activity) end

if self.should_skip_update then
Expand Down
30 changes: 15 additions & 15 deletions lua/cord/plugin/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
---@field details? string|fun(opts: CordOpts):string Details shown when idle
---@field state? string|fun(opts: CordOpts):string State shown when idle
---@field tooltip? string|fun(opts: CordOpts):string Tooltip shown when hovering over idle icon
---@field icon? string Idle icon
---@field icon? string|fun(opts: CordOpts):string Idle icon

---@class CordTextConfig
---@field workspace? string|fun(opts: CordOpts):string Text for workspace activity
---@field viewing? string|fun(opts: CordOpts):string Text for viewing activity
---@field editing? string|fun(opts: CordOpts):string Text for editing activity
---@field file_browser? string|fun(opts: CordOpts):string Text for file browser activity
---@field plugin_manager? string|fun(opts: CordOpts):string Text for plugin manager activity
---@field lsp? string|fun(opts: CordOpts):string Text for LSP manager activity
---@field docs? string|fun(opts: CordOpts):string Text for documentation activity
---@field vcs? string|fun(opts: CordOpts):string Text for VCS activity
---@field notes? string|fun(opts: CordOpts):string Text for notes activity
---@field debug? string|fun(opts: CordOpts):string Text for debugging-related plugin activity
---@field test? string|fun(opts: CordOpts):string Text for testing-related plugin activity
---@field games? string|fun(opts: CordOpts):string Text for games activity
---@field diagnostics? string|fun(opts: CordOpts):string Text for diagnostics activity
---@field dashboard? string|fun(opts: CordOpts):string Text for dashboard activity
---@field workspace? string|fun(opts: CordOpts):string|boolean Text for workspace activity
---@field viewing? string|fun(opts: CordOpts):string|boolean Text for viewing activity
---@field editing? string|fun(opts: CordOpts):string|boolean Text for editing activity
---@field file_browser? string|fun(opts: CordOpts):string|boolean Text for file browser activity
---@field plugin_manager? string|fun(opts: CordOpts):string|boolean Text for plugin manager activity
---@field lsp? string|fun(opts: CordOpts):string|boolean Text for LSP manager activity
---@field docs? string|fun(opts: CordOpts):string|boolean Text for documentation activity
---@field vcs? string|fun(opts: CordOpts):string|boolean Text for VCS activity
---@field notes? string|fun(opts: CordOpts):string|boolean Text for notes activity
---@field debug? string|fun(opts: CordOpts):string|boolean Text for debugging-related plugin activity
---@field test? string|fun(opts: CordOpts):string|boolean Text for testing-related plugin activity
---@field games? string|fun(opts: CordOpts):string|boolean Text for games activity
---@field diagnostics? string|fun(opts: CordOpts):string|boolean Text for diagnostics activity
---@field dashboard? string|fun(opts: CordOpts):string|boolean Text for dashboard activity

---@class CordButtonConfig
---@field label string|fun(opts: CordOpts):string? Button label
Expand Down

0 comments on commit ef31070

Please sign in to comment.