ncmpc  0.29
screen_text.h
Go to the documentation of this file.
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef SCREEN_TEXT_H
21 #define SCREEN_TEXT_H
22 
23 #include "list_window.h"
24 
25 #include <glib.h>
26 
27 struct mpdclient;
28 
29 struct screen_text {
30  GPtrArray *lines;
31 
32  struct list_window *lw;
33 };
34 
35 static inline void
36 screen_text_init(struct screen_text *text, WINDOW *w, unsigned cols, unsigned rows)
37 {
38  text->lines = g_ptr_array_new();
39 
40  text->lw = list_window_init(w, cols, rows);
41  text->lw->hide_cursor = true;
42 }
43 
44 void
45 screen_text_clear(struct screen_text *text);
46 
47 static inline void
48 screen_text_deinit(struct screen_text *text)
49 {
50  screen_text_clear(text);
51  g_ptr_array_free(text->lines, TRUE);
52 
53  list_window_free(text->lw);
54 }
55 
56 static inline void
57 screen_text_resize(struct screen_text *text, unsigned cols, unsigned rows)
58 {
59  list_window_resize(text->lw, cols, rows);
60 }
61 
62 static inline bool
63 screen_text_is_empty(const struct screen_text *text)
64 {
65  return text->lines->len == 0;
66 }
67 
68 void
69 screen_text_append(struct screen_text *text, const char *str);
70 
71 static inline void
72 screen_text_set(struct screen_text *text, const char *str)
73 {
74  screen_text_clear(text);
75  screen_text_append(text, str);
76 }
77 
78 const char *
79 screen_text_list_callback(unsigned idx, void *data);
80 
81 static inline void
82 screen_text_paint(struct screen_text *text)
83 {
85 }
86 
90 static inline void
91 screen_text_repaint(struct screen_text *text)
92 {
93  screen_text_paint(text);
94  wrefresh(text->lw->w);
95 }
96 
97 bool
98 screen_text_cmd(struct screen_text *text, struct mpdclient *c, command_t cmd);
99 
100 #endif
const char * screen_text_list_callback(unsigned idx, void *data)
bool screen_text_cmd(struct screen_text *text, struct mpdclient *c, command_t cmd)
GPtrArray * lines
Definition: screen_text.h:30
void screen_text_append(struct screen_text *text, const char *str)
Definition: mpdclient.h:12
void list_window_paint(const struct list_window *lw, list_window_callback_fn_t callback, void *callback_data)
void screen_text_clear(struct screen_text *text)
command_t
Definition: command.h:36
WINDOW * w
Definition: list_window.h:41
void list_window_free(struct list_window *lw)
unsigned cols
Definition: list_window.h:42
void list_window_resize(struct list_window *lw, unsigned width, unsigned height)
struct list_window * list_window_init(WINDOW *w, unsigned width, unsigned height)
Definition: list_window.h:40
Definition: screen_text.h:29
bool hide_cursor
Definition: list_window.h:62
struct list_window * lw
Definition: screen_text.h:32
unsigned rows
Definition: list_window.h:42