mirror of
https://github.com/jiriks74/presence.nvim
synced 2024-12-28 19:02:35 +01:00
Dynamic Text Update (#15)
* Add context-specific status * Add "browsing" support for file tree explorers * Move status text into its own function * Add commit and netrw support * Fix git commit file recognition * Add readonly clause * Revert editing_text option Co-authored-by: Andrew Kwon <andrewshky@gmail.com> * Delete copied line * Dynamic text update (#2) * Add basic plugin support and rewrite status_text * Fix syntax error * Fix errors pt. 2 * Change options -> self.options * editing_text -> status_text * Try to get rid of dictionary bug * Try to fix dictionary bug pt. 2 * Remove self.options * Reorder status_text initialisation * Reinsert self.options * Remove global status_text var * options still broken * Tentatively done with dynamic text * Remove global status_text variable * Remove unnecessary lines/clean up code * Dynamic text update (#3) * Clean up status text options * General code cleanup * Fix whitespace issue Co-authored-by: Andrew Kwon <andrewshky@gmail.com>
This commit is contained in:
parent
2927ceb17d
commit
c2030611c8
2 changed files with 31 additions and 17 deletions
|
@ -72,6 +72,7 @@ local serpent = require("deps.serpent")
|
|||
local Discord = require("presence.discord")
|
||||
local file_assets = require("presence.file_assets")
|
||||
local file_trees = require("presence.file_trees")
|
||||
local plugin_managers = require("presence.plugin_managers")
|
||||
|
||||
function Presence:setup(options)
|
||||
options = options or {}
|
||||
|
@ -87,13 +88,19 @@ function Presence:setup(options)
|
|||
self.log:info("Using user-defined Discord client id")
|
||||
end
|
||||
|
||||
-- General options
|
||||
self:set_option("auto_update", 1)
|
||||
self:set_option("main_image", "neovim")
|
||||
self:set_option("editing_text", self.get_status_text)
|
||||
self:set_option("workspace_text", "Working on %s")
|
||||
self:set_option("neovim_image_text", "The One True Text Editor")
|
||||
self:set_option("client_id", "793271441293967371")
|
||||
self:set_option("debounce_timeout", 15)
|
||||
self:set_option("main_image", "neovim")
|
||||
self:set_option("neovim_image_text", "The One True Text Editor")
|
||||
-- Status text options
|
||||
self:set_option("editing_text", "Editing %s")
|
||||
self:set_option("file_tree_text", "Browsing %s")
|
||||
self:set_option("git_commit_text", "Committing changes")
|
||||
self:set_option("plugin_manager_text", "Managing plugins")
|
||||
self:set_option("reading_text", "Reading %s")
|
||||
self:set_option("workspace_text", "Working on %s")
|
||||
|
||||
local discord_socket = self:get_discord_socket()
|
||||
if not discord_socket then
|
||||
|
@ -346,19 +353,24 @@ function Presence.get_file_extension(path)
|
|||
end
|
||||
|
||||
-- Get the status text for the current buffer
|
||||
function Presence.get_status_text(filename)
|
||||
function Presence:get_status_text(filename)
|
||||
if vim.bo.modifiable and not vim.bo.readonly then
|
||||
if vim.bo.filetype == "gitcommit" then
|
||||
return string.format("Committing changes")
|
||||
end
|
||||
return string.format("Editing %s", filename)
|
||||
elseif file_trees[filename:match "[^%d]+"] then
|
||||
return string.format("Browsing %s", file_trees[filename:match "[^%d]+"])
|
||||
return string.format(self.options.git_commit_text, filename)
|
||||
else
|
||||
if vim.bo.filetype == "netrw" then
|
||||
return string.format("Browsing Netrw")
|
||||
return string.format(self.options.editing_text, filename)
|
||||
end
|
||||
else
|
||||
local file_tree = file_trees[filename:match "[^%d]+"]
|
||||
if file_tree then
|
||||
return string.format(self.options.file_tree_text, file_tree)
|
||||
elseif vim.bo.filetype == "netrw" then
|
||||
return string.format(self.options.file_tree_text, "Netrw")
|
||||
elseif plugin_managers[vim.bo.filetype] then
|
||||
return string.format(self.options.plugin_manager_text, filename)
|
||||
else
|
||||
return string.format(self.options.reading_text, filename)
|
||||
end
|
||||
return string.format("Reading %s", filename)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -483,13 +495,10 @@ function Presence:update_for_buffer(buffer, should_debounce)
|
|||
small_text = use_file_as_main_image and neovim_image_text or file_text,
|
||||
}
|
||||
|
||||
local editing_text = self.options.editing_text
|
||||
editing_text = type(editing_text) == "function"
|
||||
and editing_text(filename, buffer)
|
||||
or string.format(editing_text, filename)
|
||||
local status_text = self:get_status_text(filename)
|
||||
|
||||
local activity = {
|
||||
state = editing_text,
|
||||
state = status_text,
|
||||
assets = assets,
|
||||
timestamps = {
|
||||
start = activity_set_at,
|
||||
|
|
5
lua/presence/plugin_managers.lua
Normal file
5
lua/presence/plugin_managers.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- Different plugin manager names
|
||||
return {
|
||||
["packer"] = "packer",
|
||||
["vim-plug"] = "vim-plug",
|
||||
}
|
Loading…
Reference in a new issue