~arivigo/scalc-devel

4 2

Updates on the history browsing feature

Details
Message ID
<20210705013551.uddyhuucggkqlyfj@arch>
DKIM signature
pass
Download raw message
Dear all,
I think you might be aware of ticket #17,[1] about implementing a 
history browsing feature for scalc like... well... the one you get in 
any shell prompt: Up Arrow shows previous commands, Down Arrow shows 
newer ones.

It's a hard one. Existing solutions come in many ways and forms, but...
OK, this is the list of issues with those I know of:

    1. GNU Readline: It's GPL and scalc isn't (and won't be.) Also, it
       relies on GNU extensions and I want this to be portable, as I
       use my software on non-GNU and even non-Linux systems.
    2. linenoise: It's a nice library but it also relies on 
       non-standard extensions.
    3. NetBSD's editline: I don't understand how it is supposed to be
       deployed into a project. It is available on OpenBSD, but well...
       it'd made scalc BSD-only then?
    4. dietline: It's suckless, but it doesn't lend itself to be easily
       used as a library.

My conclusion is that directly dealing with this using termios is the
easiest and most portable way to do this... scalc doesn't need too many
fancy features, so it'd be just to catch the relevant arrow keys and
call it day.

On a local branch I have a working termios implementation of scalc as
is right now... but without echoing arrow keys anymore (the stable
release does echo them.) Backspace and some corner cases (like when
the user just presses return without any new input) aren't working yet.
The first step is to have a working termios-based prompt with the same
functionality as scalc presently has, but without echoing escape 
sequences back to the user. I might very well push the code at this
stage so everyone may see how things are going.

The second step is to hook up arrow keys to the proper actions. After
that, some refactoring will probably be due before moving on to other
issues or maybe even a new release.

So these are the updates! I hope to get to back to you with actual code
next time :)  

[1]: https://todo.sr.ht/~arivigo/scalc/17

-- 
Ariadna Vigo
Web: <https://ariadnavigo.xyz>
PGP: 0xA3B1324836A669BD
Details
Message ID
<CCL3YIWQXC0G.2XQBN97WL7I6J@desktop>
In-Reply-To
<20210705013551.uddyhuucggkqlyfj@arch> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
On Mon Jul 5, 2021 at 4:35 AM MSK, Ariadna Vigo wrote:
> 2. linenoise: It's a nice library but it also relies on
> non-standard extensions.

What extensions exactly?

> 3. NetBSD's editline: I don't understand how it is supposed to be
> deployed into a project. It is available on OpenBSD, but well...
> it'd made scalc BSD-only then?

editline is usually present as libedit, for example on Alpine Linux:
https://pkgs.alpinelinux.org/package/edge/main/x86_64/libedit. Then you
probably just need to link -ledit
Details
Message ID
<20210705113655.nbnqxdbg63uua2ao@arch>
In-Reply-To
<CCL3YIWQXC0G.2XQBN97WL7I6J@desktop> (view parent)
DKIM signature
pass
Download raw message
On Mon, Jul 05, 2021 at 12:44:35PM +0300, Alexey Yerin wrote:
> What extensions exactly?

It doesn't compile with -std=c99 and -D_POSIX_C_SOURCE=200809L. One of
the extensions I recall was a direct violation on how variadic
functions are declared under ISO C99 vs. a GNU extension I wasn't even
aware it existed. There were other issues as well, but this is the one
I remember being marked as a critical error.

> editline is usually present as libedit, for example on Alpine Linux:
> https://pkgs.alpinelinux.org/package/edge/main/x86_64/libedit. Then you
> probably just need to link -ledit

Yes, and it's available on Arch as well... and surprisingly, half of
my system links to it instead of readline... OpenSSH, QEMU, even
Telegram Desktop are using it!

This *is* a petpeeve though: it depends on ncurses... So dynamic 
linking in this case is not "just" libedit, but ncurses as well. I 
haven't checked whether libedit is linked to libncurses already or if
you have to manually resolve the dependency... and I do wonder how this
would work out on Termux and OpenBSD, which are the two environments I
use this and my other projects (that's why portability is key for me).
Maybe it works just fine; I haven't checked. In general I try to link
to the least amount of libraries I can and prefer to directly 
incorporate code to avoid "funny" deployment mishaps.

I'll check this out and compare, for sure. The NIH syndrome is strong
in me, because all my projects are also meant to be a learning
experience... so... I don't know. I'll let everyone know how things 
develop via this mailing list...

Thanks for your thoughtful reply!

-- 
Ariadna Vigo
Web: <https://ariadnavigo.xyz>
PGP: 0xA3B1324836A669BD
Details
Message ID
<CCL6L5E7KVUS.29JL9KUY5S211@desktop>
In-Reply-To
<20210705113655.nbnqxdbg63uua2ao@arch> (view parent)
DKIM signature
pass
Download raw message
On Mon Jul 5, 2021 at 2:36 PM MSK, Ariadna Vigo wrote:
> On Mon, Jul 05, 2021 at 12:44:35PM +0300, Alexey Yerin wrote:
> > What extensions exactly?
>
> It doesn't compile with -std=c99 and -D_POSIX_C_SOURCE=200809L. One of
> the extensions I recall was a direct violation on how variadic
> functions are declared under ISO C99 vs. a GNU extension I wasn't even
> aware it existed. There were other issues as well, but this is the one
> I remember being marked as a critical error.

Hm, when I do the same it works fine. Except for an implicit declaration
of strcasecmp which is easily fixable by adding an #include <strings.h>.
Also, even without a declaration it works fine without crashing.

> > editline is usually present as libedit, for example on Alpine Linux:
> > https://pkgs.alpinelinux.org/package/edge/main/x86_64/libedit. Then you
> > probably just need to link -ledit
>
> This *is* a petpeeve though: it depends on ncurses... So dynamic
> linking in this case is not "just" libedit, but ncurses as well.

Won't -static work in this case?
Details
Message ID
<20210705213724.gdbrfku2jqxhqxnv@arch>
In-Reply-To
<CCL6L5E7KVUS.29JL9KUY5S211@desktop> (view parent)
DKIM signature
pass
Download raw message
On Mon, Jul 05, 2021 at 02:48:10PM +0300, Alexey Yerin wrote:
> Hm, when I do the same it works fine. Except for an implicit declaration
> of strcasecmp which is easily fixable by adding an #include <strings.h>.
> Also, even without a declaration it works fine without crashing.

Maybe it's the set of -Wall -Wextra -Wpedantic flags?

> Won't -static work in this case?

It would work, but you'd still know where the headers and the static 
library are installed in your particular system... config.mk is there 
to save the day if you want the user to do that for you... or scalc
should add pkgconf as a dependency... (libedit does seem to support 
it.) 

IMO this kind of decisions ultimately come to whatever the devs are 
more used to and like better... I have become a bit skeptical of using
non-standard stuff from outside the build tree, but honestly I'm just
trying out ideas here :P

-- 
Ariadna Vigo
Web: <https://ariadnavigo.xyz>
PGP: 0xA3B1324836A669BD
Reply to thread Export thread (mbox)