Solved Enable curses interface for nethack36

Ktaadn

New Member

Reaction score: 1
Messages: 7

How do you enable the curses interface for nethack36?
Adding OPTIONS=windowtype:curses has no effect. According to #version nethack36 seems to be compiled with x11 and the tty only.
 

T-Daemon

Daemon

Reaction score: 932
Messages: 1,819

I wonder where. And this is not how options work in any case.
OP is referring to the ~/.nethackrc options:


OPTIONS=windowtype:curses

 
OP
Ktaadn

Ktaadn

New Member

Reaction score: 1
Messages: 7

Yes, I am referring to the ~/.nethackrc options. :)
 

T-Daemon

Daemon

Reaction score: 932
Messages: 1,819

Have you tried the NETHACKOPTIONS=windowtype:curses variable from the command line?
 
OP
Ktaadn

Ktaadn

New Member

Reaction score: 1
Messages: 7

Yes, I tried it from the command line – no effect, the game started in tty (default) mode. I also tried OPTIONS=windowtype:x11 in ~/.nethackrc – the game started in x11 mode, as expected.
 

ehanneken

Member

Reaction score: 20
Messages: 28

I can confirm that curses support is unavailable in the latest nethack36 package. (I'm running FreeBSD 12.1.) After configuring ~/.nethackrc with OPTIONS=windowtype:curses, I ran nethack and got

Code:
$ nethack

OPTIONS=windowtype:curses
* Line 1: Window type curses not recognized.  Choices are:  tty, X11.

1 error in /home/eric/.nethackrc.


Hit return to continue:

If I remove .nethackrc and set NETHACKOPTIONS from the command line, I get the same result. If I switch to the nethack36-nox11 package, I get the same result, except only tty is in the list of window type choices.

UPDATE: Okay, I see how to fix this. The port's Makefile sets CFLAGS like this:
Code:
.if !defined(PKGNAMESUFFIX)
USES+=        xorg
USE_XORG=    xaw xpm xmu xext xt x11 sm ice
CFLAGS+=    -DX11_GRAPHICS -DUSE_TILES
GRAPHICS=    X11_GRAPHICS
.else
.if ${PKGNAMESUFFIX} == "-nox11"
GRAPHICS=    # none
.endif
.endif
CFLAGS+=    -DNOMAIL

But looking at the nethack source code (specifically, windows.c), it appears that CURSES_GRAPHICS has to be defined for curses support. So just change that last line to

Makefile:
CFLAGS +=    -DNOMAIL -DCURSES_GRAPHICS

and recompile the port. That should let curses work. I think. I haven't tried it.
 
OP
Ktaadn

Ktaadn

New Member

Reaction score: 1
Messages: 7

Thank you very much for your help. Unfortunately, the port does not build:

Code:
ld: error: undefined symbol: curses_read_attrs
>>> referenced by options.c
>>>               options.o:(parseoptions)

ld: error: undefined symbol: curses_read_attrs
>>> referenced by options.c
>>>               options.o:(parseoptions)

ld: error: undefined symbol: curses_fmt_attrs
>>> referenced by options.c
>>>               options.o:(get_compopt_value)

ld: error: undefined symbol: curses_procs
>>> referenced by windows.c
>>>               windows.o:(winchoices)
 

ehanneken

Member

Reaction score: 20
Messages: 28

Thank you very much for your help. Unfortunately, the port does not build:

Rats. I see the same thing. I wonder if the FreeBSD base ncurses library lacks some of the functions that nethack depends on. I installed ncurses from packages, and tried editing /usr/ports/Mk/Uses/ncurses.mk to point to it, but the build still failed for the same reasons.
 
OP
Ktaadn

Ktaadn

New Member

Reaction score: 1
Messages: 7

I am trying the vanilla code from the official git repository now. There is WINTTYLIB=-ltermlib in the Makefile. I am wondering if this shouldn't better be WINTTYLIB=-lncurses.
 

ehanneken

Member

Reaction score: 20
Messages: 28

I misunderstood the build errors. curses_read_attrs, curses_fmt_attrs, and curses_procs are not defined in the ncurses library; they're defined in the nethack source code in win/curses/cursmisc.c and win/curses/cursmain.c.

This patch file in the nethack36 port needs to be amended. The line that says

Diff:
+WINSRC = $(WINTTYSRC)

should be changed to

Diff:
+WINSRC = $(WINTTYSRC) $(WINCURSESSRC)

and the line

Diff:
+WINOBJ = $(WINTTYOBJ)

should be changed to

Diff:
+WINOBJ = $(WINTTYOBJ) $(WINCURSESOBJ)

I'm not going to claim certainty until I test these changes (probably tomorrow).
 

ljboiler

Well-Known Member

Reaction score: 163
Messages: 441

In the nethack36/Makefile, I changed
Code:
.if ${PKGNAMESUFFIX} == "nox11"
GRAPHICS=    # none
to
Code:
.if ${PKGNAMESUFFIX} == "nox11"
GRAPHICS=    CURSES_GRAPHICS
then ran make install in nethack36-nox11.

I get what appears to be a working nethack in curses mode...
This is using ncurses from the base system, FreeBSD 12-STABLE.
 

memreflect

Well-Known Member

Reaction score: 221
Messages: 257

I get what appears to be a working nethack in curses mode...
This is using ncurses from the base system, FreeBSD 12-STABLE.
Does it have color, and do you see a large "NetHack" ASCII art banner beneath the "Shall I pick character's race, ..." prompt?

Edit: Nevermind. That's the TTY version. NetHack comes with a basic TTY interface, but it also can use colors and take advantage of other ncurses features. That's what windowtype:curses is for. env NETHACKOPTIONS='windowtype:curses' nethack36 should yield an error.
 

memreflect

Well-Known Member

Reaction score: 221
Messages: 257

I misunderstood the build errors. curses_read_attrs, curses_fmt_attrs, and curses_procs are not defined in the ncurses library; they're defined in the nethack source code in win/curses/cursmisc.c and win/curses/cursmain.c.

This patch file in the nethack36 port needs to be amended. The line that says

Diff:
+WINSRC = $(WINTTYSRC)
should be changed to
Diff:
+WINSRC = $(WINTTYSRC) $(WINCURSESSRC)
and the line
Diff:
+WINOBJ = $(WINTTYOBJ)
should be changed to
Diff:
+WINOBJ = $(WINTTYOBJ) $(WINCURSESOBJ)

I'm not going to claim certainty until I test these changes (probably tomorrow).

I pretty much did exactly that (along with patching the patch-sys-unix-Makefile.utl patch and the port's Makefile), and it works:
2020-05-15-011252_1920x1080_scrot.png

It's easy to apply the attached patch (based on the 2020Q2 branch of the ports tree) to modify the Makefile and the relevant patch files:
Code:
patch -d /usr/ports/games/nethack36 < path/to/nethack-curses.patch.txt

This will enable a new set of options: CURSES, X11, or none ('none' is the same as the -nox11 port). As far as I'm aware, I didn't break anything since I didn't remove anything.

I'm not the port maintainer, so I can't say when this will stop working. If this functionality is important to you, I recommend asking the port maintainer to support such functionality officially.
 

Attachments

  • nethack-curses.patch.txt
    4.7 KB · Views: 82
OP
Ktaadn

Ktaadn

New Member

Reaction score: 1
Messages: 7

You guys are awesome! Thanks so much! However, I have to give up. The port builds now but segfaults:

Code:
'nethack36' terminated by signal SIGSEGV

I give up. No nethack for me.
Thanks again for your help and your time to fix this.
 

ehanneken

Member

Reaction score: 20
Messages: 28

I've submitted a bug report (PR 246483). My patch is fairly simple; it just adds the "Curses" interface to the build. To enable that interface, a user still has to add OPTIONS=windowtype:curses to $HOME/.nethackrc. When that happens, the interface changes from this:

tty-interface.png

to this:

curses-splash-screen.png curses-introduction.png curses-interface.png

(memreflect: Don't forget to add that line to your .nethackrc file.)

I've attached the patch file to this post, in case anyone wants to apply it now.
 

Attachments

  • enable-curses-interface.diff.txt
    1.2 KB · Views: 93
OP
Ktaadn

Ktaadn

New Member

Reaction score: 1
Messages: 7

ehanneken

Thank you so much! Your patch did it. Finally, I'm able to enjoy Nethack with the Curses interface again. Thank you all.
 
Top