Difference between revisions of "Menucolors"

From NetHackWiki
Jump to navigation Jump to search
(moving menucolors information to the menucolors page, off the patching page)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{patch
+
{{todo|Update info from original patch features to NetHack 3.6}}
|name=Menucolors
+
'''Menucolors''' is a feature in NetHack 3.6 and above that allows you to colorize individual rows on a menu based on what regular expressions match its text. You can color the [[inventory]] menu, the [[spellcasting]] menu, the [[enhance]] menu, the [[options]] menu, and more.
|author=Pasi Kallinen
 
|download=http://bilious.alt.org/~paxed/nethack/nh343-menucolor.diff
 
|bilious=11
 
}}
 
 
 
'''Menucolors''' is a [[patch]] that allows you to colorize individual rows on a menu based on what regular expressions match its text. The patch was written by [[User:paxed|paxed]] and can be found [http://bilious.alt.org/~paxed/nethack/nh343-menucolor.diff here]. You can color the [[inventory]] menu, the [[spellcasting]] menu, the [[enhance]] menu, the [[options]] menu, and more. Menucolors are currently only supported in a terminal and (partially) in the Windows GUI.
 
  
 
For example, you could color all [[blessed]] items bright cyan, all [[cursed]] items bright orange, and all [[uncursed]] items dim green. From there you could underline dangerous items (loadstone, wand of cancellation, etc.), make the [[Amulet of Yendor]] magenta, all [[gold]] yellow, and so on, until you're satisfied.
 
For example, you could color all [[blessed]] items bright cyan, all [[cursed]] items bright orange, and all [[uncursed]] items dim green. From there you could underline dangerous items (loadstone, wand of cancellation, etc.), make the [[Amulet of Yendor]] magenta, all [[gold]] yellow, and so on, until you're satisfied.
  
The menucolors patch also supports globbing instead of regular expressions; the resulting menucolors are far less powerful, but are more portable.
+
The menucolors can also support globbing instead of regular expressions; the resulting menucolors are far less powerful, but are more portable.
 
 
[[nethack.alt.org]] has the menucolors patch installed. You can test menucolors out before making the effort of [[patching]] it into your [[source code]].
 
 
 
There is a precompiled binary of NetHack 3.4.3 Windows GUI and TTY with menucolors available for download [http://bilious.alt.org/~paxed/nethack/nh343-menucolors.zip here].
 
 
 
This patch was incorporated into [[NetHack 3.6.0]]
 
  
 
==Details==
 
==Details==
Line 53: Line 41:
 
  MENUCOLOR="* holy *"=green
 
  MENUCOLOR="* holy *"=green
  
==Installing on Windows==
+
==Valid color values==
 
+
black
Please see the article on [[compiling]], the following assumes you have installed MinGW and NetHack's sources to the locations shown in that article.
+
red
 
+
green
*Download the patch binary zip package from http://gnuwin32.sourceforge.net/packages/patch.htm
+
  brown
 
+
  blue
*Unpack that into the bin directory of MinGW, so that the patch.exe will be in the same directory as mingw32-make.exe (e.g. c:\mingw\bin).
+
  magenta
 
+
  cyan
*Find the diff-file you want to patch, and download it on to your computer, preferably in the NetHack sources root directory, <tt>c:\nh343</tt>.
+
  gray
Note that linux-style line endings will cause problems, you need to convert those into Windows-style ones! You can do this for example copypasting the contents of that file from a browser window into Notepad, and then saving the notepad file.
+
  orange
In this example, we'll be using the [[menucolors]]-patch available at http://bilious.alt.org/~paxed/nethack/nh343-menucolor.diff
+
  bright green
We'll assume the file is saved in <tt>c:\nh343\</tt> as <tt>nh343-menucolor.diff</tt>
+
  yellow
 
+
  bright blue
*Start <tt>cmd.exe</tt> and do the following:
+
  bright magenta
  cd c:\nh343
+
bright cyan
  path=%path%;c:\mingw\bin
+
white
  patch -p1 < nh343-menucolor.diff
 
 
 
The <tt>1</tt> after the <tt>-p</tt> might need to be changed to <tt>0</tt> or possibly <tt>2</tt> for other patches.
 
 
 
note: On MS-Windows, the patchfile must be a text file, i.e. CR-LF must be used as line endings. A file with LF may give the error: "Assertion failed, hunk, file patch.c, line 343," unless the option '--binary' is given.
 
 
 
note: Newer version of windows require administrative privileges to run files named patch, which can break GNU patch, see here for a workaround: http://jameswynn.com/2010/03/gnu-patch-in-windows-7-or-vista/
 
 
 
*Some patches require extra configuration steps before compiling. For [[menucolors]], you need to edit <tt>c:\nh343\include\config.h</tt> by changing the line
 
  # define MENU_COLOR_REGEX
 
to
 
  /* # define MENU_COLOR_REGEX */
 
This changes the menucolors, so it won't try to use regular expressions, because MinGW does not come with regex header files. Menucolors also comes with it's own short README file, which should be <tt>c:\nh343\README.menucolor</tt>
 
 
 
*Compile NetHack, by running <tt>install.bat</tt> (Assuming you created one when [[compiling]] the source) or manually.
 
 
 
*Now you should be able to edit your RC file, and add menucolors as listed above.
 
 
 
If you want to use regular expressions for menucolors:
 
 
 
*Download the binary and developer packages from http://gnuwin32.sourceforge.net/packages/pcre.htm
 
 
 
*Edit <tt>src\Makefile.gcc</tt> and add <tt>-lpcre</tt> to WINPLIBS. There's two definitions of WINPLIBS, one is for TTY, the other for graphical GUI.
 
 
 
*Uncomment the <tt>MENU_COLOR</tt>, <tt>MENU_COLOR_REGEX</tt> and <tt>MENU_COLOR_REGEX_POSIX</tt> defines in <tt>include\config.h</tt>.
 
 
 
*Unpack the PCRE development package and copy <tt>libpcre.dll.a</tt> to <tt>c:\mingw\lib\</tt> and <tt>pcre.h</tt>, <tt>pcreposix.h</tt> and <tt>regex.h</tt> to <tt>c:\mingw\include\</tt>
 
 
 
*Run <tt>install.bat</tt> to compile NetHack.
 
 
 
*Unpack the PCRE binary package and copy <tt>pcre3.dll</tt> into the directory where NetHack binary is. (<tt>c:\nh343\binary\</tt>)
 
 
 
*You can now use regular expressions for menucolors, for an example see http://alt.org/nethack/userdata/Eidolos/Eidolos.nh343rc or put the following in your configuration file:
 
  OPTIONS=menucolors
 
  MENUCOLOR=" blessed "=green
 
  MENUCOLOR=" holy "=green
 
  MENUCOLOR=" cursed "=red
 
  MENUCOLOR=" unholy "=red
 
 
 
==Installing on Unix==
 
 
 
Unix is much simpler. Download the patch, and apply the patch with <code>patch < menucolors.diff </code>, while in the root directory of the nethack source tree. You may need to use the <code>-n</code> flag, depending on your location inside the directory tree.
 
 
 
 
 
[[Category:Patches]]
 

Latest revision as of 18:03, 14 January 2021

A user has suggested improving this page or section as follows:

"Update info from original patch features to NetHack 3.6"

Menucolors is a feature in NetHack 3.6 and above that allows you to colorize individual rows on a menu based on what regular expressions match its text. You can color the inventory menu, the spellcasting menu, the enhance menu, the options menu, and more.

For example, you could color all blessed items bright cyan, all cursed items bright orange, and all uncursed items dim green. From there you could underline dangerous items (loadstone, wand of cancellation, etc.), make the Amulet of Yendor magenta, all gold yellow, and so on, until you're satisfied.

The menucolors can also support globbing instead of regular expressions; the resulting menucolors are far less powerful, but are more portable.

Details

The menucolors are applied top to bottom, and each successive match replaces the colors and attributes.

Unfortunately, there's a bug in that setting an attribute (bold, underline, etc) resets the color of a line, and vice versa. You can work around this by setting color&attribute, but that's not a very general solution.

For the purposes of regex matching, the menu accelerator and the hyphen separating it from the menu entry are considered part of the entry by the menucolors patch. However, patches to NAO during May and June of 2012 altered this behavior, and these features are no longer part of the entry. In other words, "q - a club" or "a - autodig" will match a club in your inventory or the autodig option in the options menu as long as you aren't playing on NAO. If you are playing on NAO, you would need to use "a club" and "autodig".

The regular expressions match against menu entry separately, so you are free to use the ^ and $ operators to match the beginning and the end of the entries.

Examples

For examples of extensive menucolors, see the .nethackrc files of Eidolos and itsblah. Here's an example nethackrc file that includes menucolors (which uses regular expressions, not globbing):

OPTIONS=color,menucolors

MENUCOLOR="blessed"=cyan&bold
MENUCOLOR="cursed"=orange&bold
MENUCOLOR="uncursed"=green

MENUCOLOR="loadstone\|wand \(of\|called\) cancellation"=underline
MENUCOLOR="Amulet of Yendor named"=magenta                           # color only the real Amulet
MENUCOLOR="gold piece"=yellow

MENUCOLOR="[a-zA-Z] - [a-zA-Z ]+[ ]+[0-9]+\*[ ]+[a-z]+[ ]+[0-9]+%"=magenta  # forgotten spell
# This version will work on NAO.
# MENUCOLOR="[a-zA-Z ]+[ ]+[0-9]+\*[ ]+[a-z]+[ ]+[0-9]+%"=magenta  # forgotten spell

and here is an example that uses globbing, that is, only ? and * wildcards.

OPTIONS=color,menucolors

MENUCOLOR="* cursed *"=red
MENUCOLOR="* unholy *"=red
MENUCOLOR="* blessed *"=green
MENUCOLOR="* holy *"=green

Valid color values

black
red
green
brown
blue
magenta
cyan
gray
orange
bright green
yellow
bright blue
bright magenta
bright cyan
white