2 * PUPA -- Preliminary Universal Programming Architecture for GRUB
3 * Copyright (C) 2002 Free Software Foundation, Inc.
4 * Copyright (C) 2002,2003 Yoshinori K. Okuji <okuji@enbug.org>
6 * PUPA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with PUPA; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <pupa/term.h>
25 /* The list of terminals. */
26 static pupa_term_t pupa_term_list
;
28 /* The current terminal. */
29 static pupa_term_t pupa_cur_term
;
32 pupa_term_register (pupa_term_t term
)
34 term
->next
= pupa_term_list
;
35 pupa_term_list
= term
;
39 pupa_term_unregister (pupa_term_t term
)
43 for (p
= &pupa_term_list
, q
= *p
; q
; p
= &(q
->next
), q
= q
->next
)
52 pupa_term_iterate (int (*hook
) (pupa_term_t term
))
56 for (p
= pupa_term_list
; p
; p
= p
->next
)
62 pupa_term_set_current (pupa_term_t term
)
64 if (pupa_cur_term
&& pupa_cur_term
->fini
)
65 if ((pupa_cur_term
->fini
) () != PUPA_ERR_NONE
)
69 if ((term
->init
) () != PUPA_ERR_NONE
)
78 pupa_term_get_current (void)
83 /* Put a Unicode character. */
85 pupa_putcode (pupa_uint32_t code
)
87 if (code
== '\t' && pupa_cur_term
->getxy
)
91 n
= 8 - ((pupa_getxy () >> 8) & 7);
98 (pupa_cur_term
->putchar
) (code
);
104 /* Put a character. C is one byte of a UTF-8 stream.
105 This function gathers bytes until a valid Unicode character is found. */
109 static pupa_uint32_t code
= 0;
110 static int count
= 0;
114 if ((c
& 0xc0) != 0x80)
129 if ((c
& 0x80) == 0x00)
131 else if ((c
& 0xe0) == 0xc0)
136 else if ((c
& 0xf0) == 0xe0)
141 else if ((c
& 0xf8) == 0xf0)
146 else if ((c
& 0xfc) == 0xf8)
151 else if ((c
& 0xfe) == 0xfc)
162 /* Not finished yet. */
171 return (pupa_cur_term
->getkey
) ();
177 return (pupa_cur_term
->checkkey
) ();
183 return (pupa_cur_term
->getxy
) ();
187 pupa_gotoxy (pupa_uint8_t x
, pupa_uint8_t y
)
189 (pupa_cur_term
->gotoxy
) (x
, y
);
195 if (pupa_cur_term
->flags
& PUPA_TERM_DUMB
)
201 (pupa_cur_term
->cls
) ();
205 pupa_setcolorstate (pupa_term_color_state state
)
207 if (pupa_cur_term
->setcolorstate
)
208 (pupa_cur_term
->setcolorstate
) (state
);
212 pupa_setcolor (pupa_uint8_t normal_color
, pupa_uint8_t highlight_color
)
214 if (pupa_cur_term
->setcolor
)
215 (pupa_cur_term
->setcolor
) (normal_color
, highlight_color
);
219 pupa_setcursor (int on
)
224 if (pupa_cur_term
->setcursor
)
226 (pupa_cur_term
->setcursor
) (on
);
236 if (pupa_cur_term
->refresh
)
237 (pupa_cur_term
->refresh
) ();