File: scroller.h

package info (click to toggle)
cgdb 0.6.7-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 3,276 kB
  • sloc: ansic: 17,828; sh: 5,176; exp: 1,019; lex: 611; makefile: 287; yacc: 255; cpp: 10
file content (120 lines) | stat: -rw-r--r-- 3,350 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* scroller.h:
 * -----------
 *
 * A scrolling buffer utility.  Able to add and subtract to the buffer.
 * All routines that would require a screen update will automatically redraw
 * the scroller.  There is no "draw" function.
 */

#ifndef _SCROLLER_H_
#define _SCROLLER_H_

/* Local Includes */
#if HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#if HAVE_CURSES_H
#include <curses.h>
#elif HAVE_NCURSES_CURSES_H
#include <ncurses/curses.h>
#endif /* HAVE_CURSES_H */

/* --------------- */
/* Data Structures */
/* --------------- */

struct scroller {
    char **buffer;              /* The text buffer */
    int length;                 /* Number of lines in buffer */
    struct {
        int r;                  /* Current line (row) number */
        int c;                  /* Current column number */
        int pos;                /* Cursor position in last line */
    } current;
    WINDOW *win;                /* The scoller's own window */
};

/* --------- */
/* Functions */
/* --------- */

/* scr_new: Creates and initializes a new scroller
 * --------
 *
 *   pos_r:   Position on screen -- row
 *   pos_c:   Position on screen -- column
 *   height:  Height of the scroller on the screen (rows)
 *   width:   Width of the scroller on the screen (columns)
 *
 * Return Value: A pointer to a new scroller, or NULL on error.
 */
struct scroller *scr_new(int pos_r, int pos_c, int height, int width);

/* scr_free: Releases the memory allocated by a scroller
 * ---------
 *
 *   scr:  Pointer to the scroller object
 */
void scr_free(struct scroller *scr);

/* scr_up: Move up a number of lines
 * -------
 *
 *   scr:    Pointer to the scroller object
 *   nlines: Number of lines to scroll back; will not scroll past beginning
 */
void scr_up(struct scroller *scr, int nlines);

/* scr_down: Move down a number of lines
 * ---------
 *
 *   scr:    Pointer to the scroller object
 *   nlines: Number of lines to scroll down; will not scroll past end
 */
void scr_down(struct scroller *scr, int nlines);

/* scr_home: Jump to the top line of the buffer
 * ---------
 *
 *   scr:  Pointer to the scroller object
 */
void scr_home(struct scroller *scr);

/* scr_end: Jump to the bottom line of the buffer
 * --------
 *
 *   scr:  Pointer to the scroller object
 */
void scr_end(struct scroller *scr);

/* scr_add:  Append a string to the buffer.
 * --------
 *
 *   scr:  Pointer to the scroller object
 *   buf:  Buffer to append -- \b characters will be treated as backspace!
 */
void scr_add(struct scroller *scr, const char *buf);

/* scr_move: Reposition the buffer on the screen
 * ---------
 *
 *   scr:     Pointer to the scroller object
 *   pos_r:   Position on screen -- row
 *   pos_c:   Position on screen -- column
 *   height:  Height of the scroller on the screen (rows)
 *   width:   Width of the scroller on the screen (columns)
 */
void scr_move(struct scroller *scr,
        int pos_r, int pos_c, int height, int width);

/* scr_refresh: Refreshes the scroller on the screen, in case the caller
 * ------------ damages the screen area where the scroller is written (or,
 *              perhaps the terminal size has changed, and you wish to redraw).
 *
 *   scr:    Pointer to the scroller object
 *   focus:  If the window has focus
 */
void scr_refresh(struct scroller *scr, int focus);

#endif