gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.26k stars 243 forks source link

Handle Ctrl-Key events in EditView & some general, small improvements #739

Closed christoph-heiss closed 1 year ago

christoph-heiss commented 1 year ago

Hi!

First of, thank you for cursive! A rather important thing that popped up while implementing the new TUI-based installer for Proxmox was that the EditView does not handle ^U, ^K etc.

This implements that, plus some tests on top as well. Also included is the addition of a .get_cursor() method, as well as the clamping of the length in .remove(), two things that would be quite useful to have.

Thanks in advance!

gyscos commented 1 year ago

Hi, and thanks for the PR!

I wonder if these could be added with just an OnEventView wrapper around an EditView? I'm not entirely sure these shortcuts are idiomatic for all users. So I'd love to make it easy for your app to use define them, but I don't think they belong in the default EditView configuration.

christoph-heiss commented 1 year ago

Thanks for taking a look!

I wonder if these could be added with just an OnEventView wrapper around an EditView?

Sure, that wouldn't be much trouble either.

I'm not entirely sure these shortcuts are idiomatic for all users.

Well, there pretty much universal across TTY, CLIs and ncurses(-ish) applications/TUIs, so it is somewhat reasonable to expect them to work here too. Thus they are really not idiomatic w.r.t our usecases, that's why I chose to try to get them implemented upstream.

So I'd love to make it easy for your app to use define them, but I don't think they belong in the default EditView configuration.

In a sense that EditView should be a rather "dumb" view, only implementing the bare necessities for text editing? I get that.

I'll drop the relevant commits if that's the way forward.

Are the other two commits (7538f11463a04940d928feb10e1077a7f9436770 and 120c19cb36b9e3fc631ed0408bc97c7673c30a37) acceptable? Especially the former, the latter would be simply nice to have.

gyscos commented 1 year ago

Thanks for the work!