tdwsl / text-editor-test

simple text editor test in gforth
0 stars 0 forks source link

Not only gforth #1

Open wboeke opened 2 months ago

wboeke commented 2 months ago

I tried this script also with aster, your small forth interpreter. It works! Only the buffer sizes have to be much smaller, must be included, and one built-in word has to be modified:

void aster_f_getch() {
  struct termios t, t_old;
  tcgetattr(0, &t);
  t_old=t;
  t.c_lflag &= ~(ICANON | ECHO | ECHONL | ECHOCTL);
  tcsetattr(0, TCSANOW, &t);
  as_stack[as_sp++]=fgetc(stdin);
  tcsetattr(0, TCSANOW, &t_old);
}

I figured the key bindings of this editor, and it appeared to be a quite usable tool!

tdwsl commented 1 month ago

Hey, I actually have this already! Well, it doesn't remove the ECHONL and ECHOCTL flags, I guess I could change that. Only it isn't enabled by default: when you compile, if you pass the argument -DASTER_TERMIOS , it enables it, otherwise it just uses stdin. The Makefile does this, but you might be using an older version.

As for the editor itself, I'm glad you think it's usable! One thing I will say is that it allocates memory in a very inefficient way, and I was actually working on another similar editor that does it better a while back, but is still missing some important features. I might work on it some more and then upload it.

wboeke commented 1 month ago

After this modification of aster_f_getch() the editor seems to work, but when inserting a new line the rest of the lines don't shift downwards. This will only work if the termios function cfmakeraw() has been applied, however then accept() will not work, so the editor still is wrong. The right tric is: use the raw mode only for 'key', and implement 'accept' with normal fgets() or fgetc(). My version of edit.f is fully working as expected. I could modify some key bindings easily. Instead of the multiple 'if' words I used a 'case'.