Discussion:
[dev] using vis (libtermkey) and netbsd-curses (was: oasis: small linux system inspired by stali)
Daniel Cegiełka
2018-11-24 11:36:01 UTC
Permalink
Hi,

https://lists.suckless.org/dev/1811/33025.html

I prepared a more detailed description of how to compile vis + netbsd-curses.

1) copy from ncurses/ncurses/names.c strnames & strfnames:

DCL(strnames) = {
"cbt",
"bel",
(...)
"box1",
(NCURSES_CONST char *)0,
};

DCL(strfnames) = {
"back_tab",
"bell",
(...)
"box_chars_1",
(NCURSES_CONST char *)0,
};


2) replace ncurses macros (DCL etc.) with C declarations:

const char *strnames[] = {
"cbt",
"bel",
(...)
"box1",
NULL,
};

const char *strfnames[] = {
"back_tab",
"bell",
(...)
"box_chars_1",
NULL,
};


3) edit driver-ti.c (libtermkey) and include names.c:

#ifdef HAVE_UNIBILIUM
# include <unibilium.h>
#else
# include <curses.h>
# include <term.h>

/* strnames and strfnames */
#include "names.c"

/* curses.h has just poluted our namespace. We want this back */
# undef buttons
#endif


vis works fine, however, there is a problem when I use ':!' or ':e *'.
I think that the terminal settings are not restored. Does anyone have
an idea here how it can be solved?

Daniel
Leonardo Taccari
2018-11-24 12:15:36 UTC
Permalink
Hello Daniel,
Post by Daniel Cegiełka
[...]
vis works fine, however, there is a problem when I use ':!' or ':e *'.
I think that the terminal settings are not restored. Does anyone have
an idea here how it can be solved?
[...]
At least on NetBSD-current vis-0.5 seems working fine (it is packaged
in pkgsrc as vis-editor). I have also tried to skim for possible
pkgsrc patches on dependencies but I think that there is not anything
relevant for curses(3).

