<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="https://www.linuxjournal.com/">
  <channel>
    <title>ncurses</title>
    <link>https://www.linuxjournal.com/</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>Build Your Own Internet Radio Receiver</title>
  <link>https://www.linuxjournal.com/content/build-your-own-internet-radio-receiver</link>
  <description>  &lt;div data-history-node-id="1340545" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/nick-tufillaro" lang="" about="https://www.linuxjournal.com/users/nick-tufillaro" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Nick Tufillaro&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Tune in to communities around the world with the push of a button.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
When I get home at night, I like to tune into the world with the push
of a button. I've lived in lots of different places—from Dunedin,
New Zealand, to Santa Fe, New Mexico—and in each town, I've come to love
a radio station (usually a community radio station) that embodies
the spirit of the place. With the push of a button, I can get a bit back
in sync with each of these places and also visit new communities, thanks
to internet radio.
&lt;/p&gt;

&lt;p&gt;
Why build your own internet radio receiver? One option, of course, is
simply to use an app for a receiver. However, I've found that the most common
apps don't keep their focus on the task at hand, and are increasingly
distracted by offering additional social-networking services. And besides,
I want to listen now. I don't want to check into my computer or phone,
log in yet again, and endure the stress of recalling YAPW (Yet Another
PassWord). I've also found that the current offering of internet radio
boxes falls short of my expectations. Like I said, I've lived in a lot
of places—more than two or four or eight. I want a lot of buttons, so I can
tune in to a radio station with just one gesture. Finally, I've noticed
that streams are increasingly problematic if I don't go directly to
the source. Often, streams chosen through a "middle man" start with
an ad or blurb that is tacked on as a preamble. Or sometimes the "middle man" might
tie me to a stream of lower audio quality than the best being served up.
&lt;/p&gt;

&lt;p&gt;
So, I turned to building my own internet radio receiver—one with lots
of buttons that allow me to "tune in" without being too pushy. In this
article,
I share my experience. In principle, it should be easy—you just need a Linux distro, a ship to sail her on and an external
key pad for a rudder. In practice, it's not too hard, but there are a
few obstacles along the course that I hope to help you navigate.
&lt;/p&gt;

&lt;p&gt;
My recipe list included the following:
&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;
A used notebook with an ultra low voltage
(Core 2 Duo) processor.&lt;/li&gt;

&lt;li&gt;
An audio interface with an optical TOSLINK.&lt;/li&gt;

&lt;li&gt;
pyradio: an open-source Python radio program.&lt;/li&gt;

