Browse Source

- separated curses.c out into separate source files to optimise

library use later on
- some small mods to existing functions
tags/v0.9.3
Dan Lynch 18 years ago
parent
commit
ad1aca0634

+ 12
- 0
src/hci/mucurses/alert.c View File

@@ -0,0 +1,12 @@
1
+#include <curses.h>
2
+#include <vsprintf.h>
3
+
4
+/**
5
+ * Audible signal
6
+ *
7
+ * @ret rc	return status code
8
+ */
9
+int beep ( void ) {
10
+	printf("\a");
11
+	return OK;
12
+}

+ 51
- 0
src/hci/mucurses/clear.c View File

@@ -0,0 +1,51 @@
1
+#include <curses.h>
2
+#include "core.h"
3
+#include "cursor.h"
4
+
5
+/**
6
+ * Clear a window to the bottom from current cursor position
7
+ *
8
+ * @v *win	subject window
9
+ * @ret rc	return status code
10
+ */
11
+int wclrtobot ( WINDOW *win ) {
12
+	struct cursor_pos pos;
13
+
14
+	_store_curs_pos( win, &pos );
15
+	do {
16
+		_wputch( win, (unsigned)' ', WRAP );
17
+	} while ( win->curs_y + win->curs_x );
18
+	_restore_curs_pos( win, &pos );
19
+
20
+	return OK;
21
+}
22
+
23
+/**
24
+ * Clear a window to the end of the current line
25
+ *
26
+ * @v *win	subject window
27
+ * @ret rc	return status code
28
+ */
29
+int wclrtoeol ( WINDOW *win ) {
30
+	struct cursor_pos pos;
31
+
32
+	_store_curs_pos( win, &pos );
33
+	while ( ( win->curs_y - pos.y ) == 0 ) {
34
+		_wputch( win, (unsigned)' ', WRAP );
35
+	}
36
+	_restore_curs_pos( win, &pos );
37
+
38
+	return OK;
39
+}
40
+
41
+/**
42
+ * Completely clear a window
43
+ *
44
+ * @v *win	subject window
45
+ * @ret rc	return status code
46
+ */
47
+int werase ( WINDOW *win ) {
48
+	wmove( win, 0, 0 );
49
+	wclrtobot( win );
50
+	return OK;
51
+}

+ 50
- 0
src/hci/mucurses/colour.c View File

@@ -0,0 +1,50 @@
1
+#include <curses.h>
2
+
3
+/**
4
+ * Indicates whether the underlying terminal device is capable of
5
+ * having colours redefined
6
+ *
7
+ * @ret bool	returns boolean
8
+ */
9
+bool can_change_colour ( void ) {
10
+	return (bool)TRUE;
11
+}
12
+
13
+/**
14
+ * Identify the RGB components of a given colour value
15
+ *
16
+ * @v colour	colour value
17
+ * @v *red	address to store red component
18
+ * @v *green	address to store green component
19
+ * @v *blue	address to store blue component
20
+ * @ret rc	return status code
21
+ */
22
+int colour_content ( short colour, short *red, short *green, short *blue ) {
23
+	/* we do not have a particularly large range of colours (3
24
+	   primary, 3 secondary and black), so let's just put in a
25
+	   basic switch... */
26
+	switch(colour) {
27
+	case COLOUR_BLACK:
28
+		*red = 0; *green = 0; *blue = 0;
29
+		break;
30
+	case COLOUR_BLUE:
31
+		*red = 0; *green = 0; *blue = 1000;
32
+		break;
33
+	case COLOUR_GREEN:
34
+		*red = 0; *green = 1000; *blue = 0;
35
+		break;
36
+	case COLOUR_CYAN:
37
+		*red = 0; *green = 1000; *blue = 1000;
38
+		break;
39
+	case COLOUR_RED:
40
+		*red = 1000; *green = 0; *blue = 0;
41
+		break;
42
+	case COLOUR_MAGENTA:
43
+		*red = 1000; *green = 0; *blue = 1000;
44
+		break;
45
+	case COLOUR_YELLOW:
46
+		*red = 1000; *green = 1000; *blue = 0;
47
+		break;
48
+	}
49
+	return OK;
50
+}

