-
Notifications
You must be signed in to change notification settings - Fork 722
JSON RPC
Kakoune is able to talk to the outside world using a protocol called JSON-RPC
There's already a document describing what kind of information can transit during this discussion. I encourage you to read it first.
This wiki page will attempt to illustrate how you can use this kakoune feature.
Let's start by creating a brand new normal kakoune client. Open a terminal and run:
kak -s yolo
Here the -s
flag indicates that we want to create a brand new yolo
session.
Open a second terminal, this time we create a kakoune client that does not display a nice ncurses GUI on the screen but print raw JSON output.
kak -c yolo -ui json
Since we decided to connect to the same yolo
session. Everything you do in the first client will be mirrored
in the second one. This way you can easily discover what's going on.
Example of JSON output when the second client is launched :
{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "#303030", "bg": "#d7d7d7", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "" }]], { "fg": "#d7d7d7", "bg": "#303030", "attributes": [] }, { "fg": "#afd787", "bg": "#303030", "attributes": [] }] }
{ "jsonrpc": "2.0", "method": "menu_hide", "params": [] }
{ "jsonrpc": "2.0", "method": "info_hide", "params": [] }
{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "*scratch* 1:1 " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "#444444", "bg": "#d7d7d7", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " - unnamed1@[yolo]" }], { "fg": "#d7d7d7", "bg": "#444444", "attributes": [] }] }
{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }
After typing iHello<esc>
in the first client, here's what the output :
{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "Hello" }, { "face": { "fg": "#303030", "bg": "#d7d7d7", "attributes": [] }, "contents": "\u000a" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "" }]], { "fg": "#d7d7d7", "bg": "#303030", "attributes": [] }, { "fg": "#afd787", "bg": "#303030", "attributes": [] }] }
{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "*scratch* 1:6 " }, { "face": { "fg": "#d7d7d7", "bg": "#5f875f", "attributes": [] }, "contents": "[+]" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "#444444", "bg": "#d7d7d7", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " - unnamed1@[yolo]" }], { "fg": "#d7d7d7", "bg": "#444444", "attributes": [] }] }
{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }
We can see the Hello
contents in the draw
method.
- Normal mode commands
- Avoid the escape key
- Implementing user mode (Leader key)
- Kakoune explain
- Kakoune TV