Skip to content

A lightweight, beginner-friendly C++ library for Windows console manipulation. Perfect for creating colorful console applications, simple games, and learning Windows Console API.

License

Notifications You must be signed in to change notification settings

Coralesoft/ConCol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConCol - Windows Console Manipulation Library

C++17 Platform License Lines of Code First Created Modernized Maintained PRs Welcome

A lightweight, beginner-friendly C++ library for Windows console manipulation. Perfect for creating colorful console applications, simple games, and learning Windows Console API.

Author: C.Brown Original Version: 1.2 (2001) Current Version: 2.0 (C++17 Modernized, 2025) License: MIT Platform: Windows only

Overview

ConCol provides simple, easy-to-use functions for manipulating the Windows console:

  • Colors: Set foreground and background colors (16 colors each)
  • Cursor Control: Move cursor to any position
  • Screen Manipulation: Clear screen or sections
  • Window Sizing: Resize console window
  • Query Functions: Get console dimensions

Why ConCol?

Educational

  • Simple to understand - Great for beginners learning console programming
  • Well-documented - Clear API with usage examples
  • Minimal dependencies - Just Windows API and C++ Standard Library
  • Modern C++17 - Learn current best practices

Lightweight

  • Just 2 files - concol.hpp and concol.cpp
  • No external libraries - Pure Windows API
  • Small footprint - Under 200 lines of code
  • Fast compilation - Include and go

Beginner-Friendly

  • Easy API - Intuitive function names
  • Color constants - Use Red, Blue, LtGreen instead of numbers
  • Forgiving - Handles edge cases gracefully
  • Great for learning - Perfect first step before ncurses or other libraries

Quick Start

Requirements

  • Windows OS (XP or later)
  • C++17 compatible compiler (MinGW g++, MSVC, clang)

Installation

  1. Copy files to your project:

    concol.hpp
    concol.cpp
    
  2. Include header in your code:

    #include "concol.hpp"
  3. Compile with C++17:

    g++ -std=c++17 your_program.cpp concol.cpp -o your_program

Hello World Example

#include "concol.hpp"
#include <iostream>

int main()
{
    concol con;

    con.setForeground(LtGreen);
    con.setBackground(bBlue);
    con.ClearScreen();

    con.goto_XY(30, 10);
    std::cout << "Hello, Colorful World!";

    con.goto_XY(0, 20);
    return 0;
}

Available Colors

Foreground Colors (Text)

Black, Blue, Red, Green, Cyan, Magenta, Orange, DkGray,
LtGray, LtRed, LtGreen, LtBlue, LtCyan, LtMagenta, Yellow, White

Background Colors (Use 'b' prefix)

bBlue, bRed, bGreen, bCyan, bMagenta, bOrange, bDkGray,
bLtGray, bLtRed, bLtGreen, bLtBlue, bLtCyan, bLtMagenta, bYellow, bWhite

API Reference

Color Functions

// Set text color only
void setForeground(int fore);
con.setForeground(LtGreen);

// Set background color only
void setBackground(int back);
con.setBackground(bBlue);

// Set both colors at once (-1 to keep current)
void setColour(int fore, int back);
con.setColour(Yellow, bRed);
con.setColour(White, -1);  // Change foreground only
con.setColour(-1, bBlack); // Change background only

Cursor Control

// Move cursor to position (0-based)
void goto_XY(short x, short y);
con.goto_XY(10, 5);  // Column 10, Row 5

Screen Manipulation

// Clear entire screen
void ClearScreen();
con.ClearScreen();

// Clear from position to end of screen
void ClearSect(short x, short y);
con.ClearSect(0, 20);  // Clear from row 20 onwards

Window Functions

// Resize console window
void resizeWindow(short width, short height);
con.resizeWindow(80, 25);  // Classic 80x25

// Get console dimensions
short getPosX();  // Get width
short getPosY();  // Get height
int width = con.getPosX();
int height = con.getPosY();

Examples

See the examples/ directory for complete programs:

  • color_demo.cpp - Demonstrates all 16 colors
  • rainbow_text.cpp - Animated rainbow effect
  • simple_menu.cpp - Basic menu system
  • bouncing_ball.cpp - Simple animation

Color Demo

#include "concol.hpp"
#include <iostream>

int main()
{
    concol con;
    con.ClearScreen();

    const int colors[] = {Red, Green, Blue, Yellow, Cyan,
                          Magenta, LtRed, LtGreen, LtBlue,
                          LtCyan, LtMagenta, White};
    const char* names[] = {"Red", "Green", "Blue", "Yellow", "Cyan",
                           "Magenta", "LtRed", "LtGreen", "LtBlue",
                           "LtCyan", "LtMagenta", "White"};

    con.goto_XY(5, 2);
    std::cout << "ConCol Color Demonstration";

    for (int i = 0; i < 12; i++) {
        con.setForeground(colors[i]);
        con.goto_XY(5, 4 + i);
        std::cout << names[i] << " - The quick brown fox jumps over the lazy dog";
    }

    con.setForeground(White);
    con.goto_XY(0, 18);
    return 0;
}

Simple Animation

