Snake game written in Bash has no snake or color #533

Closed
opened 2026-01-30 21:54:32 +00:00 by claunia · 4 comments
Owner

Originally created by @mobluse on GitHub (Jan 19, 2019).

I use the most updated Ubuntu 18.04 from Store.

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.17134.556]

  • What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)
    bash snake

  • What's wrong / what should be happening instead:
    The snake is hardly shown. In WSL, no color. In WSLTTY 1.9.5 there is color. This bash game works perfectly in Raspbian Stretch and Lubuntu 16.04.
    It should look like (i.e. with color and snake): http://wp.subnetzero.org/?p=269
    The Bash source is there too. I just copied it into nano and used exactly the same file in all computers.

Originally created by @mobluse on GitHub (Jan 19, 2019). I use the most updated Ubuntu 18.04 from Store. * Your Windows build number: (Type `ver` at a Windows Command Prompt) Microsoft Windows [Version 10.0.17134.556] * What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots) `bash snake` * What's wrong / what should be happening instead: The snake is hardly shown. In WSL, no color. In WSLTTY 1.9.5 there is color. This bash game works perfectly in Raspbian Stretch and Lubuntu 16.04. It should look like (i.e. with color and snake): http://wp.subnetzero.org/?p=269 The Bash source is there too. I just copied it into `nano` and used exactly the same file in all computers.
claunia added the Resolution-External label 2026-01-30 21:54:32 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Jan 21, 2019):

This is an interesting case. It looks like your distribution might be missing the termcap files for our declared terminal type, xterm-256color.

If you run TERM=xterm ./snake.sh (or whatever you've named the script), do you get colors and/or a snake?

A more constrained repro case would be:

tput setf 4 | cat -v

On Debian buster/sid, I get:

% tput setf 4 | cat -v
% # (nothing)  

However, if I use TERM=xterm, I get:

% TERM=xterm tput setf 4 | cat -v
^[[31m
%

If the termcap for xterm-256color is missing or incomplete (which is a distribution issue), tput won't produce any output, and the color won't be changed.

@DHowett-MSFT commented on GitHub (Jan 21, 2019): This is an interesting case. It looks like your distribution might be missing the termcap files for our declared terminal type, `xterm-256color`. If you run `TERM=xterm ./snake.sh` (or whatever you've named the script), do you get colors and/or a snake? A more constrained repro case would be: ``` tput setf 4 | cat -v ``` On Debian `buster/sid`, I get: ``` % tput setf 4 | cat -v % # (nothing) ``` However, if I use `TERM=xterm`, I get: ``` % TERM=xterm tput setf 4 | cat -v ^[[31m % ``` If the termcap for xterm-256color is missing or incomplete (which is a distribution issue), `tput` won't produce any output, and the color won't be changed.
Author
Owner

@j4james commented on GitHub (Jan 22, 2019):

I'm no expert, but my understanding was that terminals aren't necessarily expected to support both setf and setaf - just the one or the other. If you look at xterm+256color entry in the current terminfo source, you can see that the setf and setb capabilities are explicitly suppressed - you're expected to use setaf and setab instead.

So I don't think there's anything wrong with the termcap entry - I think the problem is with the snake script for assuming that setf would work on all terminals when that is quite often not true.

@j4james commented on GitHub (Jan 22, 2019): I'm no expert, but my understanding was that terminals aren't necessarily expected to support both `setf` and `setaf` - just the one or the other. If you look at xterm+256color entry in [the current terminfo source](https://invisible-island.net/datafiles/current/terminfo.src.gz), you can see that the `setf` and `setb` capabilities are explicitly suppressed - you're expected to use `setaf` and `setab` instead. So I don't think there's anything wrong with the termcap entry - I think the problem is with the snake script for assuming that `setf` would work on all terminals when that is quite often not true.
Author
Owner

@DHowett-MSFT commented on GitHub (Jan 22, 2019):

@j4james Great call! I wasn't aware that it might support one and explicitly suppress the other.

In light of that, I'm closing this as external -- the onus is on snake to use the right terminal capabilities. There's a trivial workaround in terms of setting TERM, as well.

@DHowett-MSFT commented on GitHub (Jan 22, 2019): @j4james Great call! I wasn't aware that it might support one and explicitly suppress the other. In light of that, I'm closing this as **external** -- the onus is on `snake` to use the right terminal capabilities. There's a trivial workaround in terms of setting `TERM`, as well.
Author
Owner

@mobluse commented on GitHub (Jan 22, 2019):

TERM=xterm ./snake in Ubuntu 18.04 from Store fixes the color, but the snake works in a strange way and 'SIZE=3' is printed several times within the playing field. I also changed setf to setaf and setb to setab, and run it with both TERM=xterm-256color ./snake and TERM=xterm ./snake, but the problem remain.

@mobluse commented on GitHub (Jan 22, 2019): `TERM=xterm ./snake` in Ubuntu 18.04 from Store fixes the color, but the snake works in a strange way and 'SIZE=3' is printed several times within the playing field. I also changed setf to setaf and setb to setab, and run it with both `TERM=xterm-256color ./snake` and `TERM=xterm ./snake`, but the problem remain.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#533