Skip to content

davidgranstrom/osc.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

osc.nvim

Open Sound Control (OSC) library for Neovim.

asciicast

osc.nvim can be used as an OSC 1.0 compliant client/server in order to let nvim communicate with OSC enabled applications over UDP/TCP.

osc.nvim exposes the full API from the losc OSC library, read the documentation for losc here.

This plugin does not expose any mappings or commands and is lua only, see the examples below for usage.

Project status

  • Send
  • Receive
  • UDP
  • TCP

Features

  • Full OSC 1.0 compatability (see losc for more details).
  • No binary dependencies (pure lua).
  • TCP/UDP transport layers using vim.loop.
  • Can be used as a dependency to enable OSC communication for any nvim plugin.

Examples

Simple server

local osc = require'osc'.new{
  transport = 'udp',
  recvAddr = '127.0.0.1',
  recvPort  = 9000,
}

-- register a "catch all" handler
osc:add_handler('*', function(data)
  print(vim.inspect(data))
end)

-- open the OSC server
osc:open()

Simple client

local osc = require'osc'.new{
  transport = 'udp',
  sendAddr = '127.0.0.1',
  sendPort = 57120,
}

local message = osc.new_message{
  address = '/test',
  types = 'ifs',
  1, 2, 'hello from nvim!'
}

local ok, err = osc:send(message)
if not ok then
  print(err)
end

Full example

--- Send an OSC message on every keystroke.
--
-- Save this file in a `lua` directory available in your `runtimepath`.
-- Example: `~/.config/nvim/lua/osc-keydown.lua`
-- 
-- Usage: `:lua require'osc-keydown'`
--        `:OSCEnable` to start sending OSC on every keystroke.
--        `:OSCDisable` to stop sending OSC.
local osc = require'osc'.new{
  transport = 'udp',
  sendAddr = '127.0.0.1',
  sendPort = 57120,
}

local M = {}

local on_keystroke = function(k)
  local message = osc.new_message{
    address = '/nvim/key',
    types = 'si',
    k, string.byte(k)
  }
  local ok, err = osc:send(message)
  if not ok then
    print(err)
  end
end

function M.enable()
  if not M.id then
    M.id = vim.register_keystroke_callback(on_keystroke)
  end
end

function M.disable()
  if M.id then
    vim.register_keystroke_callback(nil, M.id)
  end
  M.id = nil
end

-- Register commands
vim.cmd [[ com! OSCEnable :lua require'osc-keydown'.enable()   ]]
vim.cmd [[ com! OSCDisable :lua require'osc-keydown'.disable() ]]

return M

About

Open Sound Control for Neovim

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages