1
0
mirror of https://github.com/jiriks74/presence.nvim synced 2024-11-23 20:37:50 +01:00

Add setup option to configure custom file assets

Resolve #11
This commit is contained in:
Andrew Kwon 2022-01-15 22:47:49 -08:00
parent dca3daa25d
commit 6a3828167c
3 changed files with 22 additions and 3 deletions

@ -43,6 +43,7 @@ require("presence"):setup({
enable_line_number = false, -- Displays the current line number instead of the current project enable_line_number = false, -- Displays the current line number instead of the current project
blacklist = {}, -- A list of strings or Lua patterns that disable Rich Presence if the current file name, path, or workspace matches blacklist = {}, -- A list of strings or Lua patterns that disable Rich Presence if the current file name, path, or workspace matches
buttons = true, -- Configure Rich Presence button(s), either a boolean to enable/disable, a static table (`{{ label = "<label>", url = "<url>" }, ...}`, or a function(buffer: string, repo_url: string|nil): table) buttons = true, -- Configure Rich Presence button(s), either a boolean to enable/disable, a static table (`{{ label = "<label>", url = "<url>" }, ...}`, or a function(buffer: string, repo_url: string|nil): table)
file_assets = {}, -- Custom file asset definitions keyed by file names and extensions (see default config at `lua/presence/file_assets.lua` for reference)
-- Rich Presence text options -- Rich Presence text options
editing_text = "Editing %s", -- Format string rendered when an editable file is loaded in the buffer (either string or function(filename: string): string) editing_text = "Editing %s", -- Format string rendered when an editable file is loaded in the buffer (either string or function(filename: string): string)

@ -1,4 +1,15 @@
-- Discord application asset file names (name, key[, description]) by file extension -- File asset definitions (name, source) keyed by file name or extension
-- * name - the name of the asset shown as the title of the file in Discord
-- * source - the source of the asset, either an art asset key or the URL of an image asset
--
-- Example: {
-- -- Use art assets uploaded in Discord application for the configured client id
-- js = { "JavaScript", "javascript" },
-- ts = { "TypeScript", "typescript" },
-- -- Use image URLs
-- rs = { "Rust", "https://www.rust-lang.org/logos/rust-logo-512x512.png" },
-- go = { "Go", "https://go.dev/blog/go-brand/Go-Logo/PNG/Go-Logo_Aqua.png" },
-- }
return { return {
[".aliases"] = { ".aliases", "shell" }, [".aliases"] = { ".aliases", "shell" },
[".appveyor.yml"] = { "AppVeyor config", "appveyor" }, [".appveyor.yml"] = { "AppVeyor config", "appveyor" },

@ -63,8 +63,8 @@ Presence.workspaces = {}
local log = require("lib.log") local log = require("lib.log")
local msgpack = require("deps.msgpack") local msgpack = require("deps.msgpack")
local serpent = require("deps.serpent") local serpent = require("deps.serpent")
local file_assets = require("presence.file_assets")
local file_explorers = require("presence.file_explorers") local file_explorers = require("presence.file_explorers")
local default_file_assets = require("presence.file_assets")
local plugin_managers = require("presence.plugin_managers") local plugin_managers = require("presence.plugin_managers")
local Discord = require("presence.discord") local Discord = require("presence.discord")
@ -121,6 +121,13 @@ function Presence:setup(options)
self:set_option("line_number_text", "Line %s out of %s") self:set_option("line_number_text", "Line %s out of %s")
self:set_option("blacklist", {}) self:set_option("blacklist", {})
self:set_option("buttons", true) self:set_option("buttons", true)
-- File assets options
self:set_option("file_assets", {})
for name, asset in pairs(default_file_assets) do
if not self.options.file_assets[name] then
self.options.file_assets[name] = asset
end
end
-- Get and check discord socket path -- Get and check discord socket path
local discord_socket_path = self:get_discord_socket_path() local discord_socket_path = self:get_discord_socket_path()
@ -790,7 +797,7 @@ function Presence:update_for_buffer(buffer, should_debounce)
local name = filename local name = filename
local asset_key = "code" local asset_key = "code"
local description = filename local description = filename
local file_asset = file_assets[filename] or file_assets[extension] local file_asset = self.options.file_assets[filename] or self.options.file_assets[extension]
if file_asset then if file_asset then
name, asset_key, description = unpack(file_asset) name, asset_key, description = unpack(file_asset)
self.log:debug(string.format("Using file asset: %s", vim.inspect(file_asset))) self.log:debug(string.format("Using file asset: %s", vim.inspect(file_asset)))