Coder Social home page Coder Social logo

apirogov / apconsolelib Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 264 KB

An extremely lightweight alternative for ncurses etc. for windows and linux, wrapping functions for setting color, getting keypresses and getting/setting console size and cursor location (just compile and see the demo, it's pretty self-explanatory)... It provides just the most neccessary features and is just useful if you just need this kind of features... otherwise use something more 'complete'

C 100.00%

apconsolelib's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

apconsolelib's Issues

Small enhancements

Hey there.

I am now using this library within my application, but wanted to report a small problem that there is.

The enum that contains the colors, should be move dinto the heaer file instead, as it can't be accessed otherwise.

I also have made a minimal piece of code that allows me to reset the console. I kinda picked the code up from stackoverflow and MSDN, but maybe it turns out to be useful.

#ifndef AP_HELPER
#define AP_HELPER

#ifdef WIN32
#include <windows.h>

// Console attributes.
HANDLE hConsole;
WORD saved_attributes;
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;

void initConsole() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
    WORD saved_attributes;

    /* Save current attributes */
    GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
    saved_attributes = consoleInfo.wAttributes;
}

void deinitConsole() {
    /* Restore original attributes */
    SetConsoleTextAttribute(hConsole, saved_attributes);
}

#else
#include <stdio.h>

// Nothing to do here
void initConsole() {}

void deinitConsole() {
    printf("\e[0m");
}
#endif

#endif

Kind regards, Ingwie.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.