I have also tried to the `:!' and `:e *' and they seem working (
`:!', e.g. `:!dmesg', unlike at least NetBSD vi(1) (and more
generally probably nvi) it seems to not wait for a key to be pressed so
the dmesg message is then "cleared"; `:e *' opens vis-editor-menu with
the list of the current files).


Can you please elaborate further what happens?


Thank you!
Daniel Cegiełka
2018-11-24 12:53:07 UTC
Permalink
Post by Leonardo Taccari
Hello Daniel,
Post by Daniel Cegiełka
[...]
vis works fine, however, there is a problem when I use ':!' or ':e *'.
I think that the terminal settings are not restored. Does anyone have
an idea here how it can be solved?
[...]
At least on NetBSD-current vis-0.5 seems working fine (it is packaged
in pkgsrc as vis-editor).
It works fine, because they don't use netbsd-curses but ncurses.

http://pkgsrc.se/wip/vis-editor
http://pkgsrc.se/devel/ncursesw

Here is described how they differ:

https://github.com/sabotage-linux/netbsd-curses
https://wiki.netbsd.org/curses_in_netbsd/

libtermkey requires ncurses. If you use netbsd-curses, the libtermkey
compilation will fail. I showed how to do it and use it vis without
having to install ncurses.
Post by Leonardo Taccari
I have also tried to skim for possible
pkgsrc patches on dependencies but I think that there is not anything
relevant for curses(3).
I have also tried to the `:!' and `:e *' and they seem working (
`:!', e.g. `:!dmesg', unlike at least NetBSD vi(1) (and more
generally probably nvi) it seems to not wait for a key to be pressed so
the dmesg message is then "cleared"; `:e *' opens vis-editor-menu with
the list of the current files).
Can you please elaborate further what happens?
# touch f1 f2 f3 f4 f5
# ls
f1 f2 f3 f4 f5
# vis
:!
:q
# ls
f1 f2 f3 f4 f5
#

See attachment.

Daniel
Post by Leonardo Taccari
Thank you!
Leonardo Taccari
2018-11-24 13:13:30 UTC
Permalink
Hello Daniel,
Post by Daniel Cegiełka
[...]
It works fine, because they don't use netbsd-curses but ncurses.
http://pkgsrc.se/wip/vis-editor
http://pkgsrc.se/devel/ncursesw
[...]
I had a local package to update it to the latest stable version
around but I have only committed it few hours ago and pkgsrc.se is
probably not updated to reflect that:

<https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=tree;f=vis-editor>

(and, no, ncursesw is no longer used)
Post by Daniel Cegiełka
[...]
libtermkey requires ncurses. If you use netbsd-curses, the libtermkey
compilation will fail. I showed how to do it and use it vis without
having to install ncurses.
At least wip/libtermkey package does not depends on ncurses.
Post by Daniel Cegiełka
# touch f1 f2 f3 f4 f5
# ls
f1 f2 f3 f4 f5
# vis
:!
:q
# ls
f1 f2 f3 f4 f5
#
See attachment.
Thanks for clarifying! I can confirm that I can not reproduce it.
Daniel Cegiełka
2018-11-24 14:16:20 UTC
Permalink
Post by Leonardo Taccari
Hello Daniel,
Post by Daniel Cegiełka
[...]
It works fine, because they don't use netbsd-curses but ncurses.
http://pkgsrc.se/wip/vis-editor
http://pkgsrc.se/devel/ncursesw
[...]
I had a local package to update it to the latest stable version
around but I have only committed it few hours ago and pkgsrc.se is
<https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=tree;f=vis-editor>
(and, no, ncursesw is no longer used)
At least wip/libtermkey package does not depends on ncurses.
How is this possible?

vis require libtermkey:

https://github.com/martanne/vis/blob/master/configure#L344

and libtermkey uses 'strnames' and 'strfnames' from ncurses:

https://github.com/o11c/libtermkey/blob/master/driver-ti.c#L186
https://github.com/o11c/libtermkey/blob/master/driver-ti.c#L201

I downloaded the entire NetBSD repository, and:

# cd src/lib
# grep -r strnames .
# grep -r strfnames .

Nothing. Maybe you use libtermkey+unibilium instead of netbsd curses?

Try to compile libtermkey with netbsd curses. I'm almost sure that
there will be an error. I do not see any patches here:

https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=tree;f=libtermkey;hb=a8b89fb583cb83b0ce1323596596cf7fdd306ef4
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=blob;f=libtermkey/options.mk;h=53fd3c3943ec6f035ad88b102b325b362f22d4b7;hb=a8b89fb583cb83b0ce1323596596cf7fdd306ef4

Daniel
Leonardo Taccari
2018-11-24 15:04:12 UTC
Permalink
Post by Daniel Cegiełka
[...]
Nothing. Maybe you use libtermkey+unibilium instead of netbsd curses?
[...]
Yes, libtermkey package is built with unibilium support.
Daniel Cegiełka
2018-11-24 18:21:09 UTC
Permalink
Post by Leonardo Taccari
Post by Daniel Cegiełka
[...]
Nothing. Maybe you use libtermkey+unibilium instead of netbsd curses?
[...]
Yes, libtermkey package is built with unibilium support.
libtermkey+unibilium - unfortunately, the screen flickers when I
write. I tested libtermkey+unibilium on alpine, gentoo (chroot) and my
own distribution. That's why I try to use the netbsd-curses to avoid
having to install additional ncurses. vis+netbsd-curses works fine,
but unfortunately the terminal is not reset.
Michael Forney
2018-11-24 19:22:31 UTC
Permalink
Hi Daniel,
Post by Daniel Cegiełka
Hi,
https://lists.suckless.org/dev/1811/33025.html
I prepared a more detailed description of how to compile vis +
netbsd-curses.
DCL(strnames) = {
"cbt",
"bel",
(...)
"box1",
(NCURSES_CONST char *)0,
};
DCL(strfnames) = {
"back_tab",
"bell",
(...)
"box_chars_1",
(NCURSES_CONST char *)0,
};
const char *strnames[] = {
"cbt",
"bel",
(...)
"box1",
NULL,
};
const char *strfnames[] = {
"back_tab",
"bell",
(...)
"box_chars_1",
NULL,
};
When I looked into this, I went with a slightly different approach.
Instead of copying from ncurses, I generated the arrays from term.h
and an awk script.

awk '
/TICODE_[a-z]+,/ {
names[++numnames] = substr($1, 8, length($1) - 8)
}

/^#define t_[a-z_]+(t)/ {
fnames[++numfnames] = substr($2, 3, length($2) - 5)
}

END {
print "const char *const strnames[] = {"
for (i = 1; i <= numnames; ++i)
print("\t\"" names[i] "\",")
print "\t(void *)0"
print "};"

print "const char *const strfnames[] = {"
for (i = 1; i <= numfnames; ++i)
print("\t\"" fnames[i] "\",")
print "\t(void *)0"
print "};"
}
' libterminfo/term.h > libterminfo/names.c
Post by Daniel Cegiełka
#ifdef HAVE_UNIBILIUM
# include <unibilium.h>
#else
# include <curses.h>
# include <term.h>
/* strnames and strfnames */
#include "names.c"
/* curses.h has just poluted our namespace. We want this back */
# undef buttons
#endif
You don't need to include the whole names.c in term.h, just declare the arrays:

diff --git a/libterminfo/term.h b/libterminfo/term.h
index 884cfe9..8345a7f 100644
--- a/libterminfo/term.h
+++ b/libterminfo/term.h
@@ -1944,6 +1944,8 @@ extern "C" {
#endif

extern TERMINAL *cur_term;
+extern const char *const strfnames[];
+extern const char *const strnames[];

/* setup functions */
int setupterm(const char *, int, int *);
Post by Daniel Cegiełka
vis works fine, however, there is a problem when I use ':!' or ':e *'.
I think that the terminal settings are not restored. Does anyone have
an idea here how it can be solved?
I can confirm the issue here. No idea about how to solve it though.

Compared to ncurses, I also notice a bit of flickering when scrolling
fast (status bar occasionally blinks). I remember this problem being
more severe back when I looked into this, so I had decided to stick
with ncurses for oasis for the time being.
Daniel Cegiełka
2018-11-24 22:41:33 UTC
Permalink
Post by Michael Forney
Hi Daniel,
Post by Daniel Cegiełka
Hi,
When I looked into this, I went with a slightly different approach.
Instead of copying from ncurses, I generated the arrays from term.h
and an awk script.
Hi Michael,

Thx :) It was a quick solution :)
Post by Michael Forney
Post by Daniel Cegiełka
vis works fine, however, there is a problem when I use ':!' or ':e *'.
I think that the terminal settings are not restored. Does anyone have
an idea here how it can be solved?
I can confirm the issue here. No idea about how to solve it though.
Ok, so it looks like we can probably have a bigger problem with that.
Maybe let's try to determine where this error may be generated. We
have three places to consider: vis, libtermkey and netbsd-curses.

vis:
https://github.com/martanne/vis/blob/master/ui-terminal.c#L65
https://github.com/martanne/vis/blob/master/ui-terminal-curses.c#L39

In my opinion, this may be about (missing?) calling to (def_+)
reset_prog_mode() or (def_+) reset_shell_mode()

https://github.com/martanne/vis/blob/master/ui-terminal-curses.c#L247
https://github.com/martanne/vis/blob/master/ui-terminal-curses.c#L251

http://netbsd.gw.com/cgi-bin/man-cgi?curses_tty+3+NetBSD-current
https://linux.die.net/man/3/reset_prog_mode

In the next step, we can ask Marc André Tanner for some help.

btw. netbsd curses support ~510 color pairs :)
https://github.com/martanne/vis/blob/master/ui-terminal-curses.c#L39

Daniel
Daniel Cegiełka
2018-11-26 17:57:36 UTC
Permalink
Post by Michael Forney
Hi Daniel,
When I looked into this, I went with a slightly different approach.
Instead of copying from ncurses, I generated the arrays from term.h
and an awk script.
https://github.com/sabotage-linux/netbsd-curses/issues/34

Thx Michael

Loading...