Baka
Objective
Bachelor thesis/project (Czech: Bakalářská práce)
Title
RAD tool for text user interface
Author
Petr Ospalý
Status
Version: POC
Proof of Concept - early stage of development.
Quick Start
DISCLAIMER
This is still VERY Work-In-Progress codebase and as of yet no practical application. This project is just capable of building and installing itself (build toolchain is almost worked out) and the created binary is just a (n)curses helloworld example for now.
If you are in a hurry or don’t want to read anything more:
% git clone https://github.com/ospalax/baka.git
% cd baka
% ./configure
% make install
If you want to skip the configure
part then at least check out the Makefile.config
so you will not be surprised about installation destinations - by default these are used:
${HOME}/.baka/{bin,lib,include}
.. installation directory${HOME}/.baka/config
.. configuration file${HOME}/bin/baka
.. system command - the directory should be in yourPATH
otherwise it will not be much of use
You can adjust the build process little more by using the configure
script:
% ./configure --help
The script is without any arguments interactive and will ask a few questions - this is intended. I did not wish to hide anything from the user and with this approach I tried to eliminate any nasty surprises (overwritten files etc.). So by using the configure step the build will not silently use defaults - you must be explicit and set or sanction the values.
This project has very little requirements, so if your system has one of these compilers: cc
, gcc
or clang
and it has installed ncurses
package (library and its dev counterpart) then you should be fine.
Basically you need:
*NIX
system (Linux, *BSD etc.)terminal
withshell
(xterm
+bash
for example)C
compiler (one of these:gcc
/clang
)ncurses.h
header file (/usr/include/ncurses.h
most likely)
The configure
script will test it for you.
Introduction
Text user interface
Text User Interface (TUI) does not have a notion of pixel as that is the basic element in a graphical environment (GUI). Pixel’s role in the text based environment is taken by a character and the whole screen is formed by rows and columns of these characters.
There is a nice paragraph on wikipedia in the article about curses
:
Curses-based programs often have a user interface that resembles a traditional graphical user interface, including ‘widgets’ such as text boxes and scrollable lists, rather than the command line interface (CLI) most commonly found on text-only devices. This can make them more user-friendly than a CLI-based program, while still being able to run on text-only devices. Curses-based software can also have a lighter resource footprint and operate on a wider range of systems (both in terms of hardware and software) than their GUI-based counterparts. This includes old pre-1990 machines along with modern embedded systems using text-only displays.
RAD
Baka is intended as a RAD
(Rapid Application Development) tool(chain) for rapid development of applications in text based environments (here it means terminals). Very much in line with the pioneer of such tools - Borland Delphi - though my ambitions are much lower (and capabilities of text interface much lesser).
The fundamental component of a RAD tool is the Designer - where all the rapid development take the place (mostly). Without it the user (programmer) must learn API of whatever widget toolkit he chose to use. The purpose of any RAD tool and especially of the designer is to provide WYSIWYG
features where the user intuitively design his application interface without any coding and all implementation details are hidden from him.
After the design time the user can hook up pieces of code on top of these widgets to give them some functionality. To achieve that: the RAD tool should provide a way of source code organization and automatic code creation - e.g. procedure/function templates (with auto-generated signature but empty body). We can call this the scaffolding.
Arguably the most popular way how to combine such scaffolding with the design element is by means of events (actions acted upon the widgets - mouse click, pressing the keys) and handlers (procedures/functions dealing with the events). Widgets have properties and handlers manipulate with the widgets through these properties. But only until they are invoked (triggered) by the relevant event, not sooner (usually).
Runtime and concurrency
So the last piece of this RAD system is a runtime. The runtime can be implemented as an event-loop or some concurrency system to provide the reactivity for the applications. If no such runtime would be present then the application would be strictly synchronous and appeared “frozen” most of the time. In a system without asynchronous runtime any invoked (triggered) handler would halt the rest of the application until it finishes its job and in the meantime no other event could be registered.
Try to think just a trivial scrolling feature - in a synchronous system (without any event-loop or concurrency) the scrolled portion of the application (text, form…) would not be scrolled in the “realtime” (real realtime systems are actually a whole another story…) - but instead it would have to wait until you finish the movement and release the scroll-bar. Only then a new event would be triggered to redraw the scrolled (and changed) portion of the application - as you can imagine that is very unfriendly user experience.
Description
As was stated above - baka project tries to implement RAD tool for a text based interface - namely for the unix-like terminals with (n)curses
support.
(n)curses
(meaning: “New curses”) is the most popular “curses
” compatible library (at least on Linux) providing a programming API and abstractions over the many terminal implementations.
It is (as of now) the only serious dependency which this project has…this may change with possible integration of Martin Sústrik’s libdill
- the structured concurrency library. The same author also implemented golang-like concurrency in libmill
.
Technical stack
This project uses the following products to be build and for function:
- Linux operating system
- GNU C compiler or clang
- C language + stdlib
- git
- ncurses
- shell + terminal
- (?) libdill
Project structure
Components:
- RAD Designer/IDE
- Basic widget set
- Source code manager (scaffolding)
- Runtime library (events handling)
- Build toolchain
Dependencies:
- (n)curses
- libdill (?) (to replace my own event-loop implementation)
Why C?
The programming language of choice for this project is the C
- (C99
to be exact).
Firstly ncurses
and libdill
are purely C
libraries, so C
language was a natural choice. Someone could argue that C++
would be a better fit (Object-Oriented language, hello…).
C++
also interfaces with C
seamlessly and its compiler actually can compile C
code without any hassle (many even prefer the c++
compiler for C
projects).
So why not C++
then?:
- Mainly because I do not know it :)
- C++ is huge and it is growing every committee meeting…
- Every C++ programmer knows and uses only a subset of this beast (with their own flavor)
- And many of them program in the now frowned-upon obsoleted
C++98
version of the language - Nowadays C++ looks very different than ten years ago (generics, templates and stuff)
- Bjarne Stroustrup (creator) said that he himself does not know all of C++ (from this interview):
Even I can’t answer every question about C++ without reference to supporting material (e.g. my own books, online documentation, or the standard). I’m sure that if I tried to keep all of that information in my head, I’d become a worse programmer. What I do have is a far less detailed – arguably higher level – model of C++ in my head.
So why C again?:
- I know it :)
- C is a rock-solid and stable language - it looks much the same as it looked 20 years ago
- It is a small, elegant, practical and simple language
- The whole C can be covered in a 100 pages, probably much less - compare it to C++ heavy books
- You actually can write OOP styled code even in pure C (e.g.
GObject
) - These are written in C: Linux, compilers, shell, terminal emulator, sed, awk, grep (all of the old unix toolbox - History of UNIX and the role of C), ncurses, libdill etc. - why break the party?
Why the name “baka”?
This project would not exist without (n)curses
library, which is the successor of the original curses
library - and the word “curses” can mean magic spells or insults in English. Also there is the Czech term “bakalářská práce” for the “bachelor thesis” (notice the baka in the beginning) and Czech is my native language.
When you combine these two things with my healthy interest in Japan then you get: baka a japanese “curse” meaning “fool” (used so often in the anime).
So putting it altogether: (n)curses
means curses/insults, bakalářská práce has baka in it and that’s a popular japanese word for a curse - going full circle…
And last but not least…I am really terrible at making up names…
Usage
COMING SOON