From: Ralf A. <ral...@gm...> - 2004-06-08 10:12:57
|
Hi, last month using libeditline or libedit with eesh was briefly discussed. Since having no history and no decent line editing in eesh has annoyed me for ages, I gave it a try. My qualification for this job was (and still is) outstanding: I didn't know anything about X11 programming till last sunday, I haven't written a line of C in the last two years (and not really much before either), and I never used libreadline, libeditline or libedit. So please have a look at my code if i'm doing something stupid. Furthermore I don't know anything about autoconf or automake. So I just hacked the auto-generated "Makefile" to link to libeditline and libedit (no patch attached). Because I couldn't connect to the CVS server of sourceforge last friday, I used enlightenment-0.16.7-0.65.tar.gz as a template. Since main.c of eesh isn't that large I'll mail the complete file and not a patch (see attachment). I introduced to #defines, USE_EDITLINE and USE_EDIT, to control which library is used. About libedit: you can use $HOME/.editrc to configure it, e.g. "bind -v" invokes vi keyset, see editrc (5el). My setup: Debian testing/unstable official Debian enlightenment 0.16.6-1 (I'm just using eesh from 0.16.7 to talk to it, maybe I shouldn't this?) official Debian libeditline0 1.12-5 official Debian libedit2 2.6.cvs.200201 Why did I implement it this way: 1) The prompt: to see if the user can type now. I could get rid of it when everything works. IMHO it looks better with a prompt. 2) I couldn't just replace the lines k = 0; while ((ret = read(0, &(buf[j]), 1) > 0)) { ... with the appropriate code for editline/edit or leaving the whole FD_SET-select-stuff out because a) the prompt resp. input will be messed up: no prompt shows but you can write without visible line-editing, type <ENTER> and the prompt shows with the text the user entered before including the line-editing, e.g. history. b) no output shows. c) if the eesh command doesn't produce any output d) misc. other symptoms (I went through several stages to get to the present state, I don't want to recount everything.) So I had use two fd_set variables and two calls to select: one, which looks for readfds and writefds, and another, which only looks for readfds. BTW, I could use only one variable and clear it by FD_ZERO, any preferences on your side? Maybe this is all self-evident to you but I included it because I hope it is easier for you to spot any errors. Bugs: - <CTRL d> doesn't quit the interactive mode, use <CTRL c> - libeditline: type <CTRL d> => segfault - libedit: type <CTRL d>, line-editing etc. don't work anymore; just continue typing, focus other windows, re-focus eesh, do whatever, eventually it will work again - just type <ENTER>, mostly the terminal hangs; focus another window, focus terminal with eesh again, get a new prompt - the indent isn't consistent with the rest of the file, I'll correct this for the final patch - I'm sure there are others, we just have to find them :-) First of all I'd be grateful if someone could look over my code and tell me if there any obvious errors (see my programming skills above). Ralf PS: I hope my further mails will be shorter. :-) |