Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
/**
|
|
|
|
* (C) Copyright Collin J. Doering 2015
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-10-15 05:23:11 +00:00
|
|
|
* @file ansi_escapes.h
|
|
|
|
* @author Collin J. Doering <collin.doering@rekahsoft.ca>
|
|
|
|
* @date Oct 9, 2015
|
|
|
|
* @brief Macros to ease writing ANSI escapes.
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
*/
|
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define CSI "\e[" ///< Control Sequence Introducer
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define CUU(n) CSI #n "A" ///< Cursor up
|
|
|
|
#define CUD(n) CSI #n "B" ///< Cursor down
|
|
|
|
#define CUF(n) CSI #n "C" ///< Cursor forward
|
|
|
|
#define CUB(n) CSI #n "D" ///< Cursor backward
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define CNL(n) CSI #n "E" ///< Cursor next line
|
|
|
|
#define CPL(n) CSI #n "F" ///< Cursor previous line
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define CHA(n) CSI #n "G" ///< Cursor horizontal absolute
|
|
|
|
#define CUP(n,m) CSI #n ";" #m "H" ///< Cursor position
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define ED(n) CSI #n "J" ///< Erase display
|
|
|
|
#define EL(n) CSI #n "K" ///< Erase in line
|
|
|
|
#define SU(n) CSI #n "S" ///< Scroll up
|
|
|
|
#define SD(n) CSI #n "T" ///< Scroll down
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define HVP(n,m) CSI #n ";" #m "f" ///< Horizontal and vertical position
|
2015-10-15 04:27:19 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
// #define SGR(n,m) CSI #n #m ///< Select graphic rendition
|
2015-10-15 04:27:19 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define AUX_ON CSI "5i" ///< AUX port on
|
|
|
|
#define AUX_OFF CSI "4i" ///< AUX port off
|
2015-10-15 04:27:19 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
// #define DSR CSI "6 n" ///< Device status report
|
2015-10-15 04:27:19 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define SCP CSI "s" ///< Save cursor position
|
|
|
|
#define RCP CSI "u" ///< Restore cursor position
|
2015-10-15 04:27:19 +00:00
|
|
|
|
2015-10-15 05:23:11 +00:00
|
|
|
#define HIDE_CURSOR CSI "?25l" ///< DECTCEM: hide cursor
|
|
|
|
#define SHOW_CURSOR CSI "?25h" ///< DECTCEM: show cursor
|