Stop sharing requirement_unit_state_ereq().
[freeciv.git] / client / luaconsole_common.c
blobed79e47a90dbfbcbbe9a4bce993f2b7f9c1c7c2f
1 /*****************************************************************************
2 Freeciv - Copyright (C) 2002 - R. Falke
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 *****************************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <stdarg.h>
19 #include <string.h>
21 /* utility */
22 #include "fcintl.h"
23 #include "mem.h"
25 /* common */
26 #include "featured_text.h"
28 /* include */
29 #include "luaconsole_g.h"
31 /* client */
32 #include "luaconsole_common.h"
36 /*****************************************************************************
37 Add a line of text to the output ("chatline") window, like puts() would
38 do it in the console.
39 *****************************************************************************/
40 void luaconsole_append(const struct ft_color color,
41 const char *featured_text)
43 char plain_text[MAX_LEN_MSG];
44 struct text_tag_list *tags;
46 /* Separate the text and the tags. */
47 featured_text_to_plain_text(featured_text, plain_text,
48 sizeof(plain_text), &tags, TRUE);
50 if (ft_color_requested(color)) {
51 /* A color is requested. */
52 struct text_tag *ptag = text_tag_new(TTT_COLOR, 0, FT_OFFSET_UNSET,
53 color);
55 if (ptag) {
56 /* Prepends to the list, to avoid to overwrite inside colors. */
57 text_tag_list_prepend(tags, ptag);
58 } else {
59 log_error("Failed to create a color text tag (fg = %s, bg = %s).",
60 (NULL != color.foreground ? color.foreground : "NULL"),
61 (NULL != color.background ? color.background : "NULL"));
65 real_luaconsole_append(plain_text, tags);
66 text_tag_list_destroy(tags);
69 /*****************************************************************************
70 Add a line of text to the output ("chatline") window. The text is
71 constructed in printf style.
72 *****************************************************************************/
73 void luaconsole_vprintf(const struct ft_color color,
74 const char *format, va_list args)
76 char featured_text[MAX_LEN_MSG];
78 fc_vsnprintf(featured_text, sizeof(featured_text), format, args);
79 luaconsole_append(color, featured_text);
83 /*****************************************************************************
84 Add a line of text to the output ("chatline") window. The text is
85 constructed in printf style.
86 *****************************************************************************/
87 void luaconsole_printf(const struct ft_color color,
88 const char *format, ...)
90 va_list args;
92 va_start(args, format);
93 luaconsole_vprintf(color, format, args);
94 va_end(args);
97 /*****************************************************************************
98 Add a line of text to the output ("chatline") window from server event.
99 *****************************************************************************/
100 void luaconsole_event(const char *plain_text,
101 const struct text_tag_list *tags)
103 real_luaconsole_append(plain_text, tags);
106 /*****************************************************************************
107 Standard welcome message.
108 *****************************************************************************/
109 void luaconsole_welcome_message(void)
111 luaconsole_append(ftc_any, _("This is the Client Lua Console."));