+ 95
- 0
src/hci/mucurses/core.c View File

@@ -0,0 +1,95 @@
1
+#include <curses.h>
2
+#include "core.h"
3
+
4
+WINDOW _stdscr = {
5
+	.attrs = A_DEFAULT,
6
+	.ori_y = 0,
7
+	.ori_x = 0,
8
+	.curs_y = 0,
9
+	.curs_x = 0,
10
+	.scr = curscr,
11
+};
12
+
13
+struct _softlabelkeys *slks;
14
+
15
+/*
16
+ *  Primitives
17
+ */
18
+
19
+/**
20
+ * Write a single character rendition to a window
21
+ *
22
+ * @v *win	window in which to write
23
+ * @v ch	character rendition to write
24
+ * @v wrap	wrap "switch"
25
+ */
26
+void _wputch ( WINDOW *win, chtype ch, int wrap ) {
27
+	/* make sure we set the screen cursor to the right position
28
+	   first! */
29
+	win->scr->movetoyx( win->scr, win->ori_y + win->curs_y,
30
+				      win->ori_x + win->curs_x );
31
+	win->scr->putc(win->scr, ch);
32
+	if ( ++(win->curs_x) == win->width ) {
33
+		if ( wrap == WRAP ) {
34
+			win->curs_x = 0;
35
+			/* specification says we should really scroll,
36
+			   but we have no buffer to scroll with, so we
37
+			   can only overwrite back at the beginning of
38
+			   the window */
39
+			if ( ++(win->curs_y) == win->height )
40
+				win->curs_y = 0;
41
+		} else {
42
+			(win->curs_x)--;
43
+		}
44
+	}
45
+}
46
+
47
+/**
48
+ * Write a chtype string to a window
49
+ *
50
+ * @v *win	window in which to write
51
+ * @v *chstr	chtype string
52
+ * @v wrap	wrap "switch"
53
+ * @v n		write at most n chtypes
54
+ */
55
+void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n ) {
56
+	for ( ; *chstr && n-- ; chstr++ ) {
57
+		_wputch(win,*chstr,wrap);
58
+	}
59
+}
60
+
61
+/**
62
+ * Write a standard c-style string to a window
63
+ *
64
+ * @v *win	window in which to write
65
+ * @v *str	string
66
+ * @v wrap	wrap "switch"
67
+ * @v n		write at most n chars from *str
68
+ */
69
+void _wputstr ( WINDOW *win, const char *str, int wrap, int n ) {
70
+	for ( ; *str && n-- ; str++ ) {
71
+		_wputch( win, *str | win->attrs, wrap );
72
+	}
73
+}
74
+
75
+/**
76
+ * Move a window's cursor to the specified position
77
+ *
78
+ * @v *win	window to be operated on
79
+ * @v y		Y position
80
+ * @v x		X position
81
+ * @ret rc	return status code
82
+ */
83
+int wmove ( WINDOW *win, int y, int x ) {
84
+	/* chech for out-of-bounds errors */
85
+	if ( ( ( (unsigned)x - win->ori_x ) > win->width ) ||
86
+	     ( ( (unsigned)y - win->ori_y ) > win->height ) ) {
87
+		return ERR;
88
+	}
89
+
90
+	win->curs_y = y;
91
+	win->curs_x = x;
92
+	win->scr->movetoyx( win->scr, win->ori_y + win->curs_y, 
93
+			    	      win->ori_x + win->curs_x );
94
+	return OK;
95
+}

+ 39
- 0
src/hci/mucurses/core.h View File

@@ -0,0 +1,39 @@
1
+#ifndef CORE_H
2
+#define CORE_H
3
+
4
+#define WRAP 0
5
+#define NOWRAP 1
6
+
7
+unsigned short _COLS;
8
+unsigned short _LINES;
9
+unsigned short _COLOURS;
10
+unsigned int *_COLOUR_PAIRS; /* basically this is an array, but as its
11
+			       length is determined only when initscr
12
+			       is run, I can only think to make it a
13
+			       pointer and malloc the array into being
14
+			       ... */
15
+
16
+struct _softlabel {
17
+	// label string
18
+	char *label;
19
+	/* Format of soft label 
20
+	   0: left justify
21
+	   1: centre justify
22
+	   2: right justify
23
+	 */
24
+	unsigned short fmt;
25
+};
26
+
27
+struct _softlabelkeys {
28
+	struct _softlabel fkeys[12];
29
+	attr_t attrs;
30
+	unsigned short fmt;
31
+	unsigned short maxlablen;
32
+};
33
+
34
+void _wputch ( WINDOW *win, chtype ch, int wrap );
35
+void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n );
36
+void _wputstr ( WINDOW *win, const char *str, int wrap, int n );
37
+int wmove ( WINDOW *win, int y, int x );
38
+
39
+#endif /* CURSES_H */

+ 25
- 0
src/hci/mucurses/cursor.c View File

@@ -0,0 +1,25 @@
1
+#include <curses.h>
2
+#include "cursor.h"
3
+
4
+/**
5
+ * Restore cursor position from encoded backup variable
6
+ *
7
+ * @v *win	window on which to operate
8
+ * @v *pos	pointer to struct in which original cursor position is stored
9
+ */
10
+void _restore_curs_pos ( WINDOW *win, struct cursor_pos *pos ) {
11
+	win->curs_y = pos->y;
12
+	win->curs_x = pos->x;
13
+	win->scr->movetoyx ( win->scr, win->curs_y, win->curs_x );
14
+}
15
+
16
+/**
17
+ * Store cursor position for later restoration
18
+ *
19
+ * @v *win	window on which to operate
20
+ * @v *pos	pointer to struct in which to store cursor position
21
+ */
22
+void _store_curs_pos ( WINDOW *win, struct cursor_pos *pos ) {
23
+	pos->y = win->curs_y;
24
+	pos->x = win->curs_x;
25
+}

+ 11
- 0
src/hci/mucurses/cursor.h View File

@@ -0,0 +1,11 @@
1
+#ifndef CURSOR_H
2
+#define CURSOR_H
3
+
4
+struct cursor_pos {
5
+	unsigned int y, x;
6
+};
7
+
8
+void _restore_curs_pos ( WINDOW *win, struct cursor_pos *pos );
9
+void _store_curs_pos ( WINDOW *win, struct cursor_pos *pos );
10
+
11
+#endif /* CURSOR_H */

+ 105
- 0
src/hci/mucurses/edging.c View File

@@ -0,0 +1,105 @@
1
+#include <curses.h>
2
+#include "core.h"
3
+#include "cursor.h"
4
+
5
+/**
6
+ * Draw borders from single-byte characters and renditions around a
7
+ * window
8
+ *
9
+ * @v *win	window to be bordered
10
+ * @v verch	vertical chtype
11
+ * @v horch	horizontal chtype
12
+ * @ret rc	return status code
13
+ */
14
+int box ( WINDOW *win, chtype verch, chtype horch ) {
15
+	chtype corner = '+' | win->attrs; /* default corner character */
16
+	return wborder( win, verch, verch, horch, horch,
17
+			corner, corner, corner, corner );
18
+}
19
+
20
+/**
21
+ * Draw borders from single-byte characters and renditions around a
22
+ * window
23
+ *
24
+ * @v *win	window to be bordered
25
+ * @v ls	left side
26
+ * @v rs	right side
27
+ * @v ts	top
28
+ * @v bs	bottom
29
+ * @v tl	top left corner
30
+ * @v tr	top right corner
31
+ * @v bl	bottom left corner
32
+ * @v br	bottom right corner
33
+ * @ret rc	return status code
34
+ */
35
+int wborder ( WINDOW *win, chtype ls, chtype rs,
36
+	      chtype ts, chtype bs, chtype tl,
37
+	      chtype tr, chtype bl, chtype br ) {
38
+	struct cursor_pos pos;
39
+
40
+	_store_curs_pos( win, &pos );
41
+	wmove(win,0,0);
42
+
43
+	_wputch(win,tl,WRAP);
44
+	while ( ( win->width - 1 ) - win->curs_x ) {
45
+		_wputch(win,ts,WRAP);
46
+	}
47
+	_wputch(win,tr,WRAP);
48
+
49
+	while ( ( win->height - 1 ) - win->curs_y ) {
50
+		_wputch(win,ls,WRAP);
51
+		wmove(win,win->curs_y,(win->width)-1);
52
+		_wputch(win,rs,WRAP);
53
+	}
54
+
55
+	_wputch(win,bl,WRAP);
56
+	while ( ( win->width -1 ) - win->curs_x ) {
57
+		_wputch(win,bs,WRAP);
58
+	}
59
+	_wputch(win,br,NOWRAP); /* do not wrap last char to leave
60
+				   cursor in last position */
61
+	_restore_curs_pos( win, &pos );
62
+
63
+	return OK;
64
+}
65
+
66
+/**
67
+ * Create a horizontal line in a window
68
+ *
69
+ * @v *win	subject window
70
+ * @v ch	rendition and character
71
+ * @v n		max number of chars (wide) to render
72
+ * @ret rc	return status code
73
+ */
74
+int whline ( WINDOW *win, chtype ch, int n ) {
75
+	struct cursor_pos pos;
76
+
77
+	_store_curs_pos ( win, &pos );
78
+	while ( ( win->curs_x - win->width ) && n-- ) {
79
+		_wputch ( win, ch, NOWRAP );
80
+	}
81
+	_restore_curs_pos ( win, &pos );
82
+
83
+	return OK;
84
+}
85
+
86
+/**
87
+ * Create a vertical line in a window
88
+ *
89
+ * @v *win	subject window
90
+ * @v ch	rendition and character
91
+ * @v n		max number of lines to render
92
+ * @ret rc	return status code
93
+ */
94
+int wvline ( WINDOW *win, chtype ch, int n ) {
95
+	struct cursor_pos pos;
96
+
97
+	_store_curs_pos ( win, &pos );
98
+	while ( ( win->curs_y - win->height ) && n-- ) {
99
+		_wputch ( win, ch, NOWRAP );
100
+		wmove( win, ++(win->curs_y), pos.x);
101
+	}
102
+	_restore_curs_pos ( win, &pos );
103
+
104
+	return OK;
105
+}

+ 52
- 0
src/hci/mucurses/print.c View File

@@ -0,0 +1,52 @@
1
+#include <curses.h>
2
+#include <vsprintf.h>
3
+#include <stddef.h>
4
+#include "core.h"
5
+
6
+static printw_context {
7
+	struct printf_context ctx;
8
+	WINDOW *win;
9
+};
10
+
11
+static void _printw_handler ( struct printf_context *ctx, unsigned int c ) {
12
+	struct printw_context *wctx =
13
+		container_of ( ctx, struct printw_context, ctx );
14
+
15
+	_wputch( wctx->win, c | wctx->win->attrs, WRAP );
16
+}
17
+
18
+/**
19
+ * Print formatted output in a window
20
+ *
21
+ * @v *win	subject window
22
+ * @v *fmt	formatted string
23
+ * @v varglist	argument list
24
+ * @ret rc	return status code
25
+ */
26
+int vw_printw ( WINDOW *win, const char *fmt, va_list varglist ) {
27
+	struct printw_context wctx = {
28
+		.win = win,
29
+		.ctx = { .handler = _printw_handler, },
30
+	};
31
+
32
+	vcprintf ( &(wctx.ctx), fmt, varglist );
33
+	return OK;
34
+}
35
+
36
+/**
37
+ * Print formatted output to a window
38
+ *
39
+ * @v *win	subject window
40
+ * @v *fmt	formatted string
41
+ * @v ...	string arguments
42
+ * @ret rc	return status code
43
+ */
44
+int wprintw ( WINDOW *win, const char *fmt, ... ) {
45
+	va_list args;
46
+	int i;
47
+
48
+	va_start ( args, fmt );
49
+	i = vw_printw ( win, fmt, args );
50
+	va_end ( args );
51
+	return i;
52
+}