&lt;li&gt;
An external keypad.&lt;/li&gt;&lt;/ol&gt;&lt;img src="https://www.linuxjournal.com/sites/default/files/styles/max_650x650/public/u%5Buid%5D/12693f1smaller.png" width="600" height="572" alt="""" class="image-max_650x650" /&gt;&lt;p&gt;
&lt;em&gt;Figure 1. My Hardware Setup&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
Why a notebook and not a Raspberry Pi or ship of a similar ilk? Mostly
due to time—my time in particular. It's not too hard to find a high quality
notebook about ten years old for about $50, so the cost is really not
that different, and I find the development platform to be much
quicker.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/build-your-own-internet-radio-receiver" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 27 May 2019 11:00:00 +0000</pubDate>
    <dc:creator>Nick Tufillaro</dc:creator>
    <guid isPermaLink="false">1340545 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Programming Text Windows with ncurses</title>
  <link>https://www.linuxjournal.com/content/programming-text-windows-ncurses</link>
  <description>  &lt;div data-history-node-id="1340367" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/jim-hall" lang="" about="https://www.linuxjournal.com/users/jim-hall" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Jim Hall&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;How to use ncurses to manipulate your terminal
screen.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
In my article series about programming for the text console using the ncurses
library, I showed you how to draw text on the screen and use basic text
attributes. My examples of Sierpinski's Triangle (see &lt;a href="https://www.linuxjournal.com/content/getting-started-ncurses"&gt;"Getting
Started with ncurses"&lt;/a&gt;) and a simple Quest
adventure game (see &lt;a href="https://www.linuxjournal.com/content/creating-adventure-game-terminal-ncurses"&gt;"Creating
an Adventure Game in the Terminal with ncurses"&lt;/a&gt;) used the entire screen at once.
&lt;/p&gt;

&lt;p&gt;
But what if it makes more
sense to divide the screen into portions? For example, the adventure game
might divide the screen to use part of it for the game map and another
portion of the screen for the player's status. Many programs organize the
screen into multiple parts—for instance, the Emacs editor uses an editing
pane, a status bar and a command bar. You might need to divide your
program's display areas similarly. There's an easy way to do that,
and that's with the windows functions in ncurses. This is a standard part
of any curses-compatible library.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Simple Senet&lt;/span&gt;

&lt;p&gt;
You may associate "windows" with a graphical environment, but that is
not the case here. In ncurses, "windows" are a means to divide the
screen into logical areas. Once you define a window, you don't need to
track its location on the screen; you just draw to your window using a set of
ncurses functions.
&lt;/p&gt;

&lt;p&gt;
To demonstrate, let me define a game board in an unexpected way. The ancient
Egyptian game &lt;a href="https://en.wikipedia.org/wiki/Senet"&gt;&lt;em&gt;Senet&lt;/em&gt;&lt;/a&gt;
uses a
board of 30 squares arranged in three rows and ten columns. Two players
move their pieces around the board in a backward "S" formation, so
that the board looks like this:
&lt;/p&gt;

&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;
1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;19&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;21&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;td&gt;24&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;26&lt;/td&gt;
&lt;td&gt;27&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;
Without the windows functions, you'd have to keep track of the row and
column for each piece and draw them separately. Since the board is arranged
in a backward "S" pattern, you'll always need to do weird math
to position the row and column correctly every time you update each square on
the board. But with the windows functions, ncurses lets you define the squares
once, including their position, and later refer to those windows by a logical
identifier.
&lt;/p&gt;

&lt;p&gt;
The ncurses function &lt;code&gt;newwin()&lt;/code&gt; lets you define a text window of certain
dimensions at a specific location on the screen:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/programming-text-windows-ncurses" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Tue, 05 Mar 2019 13:00:00 +0000</pubDate>
    <dc:creator>Jim Hall</dc:creator>
    <guid isPermaLink="false">1340367 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>About ncurses Colors</title>
  <link>https://www.linuxjournal.com/content/about-ncurses-colors-0</link>
  <description>  &lt;div data-history-node-id="1340201" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/jim-hall" lang="" about="https://www.linuxjournal.com/users/jim-hall" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Jim Hall&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Why does ncurses support only eight colors?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
If you've looked into the color palette available in curses, you may
wonder why curses supports only eight colors. The curses.h include file
defines these color macros:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
COLOR_BLACK
COLOR_RED
COLOR_GREEN
COLOR_YELLOW
COLOR_BLUE
COLOR_MAGENTA
COLOR_CYAN
COLOR_WHITE
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
But why only eight colors, and why these particular colors? At least with the Linux
console, if you're running on a PC, the color range's origins are
with the PC hardware.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
A Brief History of Color&lt;/span&gt;

&lt;p&gt;
Linux started as a PC operating system, so the first Linux console was a PC
running in text mode. And to understand the color palette on the PC console,
you need to go all the way back to the old CGA days. In text mode, the PC
terminal had a color palette of 16 colors, enumerated 0 (black) to 15
(white). Backgrounds were limited to the first eight colors:
&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;
0. Black
&lt;/li&gt;

&lt;li&gt;
1. Blue
&lt;/li&gt;

&lt;li&gt;
2. Green
&lt;/li&gt;

&lt;li&gt;
3. Cyan
&lt;/li&gt;

&lt;li&gt;
4. Red
&lt;/li&gt;

&lt;li&gt;
5. Magenta
&lt;/li&gt;

&lt;li&gt;
6. Brown
&lt;/li&gt;

&lt;li&gt;
7. White ("Light Gray")
&lt;/li&gt;

&lt;li&gt;
8. Bright Black ("Gray")
&lt;/li&gt;

&lt;li&gt;
9. Bright Blue
&lt;/li&gt;

&lt;li&gt;
10. Bright Green
&lt;/li&gt;

&lt;li&gt;
11. Bright Cyan
&lt;/li&gt;

&lt;li&gt;
12. Bright Red
&lt;/li&gt;

&lt;li&gt;
13. Bright Magenta
&lt;/li&gt;

&lt;li&gt;
14. Yellow
&lt;/li&gt;

&lt;li&gt;
15. Bright White
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;
These colors go back to CGA, IBM's Color/Graphics Adapter from the
earlier PC-compatible computers. This was a step up from the plain
monochrome displays; as the name implies, monochrome could display
only black or white. CGA could display a limited range of colors.
&lt;/p&gt;

&lt;p&gt;
CGA supports mixing red (R), green (G) and blue (B) colors. In its simplest
form, RGB is either "on" or "off". In this case, you can mix the RGB colors
in 2x2x2=8 ways. Table 1 shows the
binary and decimal representations of RGB.
&lt;/p&gt;

&lt;table&gt;&lt;span class="h3-replacement"&gt;Table 1. Binary and Decimal Representations of RGB&lt;/span&gt;


&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;000&lt;/td&gt;
&lt;td&gt;(0)&lt;/td&gt;
&lt;td&gt;Black&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;001&lt;/td&gt;
&lt;td&gt;(1)&lt;/td&gt;
&lt;td&gt;Blue&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;010&lt;/td&gt;
&lt;td&gt;(2)&lt;/td&gt;
&lt;td&gt;Green&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
011&lt;/td&gt;
&lt;td&gt;(3)&lt;/td&gt;
&lt;td&gt;Cyan&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
100&lt;/td&gt;
&lt;td&gt;(4)&lt;/td&gt;
&lt;td&gt;Red&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;(5)&lt;/td&gt;
&lt;td&gt;Magenta&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;
110&lt;/td&gt;
&lt;td&gt;(6)&lt;/td&gt;
&lt;td&gt;Yellow&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;111&lt;/td&gt;
&lt;td&gt;(7)&lt;/td&gt;
&lt;td&gt;White&lt;/td&gt;
&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;
To double the number of colors, CGA added an extra bit called the
"intensifier" bit. With the intensifier bit set, the red, green and blue
colors would be set to their maximum values. Without the intensifier bit,
each RGB value would be set to a "midrange" intensity. Let's represent that
intensifier bit as an extra 1 or 0 in the binary color representation, as
iRGB (Table 2).

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/about-ncurses-colors-0" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Thu, 13 Dec 2018 13:00:00 +0000</pubDate>
    <dc:creator>Jim Hall</dc:creator>
    <guid isPermaLink="false">1340201 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>It’s Here. The March 2018 Issue of Linux Journal Is Available for Download Now.</title>
  <link>https://www.linuxjournal.com/content/its-here-march-2018-issue-linux-journal-available-download-now</link>
  <description>  &lt;div data-history-node-id="1339791" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/carlie-fairchild" lang="" about="https://www.linuxjournal.com/users/carlie-fairchild" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Carlie Fairchild&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;Boasting as many pages as most technical books, this month’s issue of &lt;cite&gt;Linux Journal&lt;/cite&gt; comes in at a hefty 181—that’s 23 articles exploring topics near and dear to everyone from home automation hobbyists to Free Software advocates to hard-core hackers to high-level systems architects.
&lt;p&gt;
&lt;/p&gt;
&lt;img src="https://www.linuxjournal.com/core/misc/icons/e32700/error.svg" alt="Image removed." title="This image has been removed. For security reasons, only images from the local domain are allowed." class="imagecache-small-200px-left-align-wrap filter-image-invalid" height="16" width="16" /&gt;
Besides making the magazine bigger overall with more articles in each issue on a wider range of topics, we’ve also added a new feature that explores a given topic in-depth: the Deep Dive—think of it like an ebook inside each magazine. This month contributing editor Petros Koutoupis dives deep in to blockchain. He explores what makes Bitcoin and blockchain so exciting, what they provide, and what the future of blockchain holds. From there, he describes how to set up a private Etherium blockchain using open-source tools and looks at some markets and industries where blockchain technologies can add value.
&lt;p&gt;
&lt;/p&gt;
Subscribers, you can &lt;a href="https://secure2.linuxjournal.com/pdf/dljdownload.php"&gt;download your March issue&lt;/a&gt; now.
&lt;p&gt;
&lt;/p&gt;
Not a subscriber? It’s not too late. &lt;a href="http://www.linuxjournal.com/subscribe"&gt;Subscribe today&lt;/a&gt; and receive instant access to this and all back issues since 2010. Alternatively, you can buy the single issue &lt;a href="https://linuxjournalstore.com/collections/back-issues-of-linux-journal/products/march-2018-issue-of-linux-journal"&gt;here&lt;/a&gt;.&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/its-here-march-2018-issue-linux-journal-available-download-now" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Tue, 13 Mar 2018 15:08:24 +0000</pubDate>
    <dc:creator>Carlie Fairchild</dc:creator>
    <guid isPermaLink="false">1339791 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Programming in Color with ncurses</title>
  <link>https://www.linuxjournal.com/content/programming-color-ncurses</link>
  <description>  &lt;div data-history-node-id="1339651" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/jim-hall" lang="" about="https://www.linuxjournal.com/users/jim-hall" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Jim Hall&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Jim demonstrates color manipulation with
&lt;code&gt;curses&lt;/code&gt; by adding colors to his terminal adventure
game.&lt;/em&gt;&lt;/p&gt;


&lt;p&gt;
In parts &lt;a href="http://www.linuxjournal.com/content/getting-started-ncurses"&gt;one&lt;/a&gt;
and &lt;a href="http://www.linuxjournal.com/content/creating-adventure-game-terminal-ncurses"&gt;two&lt;/a&gt;
of my article series about programming with the &lt;code&gt;ncurses&lt;/code&gt;
library, I introduced a few &lt;code&gt;curses&lt;/code&gt; functions to draw text on the screen,
query characters from the screen and read from the keyboard. To demonstrate
several of these functions, I created a simple adventure game in
&lt;code&gt;curses&lt;/code&gt; that
drew a game map and player character using simple characters. In this
follow-up article, I show how to add color to a &lt;code&gt;curses&lt;/code&gt; program.
&lt;/p&gt;

&lt;p&gt;
Drawing on the screen is all very well and good, but if it's all white-on-black
text, your program might seem dull. Colors can help convey more
information—for example, if your program needs to indicate success or
failure. In such a
case, you could display text in green or red to help emphasize the outcome.
Or,
maybe you simply want to use colors to "snazz" up your program to make it look
prettier.
&lt;/p&gt;

&lt;p&gt;
In this article, I use a simple example to demonstrate color manipulation via the
&lt;code&gt;curses&lt;/code&gt; functions. In my previous article, I wrote a basic adventure-style
game that lets you move a player character around a crudely drawn map.
However, the
map was entirely black and white text, relying on shapes to suggest water (~)
or mountains (^), so let's update the game to use colors.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Color Essentials&lt;/span&gt;

&lt;p&gt;
Before you can use colors, your program needs to know if it can rely on the
terminal to display the colors correctly. On modern systems, this always
should be true. But in the classic days of computing, some terminals were
monochromatic, such as the venerable VT52 and VT100 terminals, usually
providing white-on-black or green-on-black text.
&lt;/p&gt;

&lt;p&gt;
To query the terminal
capability for colors, use the &lt;code&gt;has_colors()&lt;/code&gt; function. This will return a true
value if the terminal can display color, and a false value if not. It is
usually used to start an &lt;code&gt;if&lt;/code&gt; block, like this:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
if (has_colors() == FALSE) {
    endwin();
    printf("Your terminal does not support color\n");
    exit(1);
}
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
Having determined that the terminal can display color, you then can set up
&lt;code&gt;curses&lt;/code&gt;
to use colors with the &lt;code&gt;start_color()&lt;/code&gt; function. Now you're ready to define
the colors your program will use.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/programming-color-ncurses" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Tue, 06 Feb 2018 20:36:22 +0000</pubDate>
    <dc:creator>Jim Hall</dc:creator>
    <guid isPermaLink="false">1339651 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Creating an Adventure Game in the Terminal with ncurses</title>
  <link>https://www.linuxjournal.com/content/creating-adventure-game-terminal-ncurses</link>
  <description>  &lt;div data-history-node-id="1339620" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/jim-hall" lang="" about="https://www.linuxjournal.com/users/jim-hall" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Jim Hall&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;
How to use &lt;code&gt;curses&lt;/code&gt; functions to read the keyboard and manipulate the
screen.&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
My &lt;a href="http://www.linuxjournal.com/content/getting-started-ncurses"&gt;previous
article&lt;/a&gt; introduced the &lt;code&gt;ncurses&lt;/code&gt; library and provided a simple
program that demonstrated a few &lt;code&gt;curses&lt;/code&gt; functions to put text on the screen. In
this follow-up article, I illustrate how to use a few other
&lt;code&gt;curses&lt;/code&gt;
functions.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
An Adventure&lt;/span&gt;

&lt;p&gt;
When I was growing up, my family had an Apple II computer. It was on this
machine that my brother and I taught ourselves how to write programs in
AppleSoft BASIC. After writing a few math puzzles, I moved on to creating
games. Having grown up in the 1980s, I already was a fan of the &lt;em&gt;Dungeons and
Dragons&lt;/em&gt; tabletop games, where you role-played as a fighter or wizard on some
quest to defeat monsters and plunder loot in strange lands. So it
shouldn't be surprising that I also created a rudimentary adventure game.
&lt;/p&gt;

&lt;p&gt;
The AppleSoft BASIC programming environment supported a neat feature: in
standard resolution graphics mode (GR mode), you could probe the color of a
particular pixel on the screen. This allowed a shortcut to create an adventure
game. Rather than create and update an in-memory map that was
transferred to the screen periodically, I could rely on GR mode to maintain the map for me,
and my program could query the screen as the player's character moved
around the screen. Using this method, I let the computer do most of the hard
work. Thus, my top-down adventure game used blocky GR mode graphics to
represent my game map.
&lt;/p&gt;

&lt;p&gt;
My adventure game used a simple map that represented a large field with a
mountain range running down the middle and a large lake on the upper-left side. I
might crudely draw this map for a tabletop gaming campaign to include a narrow
path through the mountains, allowing the player to pass to the far side.
&lt;/p&gt;

&lt;img src="http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/quest-map.jpg" alt="" title="" class="imagecache-large-550px-centered" /&gt;&lt;p&gt;
&lt;em&gt;Figure 1. A simple Tabletop Game Map with a Lake and Mountains&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
You can draw this map in &lt;code&gt;curses&lt;/code&gt;using characters to represent
grass, mountains and water. Next, I describe how to do just that using
&lt;code&gt;curses&lt;/code&gt;
functions and how to create and play a similar adventure game in the Linux terminal.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Constructing the Program&lt;/span&gt;

&lt;p&gt;
In my last article, I mentioned that most &lt;code&gt;curses&lt;/code&gt; programs start with the same
set of instructions to determine the terminal type and set up the
&lt;code&gt;curses&lt;/code&gt;
environment:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
initscr();
cbreak();
noecho();
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
For this program, I add another statement:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/creating-adventure-game-terminal-ncurses" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Fri, 26 Jan 2018 16:26:49 +0000</pubDate>
    <dc:creator>Jim Hall</dc:creator>
    <guid isPermaLink="false">1339620 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Getting Started with ncurses</title>
  <link>https://www.linuxjournal.com/content/getting-started-ncurses</link>
  <description>  &lt;div data-history-node-id="1339608" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/jim-hall" lang="" about="https://www.linuxjournal.com/users/jim-hall" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Jim Hall&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;How to use &lt;code&gt;curses&lt;/code&gt; to draw to the terminal screen.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
While graphical user interfaces are very cool, not every program needs to run with
a point-and-click interface. For example, the venerable vi editor ran in
plain-text terminals long before the first GUI.
&lt;/p&gt;

&lt;p&gt;
The vi editor is one example of a screen-oriented program that draws in
"text" mode, using a library called &lt;code&gt;curses&lt;/code&gt;, which provides a set of
programming interfaces to manipulate the terminal screen. The
&lt;code&gt;curses&lt;/code&gt; library
originated in BSD UNIX, but Linux systems provide this functionality through the
&lt;code&gt;ncurses&lt;/code&gt; library.
&lt;/p&gt;

&lt;p&gt;
&lt;em&gt;[For a "blast from the past" on &lt;code&gt;ncurses&lt;/code&gt;, see &lt;a href="http://www.linuxjournal.com/article/1124"&gt;"ncurses: Portable
Screen-Handling for Linux"&lt;/a&gt;,
September 1, 1995, by Eric S. Raymond.]&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
Creating programs that use &lt;code&gt;curses&lt;/code&gt; is actually quite simple. In this article,
I show an example program that leverages &lt;code&gt;curses&lt;/code&gt; to draw to the terminal
screen.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Sierpinski's Triangle&lt;/span&gt;

&lt;p&gt;
One simple way to demonstrate a few &lt;code&gt;curses&lt;/code&gt; functions is by generating
Sierpinski's Triangle. If you aren't familiar with this method to generate
Sierpinski's Triangle, here are the rules:
&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;
Set three points that define a triangle.
&lt;/li&gt;

&lt;li&gt;
Randomly select a point anywhere (&lt;em&gt;x,y&lt;/em&gt;).
&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;
Then:
&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;
Randomly select one of the triangle's points.
&lt;/li&gt;

&lt;li&gt;
Set the new &lt;em&gt;x,y&lt;/em&gt; to be the midpoint between the previous
&lt;em&gt;x,y&lt;/em&gt; and
the triangle point.
&lt;/li&gt;

&lt;li&gt;
Repeat.
&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;
So with those instructions, I wrote this program to draw Sierpinski's Triangle
to the terminal screen using the &lt;code&gt;curses&lt;/code&gt; functions:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/getting-started-ncurses" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Thu, 18 Jan 2018 21:22:32 +0000</pubDate>
    <dc:creator>Jim Hall</dc:creator>
    <guid isPermaLink="false">1339608 at https://www.linuxjournal.com</guid>
    </item>

  </channel>
</rss>
