https://github.com/etorth/libnvc
Easy way to embed (neo)vim in your application
https://github.com/etorth/libnvc
embeded game gui-application neovim rpc sdl2
Last synced: 3 days ago
JSON representation
Easy way to embed (neo)vim in your application
- Host: GitHub
- URL: https://github.com/etorth/libnvc
- Owner: etorth
- License: mit
- Created: 2018-12-24T07:48:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T23:01:15.000Z (over 3 years ago)
- Last Synced: 2023-03-05T01:37:52.218Z (over 3 years ago)
- Topics: embeded, game, gui-application, neovim, rpc, sdl2
- Language: C++
- Homepage:
- Size: 6.34 MB
- Stars: 33
- Watchers: 6
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libnvc
I realize nvim now provides ```libnvim.a```, this repo may not be needed anymore.
another c++-20 nvim msgpack-rpc client, nvim-0.5.0 tested.
nvim's rpc interface is convenient but not something you can finish in 10 minutes.
this repo creates libnvc.a and you can use it to read/write a process running neovim easily.

start nvim and use ```asio_socket``` to talk to it:
```cpp
#include "libnvc.hpp"
int main()
{
// start nvim:
// $ nvim --listen "127.0.0.1:6666"
libnvc::asio_socket socket;
if(!socket.connect("localhost", 6666)){
throw std::runtime_error("failed to connect to localhost:6666");
}
libnvc::api_client client(&socket);
client.nvim_input("$i123123");
client.nvim_buf_set_name(1, "1234");
```
or use ```reproc_device``` to spawn a process running nvim in background:
```cpp
#include "libnvc.hpp"
int main()
{
// spawn nvim process with default parameters
libnvc::reproc_device reproc_dev;
reproc_dev.spawn();
libnvc::api_client client(&reproc_dev);
client.nvim_ui_attach(100, 80, {{"rgb", true}, {"ext_linegrid", true}});
client.nvim_input("$i123123");
client.nvim_buf_set_name(1, "1234");
```
### build
there is zero dependenct for user's building environment.
libnvc use asio, mpack and reproc internally but hiden by pimpl.
```bash
# build the libnvc library, nvim should be in your PATH
$ cd $HOME
$ git clone https://github.com/etorth/libnvc.git
$ mkdir b_libnvc && cd b_libnvc
$ cmake ../libnvc -DCMAKE_INSTALL_PREFIX=install -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
$ make && make install
# build the sample project, a simple nvim gui
# this requires SDL2, SDL2-image and SDL2-ttf installed
$ cd $HOME
$ mkdir b_nvim_sdl2 && cd b_nvim_sdl2
$ cmake ../libnvc/sample/nvim_sdl2 -DCMAKE_INSTALL_PREFIX=install -DLIBNVC_INCLUDE=$HOME/b_libnvc/install/include -DLIBNVC_LIB=$HOME/b_libnvc/install/lib
$ make && make install
# run the sample gui
$ cd $HOME/b_nvim_sdl2/install/nvim_sdl2 && ./nvim_sdl2
```