[Toybox] generic editor code
David Seikel
onefang at gmail.com
Thu Jan 30 21:25:13 PST 2014
On Mon, 27 Jan 2014 11:26:16 +1000 David Seikel <onefang at gmail.com>
wrote:
> I'm finally getting back to working on my editor. At least for the
> next week. I broke this out of the other thread, it should have it's
> own.
<snip>
I've fixed up the bit rot, and got joe / wordstar stuff to work. As
well as ^C and other keys usually swallowed by the terminal.
> Squeezing it down to manageable by Rob bits might be tricky due to -
>
> On Thu, 27 Dec 2012 06:06:53 -0600 Rob Landley <rob at landley.net>
> wrote:
> > Basically what I'd like is a self-contained line reader. More or
> > less a getline variant that can handle cursoring left and right to
> > insert stuff, handle backspace past a wordwrap (which on unix
> > requires knowing the screen width and your current cursor
> > position), and one that lets up/down escape sequences be hooked for
> > less/more screen scrolling, vi line movement, shell command
> > history, and so on.
>
> Which is most of the editor already.
Nearing the end of the week, and I hopefully have a first bit to put
into toybox. The generic input handler, including SIGWINCH and
terminal size probing. Hopefully it's Rob friendly enough this time
around, and can be added to toysh. If it's still too big to digest, I
can leave out the terminal size probe, and send that again later. The
CSI parser to handle that is a big lump of code in the middle.
The terminal size stuff could be integrated into the existing
terminal_size(), but I wanted this first code drop to be just stand
alone files.
First is handlekeys.c and handlekeys.h, both to be put into lib. Docs
on what it is and how to use it are in handlekeys.h. Should be usable
for all your keyboard input and screen sizing needs. Can be extended to
deal with mouse input to, but that's for another day. Error handling
leaves a lot to be desired, but is more suitable for testing at the
moment.
Second is dumbsh.c, to be put into pending. It's really just an
example for how to use handle_keys(), but it could be fleshed out into a
real toysh a little bit at a time.
Referring to Rob's comment above -
It's sorta self contained, but since it's up to the application to deal
with what to do with keystrokes and CSI commands, I made the input
handler the self contained blob. It translates things to something
easily digested by user code, and tries to deal with the gotchas. Using
that to make a getline variant doesn't take much, as the dumbsh example
shows.
The dumbsh.c file is a brain dead and stupid "shell" example. It uses
Emacs style keys (trivial to change to vi or something else) to do
cursor left, right, home, end, backspace, and delete. It reads the bash
history file and lets you up and down arrow through it. It handles
terminal resizes, even in the middle of typing commands.
Dumbsh doesn't do multi line editing, so no backspace past a wrap,
should be doable easily enough. It doesn't add stuff to the history,
should be trivial. It doesn't actually execute commands, I'm still
thinking about how to deal with ^C and friends for that.
Dumbsh has a bug or three. First time you get to the bottom of the
terminal it will swallow the next line, and resizing quickly gets crap
on the screen. Perhaps other bugs.
I'll likely work on fixing the dumbsh bugs more during the weekend.
Next week I'll be working on something else for a while. Likely there
will be a week of effort on the editor during February, but I can deal
with any small issues in the mean time.
The editor stuff is still on https://github.com/onefang/boxes , but will
leave putting that into toybox until much later. It still needs lots of
cleaning up.
--
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dumbsh.c
Type: text/x-csrc
Size: 6409 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20140131/12670c93/attachment-0012.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: handlekeys.c
Type: text/x-csrc
Size: 15684 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20140131/12670c93/attachment-0013.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: handlekeys.h
Type: text/x-chdr
Size: 2745 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20140131/12670c93/attachment-0006.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20140131/12670c93/attachment-0002.sig>
More information about the Toybox
mailing list