iPXE
edging.c
Go to the documentation of this file.
1 #include <curses.h>
2 #include "mucurses.h"
3 #include "cursor.h"
4 
5 /** @file
6  *
7  * MuCurses edging functions
8  *
9  */
10 
11 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 
13 /**
14  * Draw borders from single-byte characters and renditions around a
15  * window
16  *
17  * @v *win window to be bordered
18  * @v verch vertical chtype
19  * @v horch horizontal chtype
20  * @ret rc return status code
21  */
22 int box ( WINDOW *win, chtype verch, chtype horch ) {
23  chtype corner = '+' | win->attrs; /* default corner character */
24  return wborder( win, verch, verch, horch, horch,
25  corner, corner, corner, corner );
26 }
27 
28 /**
29  * Draw borders from single-byte characters and renditions around a
30  * window
31  *
32  * @v *win window to be bordered
33  * @v ls left side
34  * @v rs right side
35  * @v ts top
36  * @v bs bottom
37  * @v tl top left corner
38  * @v tr top right corner
39  * @v bl bottom left corner
40  * @v br bottom right corner
41  * @ret rc return status code
42  */
43 int wborder ( WINDOW *win, chtype ls, chtype rs,
44  chtype ts, chtype bs, chtype tl,
45  chtype tr, chtype bl, chtype br ) {
46  struct cursor_pos pos;
47 
48  _store_curs_pos( win, &pos );
49  wmove(win,0,0);
50 
51  _wputch(win,tl,WRAP);
52  while ( ( win->width - 1 ) - win->curs_x ) {
53  _wputch(win,ts,WRAP);
54  }
55  _wputch(win,tr,WRAP);
56 
57  while ( ( win->height - 1 ) - win->curs_y ) {
58  _wputch(win,ls,WRAP);
59  wmove(win,win->curs_y,(win->width)-1);
60  _wputch(win,rs,WRAP);
61  }
62 
63  _wputch(win,bl,WRAP);
64  while ( ( win->width -1 ) - win->curs_x ) {
65  _wputch(win,bs,WRAP);
66  }
67  _wputch(win,br,NOWRAP); /* do not wrap last char to leave
68  cursor in last position */
69  _restore_curs_pos( win, &pos );
70 
71  return OK;
72 }
73 
74 /**
75  * Create a horizontal line in a window
76  *
77  * @v *win subject window
78  * @v ch rendition and character
79  * @v n max number of chars (wide) to render
80  * @ret rc return status code
81  */
82 int whline ( WINDOW *win, chtype ch, int n ) {
83  struct cursor_pos pos;
84 
85  _store_curs_pos ( win, &pos );
86  while ( ( win->curs_x - win->width ) && n-- ) {
87  _wputch ( win, ch, NOWRAP );
88  }
89  _restore_curs_pos ( win, &pos );
90 
91  return OK;
92 }
93 
94 /**
95  * Create a vertical line in a window
96  *
97  * @v *win subject window
98  * @v ch rendition and character
99  * @v n max number of chars (high) to render
100  * @ret rc return status code
101  */
102 int wvline ( WINDOW *win, chtype ch, int n ) {
103  struct cursor_pos pos;
104 
105  _store_curs_pos ( win, &pos );
106  while ( ( win->curs_y - win->height ) && n-- ) {
107  _wputch ( win, ch, NOWRAP );
108  wmove( win, ++(win->curs_y), pos.x);
109  }
110  _restore_curs_pos ( win, &pos );
111 
112  return OK;
113 }
MuCurses header file.
int wmove(WINDOW *win, int y, int x) __nonnull
Move a window's cursor to the specified position.
Definition: mucurses.c:135
int box(WINDOW *win, chtype verch, chtype horch)
Draw borders from single-byte characters and renditions around a window.
Definition: edging.c:22
Curses Window struct.
Definition: curses.h:89
int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
Draw borders from single-byte characters and renditions around a window.
Definition: edging.c:43
MuCurses cursor implementation specific header file.
unsigned int curs_y
Definition: curses.h:97
uint8_t bl
Definition: registers.h:78
unsigned int height
Definition: curses.h:99
unsigned int width
window dimensions
Definition: curses.h:99
MuCurses core implementation specific header file.
Definition: sis900.h:208
uint8_t ch
Definition: registers.h:83
int wvline(WINDOW *win, chtype ch, int n)
Create a vertical line in a window.
Definition: edging.c:102
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define NOWRAP
Definition: mucurses.h:13
attr_t attrs
window attributes
Definition: curses.h:93
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition: mucurses.c:50
int whline(WINDOW *win, chtype ch, int n)
Create a horizontal line in a window.
Definition: edging.c:82
uint32_t chtype
Definition: curses.h:29
unsigned int n
Definition: entropy.h:159
static void _restore_curs_pos(WINDOW *win, struct cursor_pos *pos)
Restore cursor position from encoded backup variable.
Definition: cursor.h:22
unsigned int x
Definition: cursor.h:13
static void _store_curs_pos(WINDOW *win, struct cursor_pos *pos)
Store cursor position for later restoration.
Definition: cursor.h:32
#define WRAP
Definition: mucurses.h:12
unsigned int curs_x
window cursor position
Definition: curses.h:97