summaryrefslogtreecommitdiffstats
path: root/src/hci/mucurses/clear.c
blob: 7e124c1d8fedd68ee19f08a3221533c595f153c3 (plain) (blame)
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
#include <curses.h>
#include "core.h"
#include "cursor.h"

/**
 * Clear a window to the bottom from current cursor position
 *
 * @v *win	subject window
 * @ret rc	return status code
 */
int wclrtobot ( WINDOW *win ) {
	struct cursor_pos pos;

	_store_curs_pos( win, &pos );
	do {
		_wputch( win, (unsigned)' ', WRAP );
	} while ( win->curs_y + win->curs_x );
	_restore_curs_pos( win, &pos );

	return OK;
}

/**
 * Clear a window to the end of the current line
 *
 * @v *win	subject window
 * @ret rc	return status code
 */
int wclrtoeol ( WINDOW *win ) {
	struct cursor_pos pos;

	_store_curs_pos( win, &pos );
	while ( ( win->curs_y - pos.y ) == 0 ) {
		_wputch( win, (unsigned)' ', WRAP );
	}
	_restore_curs_pos( win, &pos );

	return OK;
}

/**
 * Completely clear a window
 *
 * @v *win	subject window
 * @ret rc	return status code
 */
int werase ( WINDOW *win ) {
	wmove( win, 0, 0 );
	wclrtobot( win );
	return OK;
}