Closed Lokathor closed 6 years ago
Sounds good! I'll add that the next chance I get.
Having said that, there are a couple of things to note:
The byte conversion is fine, but at the moment my quick demo idea to check out how to use ropey was forced to use
rope.insert(some_spot, &format!("{}", ch));
So there's a whole String allocation per key press. The program can just do that and still be totally responsive because computers are just so fast these days, but of course it still seems silly.
As to non-Ascii support, I'm not sure. The goal is just a side project for "a nano style editor for editing rust and maybe haskell in the terminal on my raspberry pi3". Using curses for the IO might make non-ascii tricky to say the least.
I agree the heap allocation is silly. For future reference, you can avoid it by using a stack-allocated buffer like this:
let mut buf = [0u8; 4];
rope.insert(some_spot, ch.encode_utf8(&mut buf));
In fact, I expect that's exactly how I'll implement insert_char
internally. But I agree it will be nice to have this as a convenience method.
Added in 93e7c1dfa32f62c87e453c9df6a570179fc6daf2. Also pushed a new crates.io release (0.6.3) with this functionality in it.
Please feel free to file more issues with any other feedback you might have!
There seems to be no way to insert individual characters.
I'd love to use ropey as the backing buffer of a terminal editor, but without the ability to edit the rope on a per-keypress basis there's just a lot of needless overhead.