libnx  v4.7.0
Data Structures | Macros | Enumerations | Functions
console.h File Reference

Framebuffer text console. More...

#include "../../types.h"

Go to the source code of this file.

Data Structures

struct  ConsoleRenderer
 Renderer interface for the console. More...
 
struct  ConsoleFont
 A font struct for the console. More...
 
struct  PrintConsole
 Console structure used to store the state of a console render context. More...
 

Macros

#define CONSOLE_ESC(x)   "\x1b[" #x
 
#define CONSOLE_RESET   CONSOLE_ESC(0m)
 
#define CONSOLE_BLACK   CONSOLE_ESC(30m)
 
#define CONSOLE_RED   CONSOLE_ESC(31;1m)
 
#define CONSOLE_GREEN   CONSOLE_ESC(32;1m)
 
#define CONSOLE_YELLOW   CONSOLE_ESC(33;1m)
 
#define CONSOLE_BLUE   CONSOLE_ESC(34;1m)
 
#define CONSOLE_MAGENTA   CONSOLE_ESC(35;1m)
 
#define CONSOLE_CYAN   CONSOLE_ESC(36;1m)
 
#define CONSOLE_WHITE   CONSOLE_ESC(37;1m)
 
#define CONSOLE_COLOR_BOLD   (1<<0)
 Bold text.
 
#define CONSOLE_COLOR_FAINT   (1<<1)
 Faint text.
 
#define CONSOLE_ITALIC   (1<<2)
 Italic text.
 
#define CONSOLE_UNDERLINE   (1<<3)
 Underlined text.
 
#define CONSOLE_BLINK_SLOW   (1<<4)
 Slow blinking text.
 
#define CONSOLE_BLINK_FAST   (1<<5)
 Fast blinking text.
 
#define CONSOLE_COLOR_REVERSE   (1<<6)
 Reversed color text.
 
#define CONSOLE_CONCEAL   (1<<7)
 Concealed text.
 
#define CONSOLE_CROSSED_OUT   (1<<8)
 Crossed out text.
 
#define CONSOLE_FG_CUSTOM   (1<<9)
 Foreground custom color.
 
#define CONSOLE_BG_CUSTOM   (1<<10)
 Background custom color.
 

Enumerations

enum  debugDevice {
  debugDevice_NULL ,
  debugDevice_SVC ,
  debugDevice_CONSOLE
}
 Console debug devices supported by libnx. More...
 

Functions

void consoleSetFont (PrintConsole *console, ConsoleFont *font)
 Loads the font into the console. More...
 
void consoleSetWindow (PrintConsole *console, int x, int y, int width, int height)
 Sets the print window. More...
 
PrintConsoleconsoleGetDefault (void)
 Gets a pointer to the console with the default values. More...
 
PrintConsoleconsoleSelect (PrintConsole *console)
 Make the specified console the render target. More...
 
PrintConsoleconsoleInit (PrintConsole *console)
 Initialise the console. More...
 
void consoleExit (PrintConsole *console)
 Deinitialise the console. More...
 
void consoleUpdate (PrintConsole *console)
 Updates the console, submitting a new frame to the display. More...
 
void consoleDebugInit (debugDevice device)
 Initializes debug console output on stderr to the specified device. More...
 
void consoleClear (void)
 Clears the screan by using printf("\x1b[2J");.
 

Detailed Description

Framebuffer text console.

Author
yellows8
WinterMute

Provides stdio integration for printing to the Switch screen as well as debug print functionality provided by stderr.

General usage is to initialize the console by:

PrintConsole * consoleInit(PrintConsole *console)
Initialise the console.

optionally customizing the console usage by passing a pointer to a custom PrintConsole struct.

Enumeration Type Documentation

◆ debugDevice

Console debug devices supported by libnx.

Enumerator
debugDevice_NULL 

Swallows prints to stderr.

debugDevice_SVC 

Outputs stderr debug statements using svcOutputDebugString, which can then be captured by interactive debuggers.

debugDevice_CONSOLE 

Directs stderr debug statements to Switch console window.

Function Documentation

◆ consoleDebugInit()

void consoleDebugInit ( debugDevice  device)

Initializes debug console output on stderr to the specified device.

Parameters
deviceThe debug device (or devices) to output debug print statements to.

◆ consoleExit()

void consoleExit ( PrintConsole console)

Deinitialise the console.

Parameters
consoleA pointer to the console data to initialize (if it's NULL, the default console will be used).

◆ consoleGetDefault()

PrintConsole* consoleGetDefault ( void  )

Gets a pointer to the console with the default values.

This should only be used when using a single console or without changing the console that is returned, otherwise use consoleInit().

Returns
A pointer to the console with the default values.

◆ consoleInit()

PrintConsole* consoleInit ( PrintConsole console)

Initialise the console.

Parameters
consoleA pointer to the console data to initialize (if it's NULL, the default console will be used).
Returns
A pointer to the current console.

◆ consoleSelect()

PrintConsole* consoleSelect ( PrintConsole console)

Make the specified console the render target.

Parameters
consoleA pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console)).
Returns
A pointer to the previous console.

◆ consoleSetFont()

void consoleSetFont ( PrintConsole console,
ConsoleFont font 
)

Loads the font into the console.

Parameters
consolePointer to the console to update, if NULL it will update the current console.
fontThe font to load.

◆ consoleSetWindow()

void consoleSetWindow ( PrintConsole console,
int  x,
int  y,
int  width,
int  height 
)

Sets the print window.

Parameters
consoleConsole to set, if NULL it will set the current console window.
xX location of the window.
yY location of the window.
widthWidth of the window.
heightHeight of the window.

◆ consoleUpdate()

void consoleUpdate ( PrintConsole console)

Updates the console, submitting a new frame to the display.

Parameters
consoleA pointer to the console data to initialize (if it's NULL, the default console will be used).
Remarks
This function should be called periodically. Failure to call this function will result in lack of screen updating.