rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rtty.h
Go to the documentation of this file.
1/* RLIB - Convenience library for useful things
2 * Copyright (C) 2015 Haakon Sporsheim <haakon.sporsheim@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library.
16 * See the COPYING file at the root of the source repository.
17 */
18#ifndef __R_TTY_H__
19#define __R_TTY_H__
20
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
23#endif
24
31#include <rlib/rtypes.h>
32#include <rlib/rclr.h>
33#include <stdarg.h>
34#include <stdio.h>
35#ifdef R_OS_WIN32
36#include <io.h>
37#else
38#include <unistd.h>
39#endif
40
42
65#define R_TTY_MAX_CC 32
67#define R_TTY_CSI "\x1B["
69#define R_TTY_SGR1(param) R_TTY_CSI param "m"
71#define R_TTY_SGR_RESET R_TTY_SGR1 (R_TTY_SGR_CLS_ARG)
73#define R_TTY_SGR(P1) R_TTY_SGR1 (P1)
75#define R_TTY_SGR2(P1,P2) R_TTY_SGR1 (P1";"P2)
77#define R_TTY_SGR3(P1,P2,P3) R_TTY_SGR1 (P1";"P2";"P3)
79#define R_TTY_SGR4(P1,P2,P3,P4) R_TTY_SGR1 (P1";"P2";"P3";"P4)
80
85#define R_TTY_SGR_CLS_ARG "0"
86#define R_TTY_SGR_BOLD_ARG "1"
87#define R_TTY_SGR_NOBOLD_ARG "21"
88#define R_TTY_SGR_FAINT_ARG "2"
89#define R_TTY_SGR_NORMAL_ARG "22"
90#define R_TTY_SGR_ITALIC_ARG "3"
91#define R_TTY_SGR_NOITALIC_ARG "23"
92#define R_TTY_SGR_UNDERLINE_ARG "4"
93#define R_TTY_SGR_NOUNDERLINE_ARG "24"
94#define R_TTY_SGR_BLINK_ARG "5"
95#define R_TTY_SGR_NOBLINK_ARG "25"
96#define R_TTY_SGR_INVERSE_ARG "7"
97#define R_TTY_SGR_NOINVERSE_ARG "27"
98#define R_TTY_SGR_CONCEAL_ARG "8"
99#define R_TTY_SGR_REVEAL_ARG "28"
101#define R_TTY_SGR_FG_ARG(CLR) "3"R_STRINGIFY (CLR)
103#define R_TTY_SGR_BG_ARG(CLR) "4"R_STRINGIFY (CLR)
113
114#ifdef R_OS_WIN32
116#define r_isatty _isatty
118#define r_fileno _fileno
119#else
120#define r_isatty isatty
121#define r_fileno fileno
122#endif
123
125#define r_printf printf
127#define r_vprintf vprintf
129#define r_fprintf fprintf
131#define r_vfprintf vfprintf
132
137R_API int r_print (const rchar * fmt, ...) R_ATTR_PRINTF (1, 2);
142R_API int r_printerr (const rchar * fmt, ...) R_ATTR_PRINTF (1, 2);
148typedef rboolean (*RPrintFunc) (const rchar * str, rsize size, rpointer data);
166 RPrintFunc * oldfunc, rpointer * olddata);
169 RPrintFunc * oldfunc, rpointer * olddata);
170
175
176R_END_DECLS
177
180#endif /* __R_TTY_H__ */
181
RColorFlags
Combined foreground / background / attribute flags.
Definition rclr.h:77
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
void r_override_print_handler(RPrintFunc func, rpointer data, RPrintFunc *oldfunc, rpointer *olddata)
Install a new sink for r_print.
rboolean r_printerr_default(const rchar *str, rsize size, rpointer data)
Default stderr sink (writes via the C library).
rchar * r_tty_clr_to_str(RColorFlags clr, rchar str[R_TTY_MAX_CC])
Render a colour-flag bitmask into a CSI escape sequence.
rboolean r_print_default(const rchar *str, rsize size, rpointer data)
Default stdout sink (writes via the C library).
rboolean(* RPrintFunc)(const rchar *str, rsize size, rpointer data)
Print-sink signature: receive a chunk of text and decide how to handle it (write to stdio,...
Definition rtty.h:148
int r_printerr(const rchar *fmt,...)
Print to stderr via the currently-installed printerr handler.
void r_override_printerr_handler(RPrintFunc func, rpointer data, RPrintFunc *oldfunc, rpointer *olddata)
Like r_override_print_handler but for r_printerr.
#define R_TTY_MAX_CC
Maximum length of a colour-control escape produced by r_tty_clr_to_str.
Definition rtty.h:65
int r_print(const rchar *fmt,...)
Print to stdout via the currently-installed print handler.
char rchar
Default character type (char).
Definition rtypes.h:137
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
unsigned long rsize
Unsigned pointer-sized size type (like size_t).
Definition rtypes.h:290
ANSI colour and text-attribute bitmask used by r_tty and r_log.
Foundational type aliases used by every rlib header.