Prepare for the winners of **IOCCC28**. > However these are not the 2024 droids you are looking for. :-) The HTML menu (both JavaScript and non-JavaScript) has been updated. The `Status -> Rules and guidelines' have been replaced with two separate menus `Status -> IOCCC rules` and `Status -> IOCCC guidelines`. Added a new top level `social.html` page: built from a new `social.md`. Sorted rules for building specific web pages in the top level `Makefile`. Added `make social` to make the `social.html` page from `social.md`. The `bin/gen-top-html.sh` now is able to process a argument of **social** to process the new top level `social.html` page. Changed `bin/gen-top-html.sh` VERSION from "2.0.0 2025-03-13" to "2.0.1 2025-07-25". Below `About -> Home page` a new `About -> IOCCC social media` menu item as added. Because the menu change touched every HTML file, we changed the general copyright date range for HTML files from "1984-2024" to "1984-2025" due to the extensive changes made for **IOCCC28**. Those markdown files that were modified in 2025 had their copyright date range also changed from "1984-2024" to "1984-2025". Rebuilt tarballs and sitemap due to the extensive HTML rebuilding. Ran `make update` to perform the above.
831 lines
32 KiB
HTML
831 lines
32 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||
<!-- START: two lines up starts content from: inc/top.default.html -->
|
||
|
||
<!-- END: this line ends content from: inc/top.default.html -->
|
||
<!-- START: this line starts content from: inc/head.default.html -->
|
||
|
||
<head>
|
||
<link rel="stylesheet" href="../../ioccc.css">
|
||
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap" rel="stylesheet">
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
<title>The International Obfuscated C Code Contest</title>
|
||
<link rel="icon" type="image/x-icon" href="../../favicon.ico">
|
||
<meta name="description" content="terminals.md for 2020/ferguson1">
|
||
<meta name="keywords" content="IOCCC, 2020/ferguson1, terminals.md">
|
||
</head>
|
||
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
|
||
<!-- END: this line ends content from: inc/head.default.html -->
|
||
|
||
<!-- -->
|
||
<!-- This web page was formed via the tool: bin/gen-other-html.sh -->
|
||
<!-- The content of main section of this web page came from: 2020/ferguson1/terminals.md -->
|
||
<!-- -->
|
||
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2020/ferguson1/terminals.md !!! -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2020/ferguson1/terminals.md !!! -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2020/ferguson1/terminals.md !!! -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
|
||
<!-- Markdown content was converted into HTML via the tool: bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content from: inc/body.default.html -->
|
||
|
||
<body>
|
||
|
||
<!-- END: this line ends content from: inc/body.default.html -->
|
||
<!-- START: this line starts content from: inc/topbar.default.html -->
|
||
|
||
<div class="theader">
|
||
<nav class="topbar">
|
||
<div class="container">
|
||
<div class="logo">
|
||
<a href="../../index.html" class="logo-link">
|
||
IOCCC
|
||
</a>
|
||
</div>
|
||
|
||
<div class="topbar-items">
|
||
<div class="item">
|
||
<span class="item-header">
|
||
Entries
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../years.html" class="sub-item-link">
|
||
Winning entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../authors.html" class="sub-item-link">
|
||
Winning authors
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../location.html" class="sub-item-link">
|
||
Location of authors
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../bugs.html" class="sub-item-link">
|
||
Bugs and (mis)features
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#fix_an_entry" class="sub-item-link">
|
||
Fixing entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#fix_author" class="sub-item-link">
|
||
Updating author info
|
||
</a>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="item">
|
||
<span class="item-header">
|
||
Status
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../news.html" class="sub-item-link">
|
||
News
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../status.html" class="sub-item-link">
|
||
Contest status
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../next/rules.html" class="sub-item-link">
|
||
IOCCC rules
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../next/guidelines.html" class="sub-item-link">
|
||
IOCCC guidelines
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../markdown.html" class="sub-item-link">
|
||
Markdown guidelines
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../SECURITY.html" class="sub-item-link">
|
||
Security policy
|
||
</a>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="item">
|
||
<span class="item-header">
|
||
FAQ
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html" class="sub-item-link">
|
||
Frequently asked questions
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../quick-start.html#enter" class="sub-item-link">
|
||
Enter the IOCCC
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#compiling" class="sub-item-link">
|
||
Compiling entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#running_entries" class="sub-item-link">
|
||
Running entries
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../faq.html#help" class="sub-item-link">
|
||
How to help
|
||
</a>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="item">
|
||
<span class="item-header">
|
||
About
|
||
</span>
|
||
|
||
<div class="sub-item">
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../index.html" class="sub-item-link">
|
||
Home page
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../social.html" class="sub-item-link">
|
||
IOCCC social media
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../about.html" class="sub-item-link">
|
||
About the IOCCC
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../judges.html" class="sub-item-link">
|
||
The judges
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../thanks-for-help.html" class="sub-item-link">
|
||
Thanks for the help
|
||
</a>
|
||
</div>
|
||
|
||
<div class="outfit-font">
|
||
<a href="../../contact.html" class="sub-item-link">
|
||
Contact us
|
||
</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<div class="header-mobile-menu">
|
||
<noscript>
|
||
<a href="../../nojs-menu.html" class="topbar-js-label">
|
||
Please Enable JavaScript
|
||
</a>
|
||
</noscript>
|
||
|
||
<button id="header-open-menu-button" class="topbar-mobile-menu">
|
||
<img
|
||
src="../../png/hamburger-icon-open.png"
|
||
alt="hamburger style menu icon - open state"
|
||
width=48
|
||
height=48>
|
||
</button>
|
||
|
||
<button id="header-close-menu-button" class="hide-content">
|
||
<img
|
||
src="../../png/hamburger-icon-closed.png"
|
||
alt="hamburger style menu icon - closed state"
|
||
width=48
|
||
height=48>
|
||
</button>
|
||
|
||
<div id="mobile-menu-panel" class="hide-content">
|
||
<div class="mobile-menu-container">
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
<div class="mobile-menu-item">
|
||
Entries
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../years.html">
|
||
Winning entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../authors.html">
|
||
Winning authors
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../location.html">
|
||
Location of authors
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../bugs.html">
|
||
Bugs and (mis)features
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#fix_an_entry">
|
||
Fixing entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#fix_author">
|
||
Updating author info
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../thanks-for-help.html">
|
||
Thanks for the help
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
|
||
<div class="mobile-menu-item">
|
||
Status
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../news.html">
|
||
News
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../status.html">
|
||
Contest status
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../next/rules.html">
|
||
IOCCC rules
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../next/guidelines.html">
|
||
IOCCC guidelines
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../markdown.html">
|
||
Markdown guidelines
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../SECURITY.html">
|
||
Security policy
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
<div class="mobile-menu-item">
|
||
FAQ
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html">
|
||
Frequently asked questions
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../quick-start.html#enter">
|
||
Enter the IOCCC
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#compiling">
|
||
Compiling entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#running_entries">
|
||
Running entries
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../faq.html#help">
|
||
How to help
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mobile-menu-wrapper">
|
||
<div class="mobile-menu-item">
|
||
About
|
||
</div>
|
||
<div class="mobile-submenu-wrapper">
|
||
|
||
<a class="mobile-submenu-item" href="../../index.html">
|
||
Home page
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../social.html">
|
||
IOCCC social media
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../about.html">
|
||
About the IOCCC
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../judges.html">
|
||
The judges
|
||
</a>
|
||
|
||
<a class="mobile-submenu-item" href="../../contact.html">
|
||
Contact us
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<script>
|
||
var headerOpenMenuButton = document.getElementById("header-open-menu-button");
|
||
var headerCloseMenuButton = document.getElementById("header-close-menu-button");
|
||
var mobileMenuPanel = document.getElementById("mobile-menu-panel");
|
||
|
||
headerOpenMenuButton.addEventListener("click", () => {
|
||
headerOpenMenuButton.classList.remove("topbar-mobile-menu");
|
||
headerOpenMenuButton.classList.add("hide-content");
|
||
|
||
headerCloseMenuButton.classList.remove("hide-content");
|
||
headerCloseMenuButton.classList.add("topbar-mobile-menu");
|
||
|
||
mobileMenuPanel.classList.remove("hide-content");
|
||
mobileMenuPanel.classList.add("topbar-mobile-panel");
|
||
});
|
||
|
||
headerCloseMenuButton.addEventListener("click", () => {
|
||
headerCloseMenuButton.classList.remove("topbar-mobile-menu");
|
||
headerCloseMenuButton.classList.add("hide-content");
|
||
|
||
mobileMenuPanel.classList.add("hide-content");
|
||
mobileMenuPanel.classList.remove("topbar-mobile-panel");
|
||
|
||
headerOpenMenuButton.classList.add("topbar-mobile-menu");
|
||
headerOpenMenuButton.classList.remove("hide-content");
|
||
});
|
||
</script>
|
||
|
||
<!-- END: this line ends content from: inc/topbar.default.html -->
|
||
<!-- START: this line starts content from: inc/header.default.html -->
|
||
|
||
<div class="header">
|
||
<a href="../../2011/zucker/index.html">
|
||
<img src="../../png/ioccc.png"
|
||
alt="IOCCC image by Matt Zucker"
|
||
width=300
|
||
height=110>
|
||
</a>
|
||
<h1>The International Obfuscated C Code Contest</h1>
|
||
<h2>terminals.html for 2020/ferguson1</h2>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/header.default.html -->
|
||
<!-- START: this line starts content from: inc/navbar.up2index.html -->
|
||
|
||
<div class="navbar">
|
||
<a class="Left" href="index.html">↑ jump to 2020/ferguson1/index.html ↑</a>
|
||
<a class="Right" href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.ioccc.org%2F2020%2Fferguson1%2Fterminals.html">✓</a>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/navbar.up2index.html -->
|
||
<!-- START: this line starts content from: inc/before-content.default.html -->
|
||
|
||
<div class="content" id="content">
|
||
|
||
<!-- END: this line ends content from: inc/before-content.default.html -->
|
||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||
|
||
<!-- BEFORE: 1st line of markdown file: 2020/ferguson1/terminals.md -->
|
||
<h1 id="terminals">Terminals</h1>
|
||
<p>Terminals are very easy to mess up and for that reason they deserve their own
|
||
file. I discuss terminal capabilities, dimensions (setting and how to restore
|
||
sanity if it causes any problems) as well as colours (limitations etc.).</p>
|
||
<div id="toc">
|
||
<ul>
|
||
<li><a href="#termcaps">Capabilities support testing program</a></li>
|
||
<li><a href="#dimensions">Setting the game dimensions</a>
|
||
<ul>
|
||
<li><a href="#linescolumns">The LINES and COLUMNS environmental variables</a></li>
|
||
<li><a href="#insanity">Terminal insanity</a></li>
|
||
<li><a href="#restore">Restoring the terminal</a></li>
|
||
<li><a href="#abuse">Terminal size abuse</a></li>
|
||
</ul></li>
|
||
<li><a href="#termlimitations">Terminal limitations</a></li>
|
||
<li><a href="#colours">Terminal colours</a>
|
||
<ul>
|
||
<li><a href="#background">Curses background</a></li>
|
||
<li><a href="#monochrome">Monochrome terminals</a></li>
|
||
<li><a href="#colourlimitations">Colour limitations</a></li>
|
||
<li><a href="#disablecolour">Disabling colour</a></li>
|
||
</ul></li>
|
||
</ul>
|
||
</div>
|
||
<div id="termcaps">
|
||
<h1 id="capabilities-support-testing-program"><a href="#toc">Capabilities support testing program</a></h1>
|
||
</div>
|
||
<p>Although it should be playable without the features I use (except that cursor
|
||
movement is required) I have provided a source file that can test your terminal
|
||
for the capabilities I use in the entry.</p>
|
||
<p>It also tries to determine the minimum number of columns to play without the
|
||
status line overflowing - even with the dynamic length. Try:</p>
|
||
<pre><code> $ make test</code></pre>
|
||
<p>This compiles the program <a href="https://github.com/ioccc-src/winner/blob/master/2020/ferguson1/termcaps.c">termcaps.c</a> and runs it; you should see something like:</p>
|
||
<pre><code> terminal supports cursor movement
|
||
terminal supports making cursor invisible
|
||
terminal supports bold
|
||
terminal supports colours
|
||
|
||
terminal rows 41 (38 playable)
|
||
terminal cols 155 (153 playable)
|
||
|
||
snake size: 997 (max size: 5776)
|
||
bugs: 199 (max size: 1155)
|
||
|
||
at least 34 columns (currently 155) recommended for snake size 997
|
||
at least 37 columns (currently 155) recommended for capped snake size 5776
|
||
|
||
No problems detected.</code></pre>
|
||
<p>Terminal rows and cols are the current values (the number of columns shown later
|
||
as well). The snake size is the default size to win (based on the variables, see
|
||
below). The <code>max size: 5776</code> is the capped size (or ‘capsize’). The 199 bugs is
|
||
approximately the <code>snake_size / growth_size</code> i.e. how many bugs it
|
||
will take to win the game. The max bugs in the <code>bugs</code> line is approximately
|
||
<code>max_snake_size / growth_size</code> i.e. how many bugs it’ll take to win at the
|
||
maximum (capped) snake size.</p>
|
||
<p>If I pass in any of the variables <strong>GROW</strong>, <strong>MAXSIZE</strong>, <strong>SIZE</strong> and/or
|
||
<strong>LINES</strong> or <strong>COLUMNS</strong> it bases its calculations on those variables. For
|
||
example:</p>
|
||
<pre><code> terminal supports cursor movement
|
||
terminal supports making cursor invisible
|
||
terminal supports bold
|
||
terminal supports colours
|
||
|
||
terminal rows 41 (38 playable)
|
||
terminal cols 155 (153 playable)
|
||
|
||
snake size: 5776 (max size: 5776)
|
||
bugs: 5771 (max size: 5771)
|
||
|
||
at least 37 columns (currently 155) recommended for snake size 5776
|
||
at least 37 columns (currently 155) recommended for capped snake size 5776
|
||
|
||
No problems detected.</code></pre>
|
||
<p>As you can see it tells you the max size (the ‘capsized’ snake) as well as the
|
||
requested max size (if the requested size is bigger than the capped size then it
|
||
will be set to that value instead) of the snake. The capped size is like in the
|
||
Snake game itself but the suggested minimum number of columns is based on a
|
||
number of variables.</p>
|
||
<p>If I were to do the above but set columns to less < 35 then there would be a
|
||
problem. But why if the utility recommends at least 37? This is because the
|
||
max size of the snake also depends on the terminal size. This utility is not
|
||
perfect: I don’t consider shedding; I set growth to 5 if it’s 0 (since it would
|
||
be indeterminate how many bugs are possible before ‘winning’ since there would
|
||
be no ‘winning’); and there are probably other things too.</p>
|
||
<p>As for capabilities: besides cursor movement the others are just nice to have.
|
||
From my tests keeping the cursor visible doesn’t ruin gameplay but it is less
|
||
distracting if nothing else to have it invisible (in fact due to the sequence of
|
||
function calls the cursor would mostly appear to be not in the game field itself -
|
||
from memory at least).</p>
|
||
<p>Maybe there are other capabilities I should check for that I’m unaware of but
|
||
this should give you an idea.</p>
|
||
<p>If there are any problems it will say how many (fatal and otherwise). The fatal
|
||
problems are if curses fails to initialise or if movement of cursor cannot be
|
||
done (both seem unlikely to happen nowadays).</p>
|
||
<p>Both scripts run this utility and prompt if there are any problems;
|
||
you can continue either way.</p>
|
||
<div id="dimensions">
|
||
<h1 id="setting-the-game-dimensions"><a href="#toc">Setting the game dimensions</a></h1>
|
||
</div>
|
||
<p>There are a number of ways to do this and only one will keep the terminal sane
|
||
all the time but that’s by running it under a terminal emulator that you can
|
||
resize the window with first. But what if you want exacts?</p>
|
||
<div id="linescolumns">
|
||
<h2 id="the-lines-and-columns-environmental-variables"><a href="#toc">The LINES and COLUMNS environmental variables</a></h2>
|
||
</div>
|
||
<p>To specify the lines/columns of curses program per instance use the <code>LINES</code> and
|
||
<code>COLUMNS</code> environmental variables.</p>
|
||
<p>For demonstration consider the following:</p>
|
||
<pre><code> $ echo $LINES $COLUMNS
|
||
42 157</code></pre>
|
||
<p>Note: I subtract 1 from the max y/x and the max coords in the game output
|
||
include the walls and score line but these values are for the terminal itself.</p>
|
||
<p>Say you want 55 columns:</p>
|
||
<pre><code> $ COLUMNS=55 ./prog</code></pre>
|
||
<p>This will force curses to detect the max columns (X) of your terminal (for the
|
||
game dimensions) - to be 55; it might look like this instead:</p>
|
||
<pre><code> X:27/54 Y:20/41 S:5/997 B:0</code></pre>
|
||
<p>But problems can arise with messing with dimensions: in my tests this held only
|
||
to lines.</p>
|
||
<div id="insanity">
|
||
<h2 id="terminal-insanity"><a href="#toc">Terminal insanity</a></h2>
|
||
</div>
|
||
<p>Terminal sanity can be compromised and it can cause all sorts of output
|
||
problems; it might not appear right away but it will show its ugly head
|
||
eventually if you use it. For example pager output might be screwy, echo might
|
||
be turned off, output of commands might overwrite the input of those commands,
|
||
etc. For the game you might not see the final score.</p>
|
||
<div id="restore">
|
||
<h3 id="restoring-the-terminal"><a href="#toc">Restoring the terminal</a></h3>
|
||
</div>
|
||
<p>In my tests there is one thing that at least allows you to see the final score
|
||
and that is by running <code>clear</code> before running the program. That’s what the
|
||
prog.alt version does. You might run it as one of:</p>
|
||
<pre><code> LINES=20 ./prog.alt
|
||
LINES=20 ./snake.alt</code></pre>
|
||
<p>Even if the final score is visible though the terminal may very well still be
|
||
messed up. There are numerous things you might try but probably the easiest is
|
||
to run the game again without modifying the dimensions (and then just quit) or
|
||
even just the <code>reset</code> command.</p>
|
||
<p>The Linux man page says:</p>
|
||
<blockquote>
|
||
<p>You might have to run the <code>reset</code> tool like:</p>
|
||
<p><code><LF>reset<LF></code></p>
|
||
<p>(the line-feed character is normally control-J) to get the terminal to work,
|
||
as carriage-return may no longer work in the abnormal state.</p>
|
||
</blockquote>
|
||
<p>If you don’t have the reset utility you can try:</p>
|
||
<pre><code> echo -e \\033c</code></pre>
|
||
<p>Otherwise try <code>clear; stty sane</code> (that will turn on echo also) or if all else
|
||
fails log out and back in.</p>
|
||
<p>For more information on this subject generally see the <a href="https://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO.html">Linux keyboard and
|
||
console HOWTO</a> (specifically <a href="https://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-4.html">Linux keyboard and console HOWTO section 4</a>).
|
||
Yes this works under macOS (at least it did for me).</p>
|
||
<div id="abuse">
|
||
<h3 id="terminal-size-abuse"><a href="#toc">Terminal size abuse</a></h3>
|
||
</div>
|
||
<p>So players 1, 2 and 3 are content with not meddling with the terminal sizes
|
||
outside what’s actually possible with their screen. But then player 4 comes
|
||
along and thinks he/she will be clever and mess with the dimensions a bit. Let’s
|
||
say they have a 13” monitor and they think it’d be funny to see how 997 lines
|
||
would work; they might try something like:</p>
|
||
<pre><code> LINES=997 ./prog</code></pre>
|
||
<p>What then? Well expect trouble; curses will not know any better and the max
|
||
number of lines will be 997. If they were to do:</p>
|
||
<pre><code> COLUMNS=997 ./prog</code></pre>
|
||
<p>Then they will see a different effect. Again the same reason: the player trying
|
||
to be funny.</p>
|
||
<p>The game will try and be funny in return and you can expect it to not function
|
||
properly. Because that’s what funny means in this context.</p>
|
||
<div id="termlimitations">
|
||
<h1 id="terminal-limitations"><a href="#toc">Terminal limitations</a></h1>
|
||
</div>
|
||
<p>It’d be nice if curses could detect hitting more than one arrow key at the
|
||
same time so that diagonal directions would be possible but unfortunately it’s
|
||
not (<code>cat -v</code> confirms this). Even if I were to define four extra keys what
|
||
would they be? And what about the head character? The <a href="HACKING.html">HACKING.html</a>
|
||
file has information on this.</p>
|
||
<p>I also limit the terminal size to 10 lines/columns but most likely it would
|
||
require the cheat modes to win and in any event allowing certain low values
|
||
causes problems e.g. <strong>LINES=6 COLUMNS=6</strong> and <strong>LINES=3 COLUMNS=3</strong> caused some
|
||
nasty issues.</p>
|
||
<div id="colours">
|
||
<h1 id="terminal-colours"><a href="#toc">Terminal colours</a></h1>
|
||
</div>
|
||
<p>N.B.: If all you’re after is wanting to change the colours see the script
|
||
<a href="https://github.com/ioccc-src/winner/blob/master/2020/ferguson1/snake-colours.sh">snake-colours.sh</a> instead. The rest of this file was mostly notes for the
|
||
judges; here I discuss the background, foreground as well as limitations (in
|
||
particular runtime limitations).</p>
|
||
<div id="background">
|
||
<h2 id="curses-background"><a href="#toc">Curses background</a></h2>
|
||
</div>
|
||
<p>The documentation I have seen says that the background will always be black and
|
||
from a quick test this holds even with a terminal that has a white background.
|
||
There is a way to force the background to remain white though that’s by way of
|
||
monochrome (so no colours); I discuss that and another related terminal specific
|
||
in the troubleshooting guide (there’s another way but it would take me over the
|
||
iocccsize; I talk about it in the <a href="HACKING.html">HACKING.html</a>.</p>
|
||
<div id="monochrome">
|
||
<h2 id="monochrome-terminals"><a href="#toc">Monochrome terminals</a></h2>
|
||
</div>
|
||
<p>According to my tests for monochrome terminals the screen has the white and
|
||
black background; if terminal is configured to be black background white
|
||
foreground that is the order it is too. You can try that like:</p>
|
||
<pre><code> TERM=linux-m ./prog</code></pre>
|
||
<p>But I do not specifically check if the terminal has colours. Is there a curses
|
||
implementation that has a problem here? Below I explain what to comment out
|
||
should you need colours to be disabled but I personally have not run into any
|
||
problems even with monochrome terminals. Later I say what to do to remove colour
|
||
support in the source code itself.</p>
|
||
<div id="colourlimitations">
|
||
<h2 id="colour-limitations"><a href="#toc">Colour limitations</a></h2>
|
||
</div>
|
||
<p>According to X/Open Curses, Issue 7 (pg. 57):</p>
|
||
<blockquote>
|
||
<p>With <code>init_pair()</code> and <code>pair_content()</code>, the value of pair must be in a range from
|
||
0 to and including <code>COLOR_PAIRS-1</code>. (There may be an implementation-specific upper
|
||
limit on the valid value of pair, but any such limit is at least 63.) Valid
|
||
values for f and b are the range from 0 to and including <code>COLORS-1</code>.</p>
|
||
</blockquote>
|
||
<p>The manpage for <code>init_pair()</code> says this:</p>
|
||
<blockquote>
|
||
<p>These limits apply to color values and color pairs. Values outside these
|
||
limits are not legal, and may result in a runtime error:</p>
|
||
<p>[…]</p>
|
||
<p><code>COLOR_PAIRS</code> corresponds to the terminal database’s <code>max_pairs</code> capability,
|
||
(see <code>terminfo(5)</code>).</p>
|
||
</blockquote>
|
||
<p>Based on the two as well as the fact that monochrome terminals (I’ve tried under
|
||
both Linux and macOS) seem to work fine I believe I am fine here too. And to
|
||
confirm this I wrote the following code with the output below:</p>
|
||
<pre><code> #include <curses.h>
|
||
|
||
int main()
|
||
{
|
||
initscr();
|
||
start_color();
|
||
printw("COLORS: %d\nCOLOR_PAIRS: %d\n", COLORS, COLOR_PAIRS);
|
||
getch();
|
||
endwin();
|
||
}</code></pre>
|
||
<pre><code> TERM=linux-m ./colour_pairs
|
||
COLORS: 0
|
||
COLOR_PAIRS: 0</code></pre>
|
||
<p>Without specifying the TERM I get:</p>
|
||
<pre><code> COLORS: 256
|
||
COLOR_PAIRS: 32767</code></pre>
|
||
<p>In the case that colour is supported the standard states that there will be more
|
||
possible colour pairs than I have used so that’s not a problem either. Perhaps
|
||
even it would only be a runtime error if the colours are supported and the
|
||
number is out of the range? To try and figure this out I did another test:</p>
|
||
<pre><code> int main()
|
||
{
|
||
initscr();
|
||
start_color();
|
||
|
||
init_pair(COLOR_PAIRS+1, COLOR_WHITE, COLOR_GREEN);
|
||
bkgd(COLOR_PAIR(COLOR_PAIRS+1));
|
||
init_pair(1, COLOR_WHITE, COLOR_BLACK);
|
||
attron(COLOR_PAIR(1));
|
||
printw("COLORS: %d\nCOLOR_PAIRS: %d\n", COLORS, COLOR_PAIRS);
|
||
|
||
getch();
|
||
endwin();
|
||
}</code></pre>
|
||
<p>Running it like</p>
|
||
<pre><code> TERM=linux-m ./colour_pairs</code></pre>
|
||
<p>I got the output as if colours weren’t used: 0 and 0. With coloured terminals
|
||
however it was not visible. If I however comment out the call to <code>bkgd()</code> I get
|
||
instead:</p>
|
||
<pre><code> COLORS: 256
|
||
COLOR_PAIRS: 32767</code></pre>
|
||
<p>Which leads me to believe that if you try using a value outside the range it
|
||
won’t work for a colour-capable terminal but it doesn’t matter for monochrome
|
||
terminals one way or another. And since I don’t go beyond the ranges (as I cited
|
||
earlier) there shouldn’t be any problem here.</p>
|
||
<div id="disablecolour">
|
||
<h2 id="disabling-colour"><a href="#toc">Disabling colour</a></h2>
|
||
</div>
|
||
<p>Nevertheless if it is a problem and you don’t want to use a monochrome terminal
|
||
(or can’t):</p>
|
||
<p>First comment out the code that has <code>start_color();</code> and then add <code>return;</code> to the
|
||
top of the <code>C()</code> function (the rest of the code won’t be reached). If necessary
|
||
you can also comment out the <code>init_pair()</code> calls.</p>
|
||
<p>Perhaps you only need to add the <code>return;</code> to <code>C()</code>. My guess is that’s the case
|
||
but I do not know for certain.</p>
|
||
<hr style="width:10%;text-align:left;margin-left:0">
|
||
<p>Jump to: <a href="#">top</a></p>
|
||
<!--
|
||
|
||
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
|
||
|
||
You are free to share and adapt this file under the terms of this license:
|
||
|
||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||
|
||
For more information, see:
|
||
|
||
https://creativecommons.org/licenses/by-sa/4.0/
|
||
|
||
-->
|
||
<!-- AFTER: last line of markdown file: 2020/ferguson1/terminals.md -->
|
||
|
||
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content from: inc/after-content.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/after-content.default.html -->
|
||
<!-- START: this line starts content from: inc/footer.default.html -->
|
||
|
||
<!--
|
||
|
||
Copyright © 1984-2025 by Landon Curt Noll. All Rights Reserved.
|
||
|
||
You are free to share and adapt this file under the terms of this license:
|
||
|
||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||
|
||
For more information, see:
|
||
|
||
https://creativecommons.org/licenses/by-sa/4.0/
|
||
|
||
-->
|
||
|
||
<div class="footer">
|
||
|
||
<div id="copyright"><h3>Copyright © 1984-2025 by Landon Curt Noll:
|
||
<a href="https://creativecommons.org/faq/#what-does-some-rights-reserved-mean"
|
||
target="_blank"
|
||
rel="license noopener noreferrer">Some Rights Reserved</a></h3>
|
||
<p>
|
||
This work is <b>licensed by Landon Curt Noll</b> under
|
||
<b><a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=chooser-v1"
|
||
target="_blank"
|
||
rel="license noopener noreferrer"
|
||
style="display:inline-block;">CC BY-SA 4.0</a></b>.
|
||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||
src="../../png/cc.png"
|
||
alt="cc inside circle symbol">
|
||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||
src="../../png/by.png"
|
||
alt="person inside circle symbol">
|
||
<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;"
|
||
src="../../png/sa.png"
|
||
alt="arrow looping back on itself inside circle symbol"><br>
|
||
You should <b>carefully review</b> the
|
||
<b><a href="https://creativecommons.org/licenses/by-sa/4.0/legalcode.en"
|
||
target="_blank"
|
||
rel="license noopener noreferrer">CC BY-SA 4.0 LEGAL CODE</a></b>
|
||
before using the licensed material.<br>
|
||
You may wish to review the
|
||
<b><a href="../../license.html"
|
||
target="_blank"
|
||
rel="license noopener noreferrer">highlights of some of the key features and terms</a></b>
|
||
of <b>CC BY-SA 4.0</b>.<br>
|
||
</p>
|
||
</div>
|
||
|
||
<div id="coda"><h3>Coda</h3>
|
||
<p>
|
||
<a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.ioccc.org%2F2020%2Fferguson1%2Fterminals.html" rel="nofollow">Nu HTML check this web page</a><br>
|
||
<a href="#top">Jump to top</a> <a href="#content">Jump to Content</a>
|
||
</p>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/footer.default.html -->
|
||
<!-- START: this line starts content from: inc/bottom.default.html -->
|
||
|
||
</body>
|
||
</html>
|
||
|
||
<!-- END: this line ends content from: inc/bottom.default.html -->
|