Syntax Highlighting

Syntax highlighting is a useful tool and nowadays a common feature with many text editors. Syntax highlighting is available with some Linux text pagers too although not always directly. The most popular pager with Linux probably is the less command.

Searching the web finds many articles about adding syntax highlighting with less, including adding color to man pages. The common advice to providing syntax highlighting with less is the source-highlight package. There are some caveats with this solution — some of the colors are difficult to read with a black background and syntax highlighting does not function with certain files.

The documentation is about as clear as mud, written by geeks for geeks.

With Slackware some of the usability problems include:

  • Viewing /var/log/syslog displays the date/time stamp in a dark blue that is almost unreadable with a black background.
  • Viewing /var/log/messages results in no highlighting at all, despite having the same file format as /var/log/syslog.
  • Viewing the Slackware ChangeLog.txt file does not highlight dates/times and has the same dark blue readability problem.

Other files have similar issues.

Editing the following files help some by changing the colors, such as blue to cyan:

  • /usr/share/source-highlight/default.style
  • /usr/share/source-highlight/esc.style

Part of the problem is the package seems designed from the perspective of the Debian distro. Thus the Slackware ChangeLog.txt file is not recognized as a changelog file nor is the /var/log/messages file recognized as a log file.

Editing /usr/bin/src-hilite-lesspipe.sh helps by changing the case statement from *ChangeLog|*changelog to *ChangeLog*|*changelog.

Adding another case statement helps resolve the issues with various system log files:


    *syslog*|*messages*|*dnsmasq*|*cron*|*debug*|*kernel*|*maillog*|*secure*)
      source-highlight —failsafe -f esc —lang-def=log.lang —style-file=esc.style -i "$source" ;;
    

Improving the highlighting with the Slackware ChangeLog.txt requires editing changelog.lang. This is done by replacing the date/time formatting with a more robust snippet from the log.lang file.

A complete patch is available here.

Posted: Category: Usability Tagged: Slackware

Next: Monthly and Weekly Cron Jobs

Previous: DD-WRT Inconsistency