2 unstable releases

0.2.0 Aug 8, 2020
0.1.0 Aug 3, 2020

#384 in Text editors


Used in kak-broot

MIT license

10KB
227 lines

kak-ui

A high-level rust wrapper around kakoune's JSON-RPC user interface.


lib.rs:

Provides a high-level wrapper around kakoune's JSON-RPC UI. This crate doesn't have any opinions on how you choose to communicate with kakoune or how you choose to deserialize/serialize JSON as long as it is supported by serde.

The main types to look at here are IncomingRequest and OutgoingRequest.

Examples

Basic usage:

 use std::io::{BufRead, BufReader};
 use std::process::{Command, Child, Stdio};
 use kak_ui::{IncomingRequest, OutgoingRequest};

 let kak_child_process = Command::new("kak")
     .args(&["-ui", "json"])
     .stdout(Stdio::piped())
     .stdin(Stdio::piped())
     .spawn()
     .unwrap();

 let incoming_request: IncomingRequest = serde_json::from_str(
     &BufReader::new(kak_child_process.stdout.unwrap())
         .lines()
         .next()
         .unwrap()
         .unwrap(),
 )
 .unwrap();

 let outgoing_request = OutgoingRequest::Keys(vec!["<esc>:q<ret>".to_string()]);
 serde_json::to_writer(kak_child_process.stdin.unwrap(), &outgoing_request).unwrap();

Dependencies

~0.3–1MB
~22K SLoC