~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to kern/term.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
struct grub_term_output *grub_term_outputs;
29
29
struct grub_term_input *grub_term_inputs;
30
30
 
31
 
void (*grub_newline_hook) (void) = NULL;
32
 
 
33
31
/* Put a Unicode character.  */
34
 
void
35
 
grub_putcode (grub_uint32_t code, struct grub_term_output *term)
 
32
static void
 
33
grub_putcode_dumb (grub_uint32_t code,
 
34
                   struct grub_term_output *term)
36
35
{
 
36
  struct grub_unicode_glyph c =
 
37
    {
 
38
      .base = code,
 
39
      .variant = 0,
 
40
      .attributes = 0,
 
41
      .ncomb = 0,
 
42
      .combining = 0,
 
43
      .estimated_width = 1
 
44
    };
 
45
 
37
46
  if (code == '\t' && term->getxy)
38
47
    {
39
48
      int n;
40
49
 
41
 
      n = 8 - ((term->getxy () >> 8) & 7);
 
50
      n = 8 - ((term->getxy (term) >> 8) & 7);
42
51
      while (n--)
43
 
        grub_putcode (' ', term);
 
52
        grub_putcode_dumb (' ', term);
44
53
 
45
54
      return;
46
55
    }
47
56
 
48
 
  (term->putchar) (code);
 
57
  (term->putchar) (term, &c);
49
58
  if (code == '\n')
50
 
    (term->putchar) ('\r');
 
59
    grub_putcode_dumb ('\r', term);
51
60
}
52
61
 
53
 
/* Put a character. C is one byte of a UTF-8 stream.
54
 
   This function gathers bytes until a valid Unicode character is found.  */
55
 
void
56
 
grub_putchar (int c)
 
62
static void
 
63
grub_xputs_dumb (const char *str)
57
64
{
58
 
  static grub_size_t size = 0;
59
 
  static grub_uint8_t buf[6];
60
 
  grub_uint8_t *rest;
61
 
  grub_uint32_t code;
62
 
 
63
 
  buf[size++] = c;
64
 
 
65
 
  while (grub_utf8_to_ucs4 (&code, 1, buf, size, (const grub_uint8_t **) &rest) 
66
 
         != 0)
 
65
  for (; *str; str++)
67
66
    {
68
 
      struct grub_term_output *term;
69
 
      size -= rest - buf;
70
 
      grub_memmove (buf, rest, size);
 
67
      grub_term_output_t term;
 
68
      grub_uint32_t code = *str;
 
69
      if (code > 0x7f)
 
70
        code = '?';
 
71
 
71
72
      FOR_ACTIVE_TERM_OUTPUTS(term)
72
 
        grub_putcode (code, term);
73
 
      if (code == '\n' && grub_newline_hook)
74
 
        grub_newline_hook ();
 
73
        grub_putcode_dumb (code, term);
75
74
    }
76
75
}
77
76
 
 
77
void (*grub_xputs) (const char *str) = grub_xputs_dumb;
 
78
 
78
79
int
79
80
grub_getkey (void)
80
81
{
86
87
    {
87
88
      FOR_ACTIVE_TERM_INPUTS(term)
88
89
      {
89
 
        int key = term->checkkey ();
 
90
        int key = term->checkkey (term);
90
91
        if (key != -1)
91
 
          return term->getkey ();
 
92
          return term->getkey (term);
92
93
      }
93
94
 
94
95
      grub_cpu_idle ();
102
103
 
103
104
  FOR_ACTIVE_TERM_INPUTS(term)
104
105
  {
105
 
    int key = term->checkkey ();
 
106
    int key = term->checkkey (term);
106
107
    if (key != -1)
107
108
      return key;
108
109
  }
119
120
  FOR_ACTIVE_TERM_INPUTS(term)
120
121
  {
121
122
    if (term->getkeystatus)
122
 
      status |= term->getkeystatus ();
 
123
      status |= term->getkeystatus (term);
123
124
  }
124
125
 
125
126
  return status;
126
127
}
127
128
 
128
129
void
129
 
grub_cls (void)
130
 
{
131
 
  struct grub_term_output *term;
132
 
 
133
 
  FOR_ACTIVE_TERM_OUTPUTS(term)  
134
 
  {
135
 
    if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
136
 
      {
137
 
        grub_putcode ('\n', term);
138
 
        grub_term_refresh (term);
139
 
      }
140
 
    else
141
 
      (term->cls) ();
142
 
  }
143
 
}
144
 
 
145
 
void
146
 
grub_setcolorstate (grub_term_color_state state)
147
 
{
148
 
  struct grub_term_output *term;
149
 
  
150
 
  FOR_ACTIVE_TERM_OUTPUTS(term)
151
 
    grub_term_setcolorstate (term, state);
152
 
}
153
 
 
154
 
void
155
130
grub_refresh (void)
156
131
{
157
132
  struct grub_term_output *term;