1 /*@ S-nail - a mail user agent derived from Berkeley Mail. 2 *@ `(un)?colour' commands, and anything working with it. 3 * 4 * Copyright (c) 2014 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>. 5 * SPDX-License-Identifier: ISC 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 #ifndef mx_COLOUR_H 20 #define mx_COLOUR_H 21 22 #include <mx/nail.h> 23 #ifdef mx_HAVE_COLOUR 24 25 #define mx_HEADER 26 #include <su/code-in.h> 27 28 struct mx_colour_env; 29 30 /* Injection, if mx_HAVE_COLOUR */ 31 #define mx_COLOUR(X) X 32 33 /* We do have several contexts of colour IDs; since only one of them can be 34 * active at any given time let's share the value range */ 35 enum mx_colour_ctx{ 36 mx_COLOUR_CTX_SUM, 37 mx_COLOUR_CTX_VIEW, 38 mx_COLOUR_CTX_MLE, 39 mx__COLOUR_CTX_MAX1 40 }; 41 42 enum mx_colour_id{ 43 /* Header summary */ 44 mx_COLOUR_ID_SUM_DOTMARK = 0, 45 mx_COLOUR_ID_SUM_HEADER, 46 mx_COLOUR_ID_SUM_THREAD, 47 48 /* Message display */ 49 mx_COLOUR_ID_VIEW_FROM_ = 0, 50 mx_COLOUR_ID_VIEW_HEADER, 51 mx_COLOUR_ID_VIEW_MSGINFO, 52 mx_COLOUR_ID_VIEW_PARTINFO, 53 54 /* Mailx-Line-Editor */ 55 mx_COLOUR_ID_MLE_POSITION = 0, 56 mx_COLOUR_ID_MLE_PROMPT, 57 mx_COLOUR_ID_MLE_ERROR, 58 59 mx__COLOUR_IDS = mx_COLOUR_ID_VIEW_PARTINFO + 1 60 }; 61 62 /* Some non-string colour precondition constants, let us call them tags */ 63 #define mx_COLOUR_TAG_SUM_DOT R(char*,-2) 64 #define mx_COLOUR_TAG_SUM_OLDER R(char*,-3) 65 66 enum mx_colour_get_flags{ 67 mx_COLOUR_GET_FORCED = 1u<<0, /* Act even if COLOUR_IS_ACTIVE() is false */ 68 mx_COLOUR_PAGER_USED = 1u<<1 /* Assume output goes to pager */ 69 }; 70 71 struct mx_colour_env{ 72 struct mx_colour_env *ce_last; 73 boole ce_enabled; /* Colour enabled on this level */ 74 u8 ce_ctx; /* enum mx_colour_ctx */ 75 u8 ce_ispipe; /* .ce_outfp known to be a pipe */ 76 u8 ce__pad[5]; 77 FILE *ce_outfp; 78 struct a_colour_map *ce_current; /* Active colour or NIL */ 79 }; 80 81 struct mx_colour_pen; 82 83 /* `(un)?colour' */ 84 EXPORT int c_colour(void *v); 85 EXPORT int c_uncolour(void *v); 86 87 /* TODO All the colour (pen etc. ) interfaces below have to vanish. 88 * TODO What we need here is a series of query functions which take context, 89 * TODO like a message* for the _VIEW_ series, and which return a 64-bit 90 * TODO flag carrier which returns font-attributes as well as foreground and 91 * TODO background colours (at least 24-bit each). 92 * TODO And the actual drawing stuff is up to the backend, maybe in termios, 93 * TODO or better termcap, or in ui-str. I do not know */ 94 95 /* An execution context is teared down, and it finds to have a colour stack. 96 * Signals are blocked */ 97 EXPORT void mx_colour_stack_del(struct n_go_data_ctx *gdcp); 98 99 /* We want coloured output (in this autorec memory cycle), pager_used is used 100 * to test whether *colour-pager* is to be inspected, if fp is given, the reset 101 * sequence will be written as necessary by _stack_del() 102 * env_gut() will reset() as necessary if fp is not NIL */ 103 EXPORT void mx_colour_env_create(enum mx_colour_ctx cctx, FILE *fp, 104 boole pager_used); 105 EXPORT void mx_colour_env_gut(void); 106 107 /* Putting anything (for pens: including NIL) resets current state first */ 108 EXPORT void mx_colour_put(enum mx_colour_id cid, char const *ctag); 109 EXPORT void mx_colour_reset(void); 110 111 /* Of course temporary only and may return NIL. Does not affect state! */ 112 EXPORT struct str const *mx_colour_reset_to_str(void); 113 114 /* A pen is bound to its environment and automatically reclaimed; it may be 115 * NULL but that can be used anyway for simplicity. 116 * This includes pen_to_str() -- which doesn't affect state! */ 117 EXPORT struct mx_colour_pen *mx_colour_pen_create(enum mx_colour_id cid, 118 char const *ctag); 119 EXPORT void mx_colour_pen_put(struct mx_colour_pen *self); 120 121 /* Get an escape sequence (or NIL, if self is, or no colour there is) */ 122 EXPORT struct str const *mx_colour_pen_to_str(struct mx_colour_pen *self); 123 124 /* Get terminal reset control sequence (or NIL if no colour there is). 125 * The return value is "volatile" to colour change commands */ 126 EXPORT struct str const *mx_colour_get_reset_cseq(u32 get_flags); 127 128 /* Just get the pen for the given combination, or NIL. 129 * The return value is "volatile" to colour change commands */ 130 EXPORT struct mx_colour_pen *mx_colour_get_pen(u32 get_flags, 131 enum mx_colour_ctx cctx, enum mx_colour_id cid, char const *ctag); 132 133 /* Get terminal control sequence (or NIL, if self is, or no colour there is) */ 134 EXPORT struct str const *mx_colour_pen_get_cseq( 135 struct mx_colour_pen const *self); 136 137 #include <su/code-ou.h> 138 #else 139 # define mx_COLOUR(X) 140 #endif /* mx_HAVE_COLOUR */ 141 #endif /* mx_COLOUR_H */ 142 /* s-it-mode */ 143