#include "concol.hpp"
#include <iostream>
#include <windows.h>

int main()
{
    concol con;
    con.ClearScreen();
    con.setForeground(LtCyan);

    // Bouncing ball across screen
    for (int x = 0; x < 70; x++) {
        con.goto_XY(x, 12);
        std::cout << "O";
        Sleep(50);
        con.goto_XY(x, 12);
        std::cout << " ";
    }

    con.goto_XY(0, 20);
    return 0;
}

Building Examples

Using g++ (MinGW)

g++ -std=c++17 -Wall examples/color_demo.cpp concol.cpp -o color_demo
./color_demo

Using MSVC

cl /std:c++17 /EHsc examples/color_demo.cpp concol.cpp
color_demo.exe

Tips for Beginners

  1. Always reset cursor - Use goto_XY(0, lastLine) before program exit
  2. Clear before drawing - Call ClearScreen() at start for clean slate
  3. Test colors - Run the color demo to see all options
  4. Coordinate system - (0,0) is top-left, X is column, Y is row
  5. Screen buffering - Use std::cout << std::flush for immediate display

Comparison with Other Libraries

Feature ConCol ncurses pdcurses termcolor
Complexity ⭐ Simple ⭐⭐⭐ Complex ⭐⭐ Moderate ⭐ Simple
Platform Windows Unix/Linux Cross-platform Cross-platform
Features Basic Full TUI Full TUI Colors only
Learning Curve Gentle Steep Moderate Gentle
Best For Beginners Production TUIs Cross-platform Simple color

Choose ConCol if:

  • You're learning C++ console programming
  • You need simple Windows console manipulation
  • You want minimal dependencies
  • You're building a small game or utility

Choose others if:

  • You need cross-platform support (ncurses/pdcurses)
  • You need advanced TUI features (windows, panels, forms)
  • You're building a production terminal application

Limitations

  • Windows-only - Uses Windows Console API directly
  • No Unicode - Basic ASCII/ANSI support only
  • 16 colors - Standard console palette only
  • Basic features - No advanced TUI elements (menus, forms, etc.)
  • No input - Only output; use std::cin or _getch() for input

Frequently Asked Questions

Q: Can I use this on Linux/Mac? A: No, ConCol uses Windows Console API. For cross-platform, consider ncurses or pdcurses.

Q: Does it work with modern Windows Terminal? A: Yes! Works with cmd.exe, PowerShell, and Windows Terminal.

Q: Can I use this commercially? A: Yes, MIT license allows commercial use.

Q: How do I handle keyboard input? A: ConCol handles output only. Use std::cin, _getch(), or Windows input functions.

Q: Can I change font size? A: No, console font is controlled by user's terminal settings.

Technical Details

C++17 Features Used

  • [[nodiscard]] attributes
  • noexcept specifications
  • Defaulted constructors/destructors (= default)
  • nullptr instead of NULL
  • static_cast for type safety
  • Modern include guards

Windows API Functions

  • GetStdHandle() - Get console handle
  • SetConsoleTextAttribute() - Set colors
  • SetConsoleCursorPosition() - Move cursor
  • FillConsoleOutputCharacter() - Clear screen
  • GetConsoleScreenBufferInfo() - Query console state
  • SetConsoleWindowInfo() - Resize window

Version History

  • v2.0 (2025) - C++17 modernization

    • Added noexcept, const correctness
    • Fixed all compiler warnings
    • Improved documentation
    • Added examples
    • Defaulted special members
  • v1.2 (2001) - Original version

    • Basic color and cursor control
    • Screen clearing
    • Window resizing
    • Created for Scrabble game project

📖 The Story Behind ConCol

I wrote the first version of ConCol back in 2001 as a first-year uni project. I needed colour and cursor control for a Scrabble assignment, so I poked around the WinAPI and built a ~200-line helper that just worked.

Fast-forward to 2025: I found the old code, cleaned it up, and kept the spirit the same — tiny, readable, and useful.

What changed

  • Updated to modern C++ (C++17)
  • Tidied warnings and rough edges
  • Wrote proper docs and examples
  • Kept it small — still under 200 lines

Why share it now Not everything needs a framework. Sometimes you just want to paint text, move a cursor, and crack on. If you’re learning C++ on Windows or you want a no-fuss console helper, this will get you moving without the faff.

If you’re curious where it started, the old Scrabble project lives here: https://github.com/Coralesoft/Scrabble

Contributing

Contributions welcome! This is an educational project, so:

  • Keep code simple and readable
  • Document new features clearly
  • Maintain beginner-friendliness
  • Add examples for new functionality

License

MIT License - see LICENSE file for details

Copyright (c) 2001-2025 C Brown

Acknowledgments

  • Created for a C++ Scrabble game assignment (2001)
  • Modernized to C++17 standards (2025)
  • Inspired by the need for simple console manipulation without the complexity of ncurses

Resources


Happy Console Programming! 🎨

If you find ConCol useful for learning, please star the repository and share with others!

About

A lightweight, beginner-friendly C++ library for Windows console manipulation. Perfect for creating colorful console applications, simple games, and learning Windows Console API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages