2016-05-02 13:29:21 +08:00
|
|
|
// Generic output functions.
|
|
|
|
//
|
|
|
|
// Constants for various character classifications. Each character of a command string can be
|
|
|
|
// classified as one of the following types.
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_OUTPUT_H
|
|
|
|
#define FISH_OUTPUT_H
|
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <vector>
|
2016-04-21 14:00:54 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
#include "color.h"
|
2015-07-25 23:14:25 +08:00
|
|
|
#include "common.h"
|
2016-04-21 14:00:54 +08:00
|
|
|
#include "fallback.h" // IWYU pragma: keep
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Constants for various colors as used by the set_color function.
|
|
|
|
enum {
|
2012-11-19 08:30:30 +08:00
|
|
|
FISH_COLOR_BLACK,
|
|
|
|
FISH_COLOR_RED,
|
|
|
|
FISH_COLOR_GREEN,
|
|
|
|
FISH_COLOR_YELLOW,
|
|
|
|
FISH_COLOR_BLUE,
|
|
|
|
FISH_COLOR_MAGENTA,
|
|
|
|
FISH_COLOR_CYAN,
|
|
|
|
FISH_COLOR_WHITE,
|
2016-04-05 07:55:40 +08:00
|
|
|
FISH_COLOR_NORMAL, // the default fg color of the terminal
|
2012-11-19 08:30:30 +08:00
|
|
|
FISH_COLOR_RESET
|
2015-08-11 16:00:05 +08:00
|
|
|
};
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Sets the fg and bg color. May be called as often as you like, since if the new color is the same
|
|
|
|
/// as the previous, nothing will be written. Negative values for set_color will also be ignored.
|
|
|
|
/// Since the terminfo string this function emits can potentially cause the screen to flicker, the
|
|
|
|
/// function takes care to write as little as possible.
|
|
|
|
///
|
|
|
|
/// Possible values for color are any form the FISH_COLOR_* enum and FISH_COLOR_RESET.
|
|
|
|
/// FISH_COLOR_RESET will perform an exit_attribute_mode, even if set_color thinks it is already in
|
|
|
|
/// FISH_COLOR_NORMAL mode.
|
|
|
|
///
|
|
|
|
/// In order to set the color to normal, three terminfo strings may have to be written.
|
|
|
|
///
|
|
|
|
/// - First a string to set the color, such as set_a_foreground. This is needed because otherwise
|
|
|
|
/// the previous strings colors might be removed as well.
|
|
|
|
///
|
|
|
|
/// - After that we write the exit_attribute_mode string to reset all color attributes.
|
|
|
|
///
|
|
|
|
/// - Lastly we may need to write set_a_background or set_a_foreground to set the other half of the
|
|
|
|
/// color pair to what it should be.
|
|
|
|
///
|
|
|
|
/// \param c Foreground color.
|
|
|
|
/// \param c2 Background color.
|
2012-02-12 09:07:56 +08:00
|
|
|
void set_color(rgb_color_t c, rgb_color_t c2);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Write specified multibyte string.
|
2014-05-10 05:37:23 +08:00
|
|
|
void writembs_check(char *mbs, const char *mbs_name, const char *file, long line);
|
|
|
|
#define writembs(mbs) writembs_check((mbs), #mbs, __FILE__, __LINE__)
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Write a wide character using the output method specified using output_set_writer().
|
2012-11-19 08:30:30 +08:00
|
|
|
int writech(wint_t ch);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Write a wide character string to FD 1.
|
2012-11-19 08:30:30 +08:00
|
|
|
void writestr(const wchar_t *str);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Return the internal color code representing the specified color.
|
2012-11-19 08:30:30 +08:00
|
|
|
rgb_color_t parse_color(const wcstring &val, bool is_background);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// This is for writing process notification messages. Has to write to stdout, so clr_eol and such
|
|
|
|
/// functions will work correctly. Not an issue since this function is only used in interactive mode
|
|
|
|
/// anyway.
|
2012-11-19 08:30:30 +08:00
|
|
|
int writeb(tputs_arg_t b);
|
2006-02-16 21:40:25 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Set the function used for writing in move_cursor, writespace and set_color and all other output
|
|
|
|
/// functions in this library. By default, the write call is used to give completely unbuffered
|
|
|
|
/// output to stdout.
|
2012-11-19 08:30:30 +08:00
|
|
|
void output_set_writer(int (*writer)(char));
|
2006-02-16 21:40:25 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Return the current output writer.
|
|
|
|
int (*output_get_writer())(char);
|
2006-10-02 00:02:58 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Sets what colors are supported.
|
|
|
|
enum { color_support_term256 = 1 << 0, color_support_term24bit = 1 << 1 };
|
2014-09-20 06:37:31 +08:00
|
|
|
typedef unsigned int color_support_t;
|
|
|
|
color_support_t output_get_color_support();
|
|
|
|
void output_set_color_support(color_support_t support);
|
2012-02-14 01:52:17 +08:00
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
/// Given a list of rgb_color_t, pick the "best" one, as determined by the color support. Returns
|
|
|
|
/// rgb_color_t::none() if empty.
|
2014-11-10 08:42:35 +08:00
|
|
|
rgb_color_t best_color(const std::vector<rgb_color_t> &colors, color_support_t support);
|
|
|
|
|
2016-05-02 13:29:21 +08:00
|
|
|
// Exported for builtin_set_color's usage only.
|
2014-09-20 09:44:18 +08:00
|
|
|
void write_color(rgb_color_t color, bool is_fg);
|
2013-02-15 07:50:24 +08:00
|
|
|
unsigned char index_for_color(rgb_color_t c);
|
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#endif
|