+ 179
- 0
src/hci/mucurses/slk.c View File

@@ -0,0 +1,179 @@
1
+#include <curses.h>
2
+#include <stddef.h>
3
+#include <malloc.h>
4
+#include <string.h>
5
+#include "core.h"
6
+
7
+extern struct _softlabelkeys *slks;
8
+
9
+/**
10
+ * Return the attribute used for the soft function keys
11
+ *
12
+ * @ret attrs	the current attributes of the soft function keys
13
+ */
14
+attr_t slk_attr ( void ) {
15
+	return ( slks == NULL ? 0 : slks->attrs );
16
+}
17
+
18
+/**
19
+ * Turn off soft function key attributes
20
+ *
21
+ * @v attrs	attribute bit mask
22
+ * @ret rc	return status code
23
+ */
24
+int slk_attroff ( const chtype attrs ) {
25
+	if ( slks == NULL ) 
26
+		return ERR;
27
+	slks->attrs &= ~( attrs & A_ATTRIBUTES );
28
+	return OK;
29
+}
30
+
31
+/**
32
+ * Turn on soft function key attributes
33
+ *
34
+ * @v attrs	attribute bit mask
35
+ * @ret rc	return status code
36
+ */
37
+int slk_attron ( const chtype attrs ) {
38
+	if ( slks == NULL )
39
+		return ERR;
40
+	slks->attrs |= ( attrs & A_ATTRIBUTES );
41
+	return OK;
42
+}
43
+
44
+/**
45
+ * Set soft function key attributes
46
+ *
47
+ * @v attrs	attribute bit mask
48
+ * @ret rc	return status code
49
+ */
50
+int slk_attrset ( const chtype attrs ) {
51
+	if ( slks == NULL ) 
52
+		return ERR;
53
+	slks->attrs = ( attrs & A_ATTRIBUTES );
54
+	return OK;
55
+}
56
+
57
+/**
58
+ * Turn off soft function key attributes
59
+ *
60
+ * @v attrs	attribute bit mask
61
+ * @v *opts	undefined (for future implementation)
62
+ * @ret rc	return status code
63
+ */
64
+int slk_attr_off ( const attr_t attrs, void *opts __unused ) {
65
+	return slk_attroff( attrs );
66
+}
67
+
68
+/**
69
+ * Turn on soft function key attributes
70
+ *
71
+ * @v attrs	attribute bit mask
72
+ * @v *opts	undefined (for future implementation)
73
+ * @ret rc	return status code
74
+ */
75
+int slk_attr_on ( attr_t attrs, void *opts __unused ) {
76
+	return slk_attron( attrs );
77
+}
78
+
79
+/**
80
+ * Set soft function key attributes
81
+ *
82
+ * @v attrs			attribute bit mask
83
+ * @v colour_pair_number	colour pair integer
84
+ * @v *opts			undefined (for future implementation)
85
+ * @ret rc			return status code
86
+ */
87
+int slk_attr_set ( const attr_t attrs, short colour_pair_number,
88
+		   void *opts __unused ) {
89
+	if ( slks == NULL ) 
90
+		return ERR;
91
+
92
+	if ( ( unsigned short )colour_pair_number > COLORS )
93
+		return ERR;
94
+
95
+	slks->attrs = ( (unsigned short)colour_pair_number << CPAIR_SHIFT ) |
96
+		( attrs & A_ATTRIBUTES );
97
+	return OK;
98
+}
99
+
100
+/**
101
+ * Clear the soft function key labels from the screen
102
+ *
103
+ * @ret rc	return status code
104
+ */
105
+int slk_clear ( void ) {
106
+	if ( slks == NULL )
107
+		return ERR;
108
+
109
+	wmove(stdscr,stdscr->height-1,0);
110
+	wclrtoeol(stdscr);
111
+	return 0;
112
+}
113
+
114
+/**
115
+ * Initialise the soft function keys
116
+ *
117
+ * @v fmt	format of keys
118
+ * @ret rc	return status code
119
+ */
120
+int slk_init ( int fmt ) {
121
+	if ( (unsigned)fmt > 3 ) {
122
+		return ERR;
123
+	}
124
+
125
+	slks = malloc(sizeof(struct _softlabelkeys));
126
+	slks->attrs = A_DEFAULT;
127
+	slks->fmt = (unsigned short)fmt;
128
+	slks->maxlablen = 5;
129
+	return OK;
130
+}
131
+
132
+/**
133
+ * Return the label for the specified soft key
134
+ *
135
+ * @v labnum	soft key identifier
136
+ * @ret label	return label
137
+ */
138
+char* slk_label ( int labnum ) {
139
+	if ( slks == NULL ) 
140
+		return NULL;
141
+
142
+	return slks->fkeys[labnum].label;
143
+}
144
+
145
+/**
146
+ * Restore soft function key labels to the screen
147
+ *
148
+ * @ret rc	return status code
149
+ */
150
+int slk_restore ( void ) {
151
+	if ( slks == NULL ) 
152
+		return ERR;
153
+
154
+	return OK;
155
+}
156
+
157
+/**
158
+ * Configure specified soft key
159
+ *
160
+ * @v labnum	soft label position to configure
161
+ * @v *label	string to use as soft key label
162
+ * @v fmt	justification format of label
163
+ * @ret rc	return status code
164
+ */
165
+int slk_set ( int labnum, const char *label, int fmt ) {
166
+	if ( slks == NULL ) 
167
+		return ERR;
168
+	if ( (unsigned short)labnum > 12 )
169
+		return ERR;
170
+	if ( (unsigned short)fmt >= 3 )
171
+		return ERR;
172
+	if ( strlen(label) > slks->maxlablen )
173
+		return ERR;
174
+
175
+	strcpy( slks->fkeys[labnum].label, label );
176
+	slks->fkeys[labnum].fmt = fmt;
177
+
178
+	return OK;
179
+}

