mehalter / cord.nvim

πŸš€ Discord Rich Presence plugin for Neovim written in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🧩 Cord

πŸš€ Cord is a Discord Rich Presence plugin designed for Neovim, written in Rust.

cord_banner

πŸ’Ž Features

  • Lightweight and dependency-free
  • Cross-platform support (Windows, Linux, macOS)
  • Blazingly fast startup due to non-blocking, asynchronous nature
  • Highly configurable in Lua
  • Offers more than 60 icons for languages and components
  • Automatically detects working directory and repository based on Git
  • Identifies problems across active buffers
  • Supports configurable idle status detection
  • Provides user commands for managing the presence
  • Is written in native code and uses Lua FFI for integration

πŸ”Œ Requirements

πŸ“¦ Installation

lazy.nvim
{
  'vyfor/cord.nvim',
  build = './build',
  event = 'VeryLazy'
}
pckr.nvim
{
  'vyfor/cord.nvim',
  run = './build'
}
other

Same steps apply to other plugin managers. Just make sure to add/run this build command:

./build

πŸ”§ Configuration

require('cord').setup({
  usercmds = true,                              -- Enable user commands
  timer = {
    enable = true,                              -- Enable automatically updating presence
    interval = 1500,                            -- Interval between presence updates in milliseconds (min 500)
    reset_on_idle = false,                      -- Reset start timestamp on idle
    reset_on_change = false,                    -- Reset start timestamp on presence change
  },
  editor = {
    image = nil,                                -- Image ID or URL in case a custom client id is provided
    client = 'neovim',                          -- vim, neovim, lunarvim, nvchad or your application's client id
    tooltip = 'The Superior Text Editor',       -- Text to display when hovering over the editor's image
  },
  display = {
    show_time = true,                           -- Display start timestamp
    show_repository = true,                     -- Display 'View repository' button linked to repository url, if any
    show_cursor_position = true,                -- Display line and column number of cursor's position
    swap_fields = false,                        -- If enabled, workspace is displayed first
    workspace_blacklist = {},                   -- List of workspace names to hide
  },
  lsp = {
    show_problem_count = false,                 -- Display number of diagnostics problems
    severity = 1,                               -- 1 = Error, 2 = Warning, 3 = Info, 4 = Hint
    scope = 'workspace',                        -- buffer or workspace
  },
  idle = {
    show_idle = true,                           -- Enable idle status
    timeout = 300000,                           -- Timeout in milliseconds after which the idle status is set, 0 to display immediately
    disable_on_focus = true,                    -- Do not display idle status when neovim is focused
    text = 'Idle',                              -- Text to display when idle
    tooltip = 'πŸ’€',                             -- Text to display when hovering over the idle image
  },
  text = {
    viewing = 'Viewing {}',                     -- Text to display when viewing a readonly file
    editing = 'Editing {}',                     -- Text to display when editing a file
    file_browser = 'Browsing files in {}',      -- Text to display when browsing files (Empty string to disable)
    plugin_manager = 'Managing plugins in {}',  -- Text to display when managing plugins (Empty string to disable)
    workspace = 'In {}',                        -- Text to display when in a workspace (Empty string to disable)
  },
  buttons = {
    {
      label = 'View repository',                -- Text displayed on the button
      url = 'git',                              -- URL where the button leads to ('git' = Git repository URL)
    },
    -- {
    --   label = 'View plugin',
    --   url = 'https://github.com/vyfor/cord.nvim',
    -- }
  },
})

⌨️ 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

🌱 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 if you have any questions.

❓ FAQ

Why Rust?

This plugin was initially written in Kotlin. Kotlin/Native, despite compiling to native code, still relies on the JVM for its compiler which is inconvenient, and aside from that, compile times are quite slow.

Why was Lua not considered?

The internal code needs to run on a separate thread due to Discord's ratelimit enforcement between connections. Implementing multithreading is much simpler in Rust compared to Lua. Although, a considerable part of the codebase still relies on Lua code.

Why does Cord use a timer-based approach?

Certain plugins often tend to break the order of events. And data such as cursor's current position needs to be fetched quite frequently and using autocommands for this task would stress the CPU. Thus, it was decided to use a timer. Regardless of that, Cord continues to rely on autocommands for aspects less prone to change, such as workspace or Git repository.

Dependency-free?

Every aspect, including FFI, JSON serialization and pipe connection, is implemented from scratch to avoid reliance on external crates and prevent any increase in compile times. Serialization is mainly hard-coded to focus on performance, even if the difference is negligible. 🀫

About

πŸš€ Discord Rich Presence plugin for Neovim written in Rust

License:Apache License 2.0


Languages

Language:Rust 69.6%Language:Lua 30.2%Language:Batchfile 0.2%