Programming for Kids: BennuGD ASCII-editor

The BennuGD ASCII Editor becomes real!

I am quite hectic during these days, so I don’t have the time to do all the tasks my Programming for Kids project does deserve. It is a shame. However, and somehow, I did manage to do some developing stuff, and now my BennuGD ASCII editor, developed entirely using the BennuGD language – with my own additions to the language, compiler and interpreter, of course -, is allowed to show itself to you all!

By now it is quite basic, it has no advanced options as you can find on Vim, for example, but that’s purely a matter of time. What I’ve done is, basically, to create its core system and basic functionalities. Don’t have such a deep look at its interface, which is, I have to admit, quite gross. As I said earlier, it is a matter of time – and art no doubt -.

The main thing here is I could develop what you are about to see in the next demonstrative video using BennuGD language. There is nothing more, no external modules, no external libraries, nothing at all of that sort. Let’s show a screenshot below and let’s go discuss quickly some technical aspects of it.

Inside my BennuGD ASCII editor’s code

I made some internal changes to the BennuGD compiler language, in order to add some trivial functionalities allowing me to develop my BennuGD ASCII editor’s core. For example, I added the non-existing function getchar(). BennuGD keys processing is quite annoying, allowing a developer to check whenever a concrete key has been pressed, but in order to determine the last pressed key, say: Was it ‘A’ key, or was it the  ‘1’ key?, the only way to do that using Bennu is to iterate all across the entire key space, for God’s sake!

Thus, I decided to add this function, working the same way the C language getchar(); does.

So, now I can write something like:

784         /* Get the current pressed key : */
785         _key = getchar();
787         /* ————————————————————————————*/
788         /* An editable key has been pushed – _valid_chars – key */
789         /* ————————————————————————————*/
790         If(_bgd_search_for_a_key(_key) /* Avoid conflicts with Alt options */ && !Key(_ALT))
791             If(_bgd_edit_mode==_BGD_EDIT_INSERT)    /* Insert mode … */
792                 _ins_char_page(_cpage, mn.m, mn.n, 1, &mn,_key);
793             Else    /* Just replace */
794                 /* Okay, let’s update the page contents: */
795       [mn.m-1][mn.n-1] = _key;
796                 /* Advance one char */
797                 If(mn.n<_bgd_matrix_editable_bottom_n)
798                     mn.n++;
799                 Else
800                     /* Next row; if it is the last one, goto next page – or create a blank one – */
801                     If(mn.m+1<_bgd_matrix_editable_bottom_m)
802                         mn.m++; mn.n=1;
803                     Else
804                         _change_page(;
805                     End
806                 End
807             End
808             _pg_update_page_bytes(;
809          Else

See? Now I can, simply, get the last pressed key and then use the old-fashioned “switch” or “if-then-else” programming branches to do certain things, as you saw in the previous code snippet.

Double linked list pages system

My BennuGD ASCII editor is developed using a double linked list data structure, growing dynamically when it needs, so its memory usage is optimal. The entire editor is based on the concept of “pages”, that is, instead of “lines”, my approach tries to define the idea of “pages” of a book, so the kid when developing using my editor, is going to use it as a “real book”, going from one page to the other and adding, removing of searching all along the pages of his or her developement, instead of referencing it using only line numbers.

There’s something remarkable and even a bit notorious when it comes to dealing with arrays using BennuGD: if you allocate, say, [i] bytes, you have [0, 1, …, i] bytes for real, instead of the obvious and right approach of any programming language: [0, 1, .., i-1] bytes. At first it was quite confusing, I have to admit.

The demonstrative videos


Here, my own implementation of copy, cut & paste. It is feasible even to do that diagonally!!!Go have a look:  copying_pasting_diagonally