+ 115
- 0
src/hci/mucurses/winattrs.c View File

@@ -0,0 +1,115 @@
1
+#include <curses.h>
2
+
3
+/**
4
+ * Turn off attributes in a window
5
+ *
6
+ * @v win	subject window
7
+ * @v attrs	attributes to enable
8
+ * @ret rc	return status code
9
+ */
10
+int wattroff ( WINDOW *win, int attrs ) {
11
+	win->attrs &= ~attrs;
12
+	return OK;
13
+}
14
+
15
+/**
16
+ * Turn on attributes in a window
17
+ *
18
+ * @v win	subject window
19
+ * @v attrs	attributes to enable
20
+ * @ret rc	return status code
21
+ */
22
+int wattron ( WINDOW *win, int attrs ) {
23
+	win->attrs |= attrs;
24
+	return OK;
25
+}
26
+
27
+/**
28
+ * Set attributes in a window
29
+ *
30
+ * @v win	subject window
31
+ * @v attrs	attributes to enable
32
+ * @ret rc	return status code
33
+ */
34
+int wattrset ( WINDOW *win, int attrs ) {
35
+	win->attrs = ( attrs | ( win->attrs & A_COLOR ) );
36
+	return OK;
37
+}
38
+
39
+/**
40
+ * Get attributes and colour pair information
41
+ *
42
+ * @v *win	window to obtain information from
43
+ * @v *attrs	address in which to store attributes
44
+ * @v *pair	address in which to store colour pair
45
+ * @v *opts	undefined (for future implementation)
46
+ * @ret rc	return status cude
47
+ */
48
+int wattr_get ( WINDOW *win, attr_t *attrs, short *pair, 
49
+		void *opts __unused ) {
50
+	*attrs = win->attrs & A_ATTRIBUTES;
51
+	*pair = (short)(( win->attrs & A_COLOR ) >> CPAIR_SHIFT);
52
+	return OK;
53
+}
54
+
55
+/**
56
+ * Turn off attributes in a window
57
+ *
58
+ * @v *win	subject window
59
+ * @v attrs	attributes to toggle
60
+ * @v *opts	undefined (for future implementation)
61
+ * @ret rc	return status code
62
+ */
63
+int wattr_off ( WINDOW *win, attr_t attrs, 
64
+		void *opts __unused ) {
65
+	wattroff( win, attrs );
66
+	return OK;
67
+}
68
+
69
+/**
70
+ * Turn on attributes in a window
71
+ *
72
+ * @v *win	subject window
73
+ * @v attrs	attributes to toggle
74
+ * @v *opts	undefined (for future implementation)
75
+ * @ret rc	return status code
76
+ */
77
+int wattr_on ( WINDOW *win, attr_t attrs, 
78
+	       void *opts __unused ) {
79
+	wattron( win, attrs );
80
+	return OK;
81
+}
82
+
83
+/**
84
+ * Set attributes and colour pair information in a window
85
+ *
86
+ * @v *win	subject window
87
+ * @v attrs	attributes to set
88
+ * @v cpair	colour pair to set
89
+ * @v *opts	undefined (for future implementation)
90
+ * @ret rc	return status code
91
+ */
92
+int wattr_set ( WINDOW *win, attr_t attrs, short cpair, 
93
+		void *opts __unused ) {
94
+	wattrset( win, attrs | ( ( (unsigned short)cpair ) << CPAIR_SHIFT ) );
95
+	return OK;
96
+}
97
+
98
+/**
99
+ * Set colour pair for a window
100
+ *
101
+ * @v *win			subject window
102
+ * @v colour_pair_number	colour pair integer
103
+ * @v *opts			undefined (for future implementation)
104
+ * @ret rc			return status code
105
+ */
106
+int wcolour_set ( WINDOW *win, short colour_pair_number, 
107
+		  void *opts __unused ) {
108
+	if ( ( unsigned short )colour_pair_number > COLORS )
109
+		return ERR;
110
+
111
+	win->attrs = ( (unsigned short)colour_pair_number << CPAIR_SHIFT ) |
112
+		( win->attrs & A_ATTRIBUTES );
113
+	return OK;
114
+}
115
+

+ 20
- 0
src/hci/mucurses/wininit.c View File

@@ -0,0 +1,20 @@
1
+#include <curses.h>
2
+#include <stddef.h>
3
+#include "core.h"
4
+
5
+extern struct _softlabelkeys *slks;
6
+
7
+/**
8
+ * Initialise console environment
9
+ *
10
+ * @ret *win	return pointer to stdscr
11
+ */
12
+WINDOW *initscr ( void ) {
13
+	/* determine console size */
14
+	/* initialise screen */
15
+	stdscr->width = 80;
16
+	stdscr->height = ( slks == NULL ? 25 : 24 );
17
+	/* set previously unknown window attributes */
18
+	/* refresh screen */
19
+	return stdscr;
20
+}

Loading…
Cancel
Save