Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/luaconsole_common.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
luaconsole_common.c
Go to the documentation of this file.
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.
7
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*****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdarg.h>
19#include <string.h>
20
21/* utility */
22#include "fcintl.h"
23#include "mem.h"
24
25/* common */
26#include "featured_text.h"
27
28/* include */
29#include "luaconsole_g.h"
30
31/* client */
32#include "luaconsole_common.h"
33
34
35
36/*************************************************************************/
40 void luaconsole_append(const struct ft_color color,
41 const char *featured_text)
42{
43 char plain_text[MAX_LEN_MSG];
44 struct text_tag_list *tags;
45
46 /* Separate the text and the tags. */
47 featured_text_to_plain_text(featured_text, plain_text,
48 sizeof(plain_text), &tags, TRUE);
49
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);
54
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"));
62 }
63 }
64
65 real_luaconsole_append(plain_text, tags);
66 text_tag_list_destroy(tags);
67}
68
69/*************************************************************************/
73 void luaconsole_vprintf(const struct ft_color color,
74 const char *format, va_list args)
75{
76 char featured_text[MAX_LEN_MSG];
77
78 fc_vsnprintf(featured_text, sizeof(featured_text), format, args);
79 luaconsole_append(color, featured_text);
80}
81
82
83/*************************************************************************/
87 void luaconsole_printf(const struct ft_color color,
88 const char *format, ...)
89{
90 va_list args;
91
92 va_start(args, format);
93 luaconsole_vprintf(color, format, args);
94 va_end(args);
95}
96
97/*************************************************************************/
100 void luaconsole_event(const char *plain_text,
101 const struct text_tag_list *tags)
102{
103 real_luaconsole_append(plain_text, tags);
104}
105
106/*************************************************************************/
109 void luaconsole_welcome_message(void)
110{
111 luaconsole_append(ftc_any, _("This is the Client Lua Console."));
112}
fcintl.h
_
#define _(String)
Definition fcintl.h:67
featured_text_to_plain_text
size_t featured_text_to_plain_text(const char *featured_text, char *plain_text, size_t plain_text_len, struct text_tag_list **tags, bool replace_link_text)
Definition featured_text.c:864
ftc_any
const struct ft_color ftc_any
Definition featured_text.c:73
text_tag_new
struct text_tag * text_tag_new(enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Definition featured_text.c:638
featured_text.h
FT_OFFSET_UNSET
#define FT_OFFSET_UNSET
Definition featured_text.h:104
ft_color_requested
static bool ft_color_requested(const struct ft_color color)
Definition featured_text.h:160
TTT_COLOR
@ TTT_COLOR
Definition featured_text.h:125
real_luaconsole_append
void real_luaconsole_append(const char *astring, const struct text_tag_list *tags)
Definition luaconsole.c:458
log_error
#define log_error(message,...)
Definition log.h:103
luaconsole_vprintf
void luaconsole_vprintf(const struct ft_color color, const char *format, va_list args)
Definition luaconsole_common.c:73
luaconsole_welcome_message
void luaconsole_welcome_message(void)
Definition luaconsole_common.c:109
luaconsole_event
void luaconsole_event(const char *plain_text, const struct text_tag_list *tags)
Definition luaconsole_common.c:100
luaconsole_append
void luaconsole_append(const struct ft_color color, const char *featured_text)
Definition luaconsole_common.c:40
luaconsole_printf
void luaconsole_printf(const struct ft_color color, const char *format,...)
Definition luaconsole_common.c:87
luaconsole_common.h
luaconsole_g.h
mem.h
MAX_LEN_MSG
#define MAX_LEN_MSG
Definition packets.h:43
color
Definition colors.h:20
ft_color
Definition featured_text.h:141
text_tag
Definition featured_text.c:49
fc_vsnprintf
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:896
TRUE
#define TRUE
Definition support.h:46