2 * Copyright 2005 Timo Hirvonen
9 struct cmdline cmdline
;
11 void cmdline_init(void)
18 cmdline
.line
= xnew(char, cmdline
.size
);
22 void cmdline_insert_ch(uchar ch
)
26 size
= u_char_size(ch
);
27 if (cmdline
.blen
+ size
> cmdline
.size
) {
29 cmdline
.line
= xrenew(char, cmdline
.line
, cmdline
.size
);
31 memmove(cmdline
.line
+ cmdline
.bpos
+ size
,
32 cmdline
.line
+ cmdline
.bpos
,
33 cmdline
.blen
- cmdline
.bpos
+ 1);
34 u_set_char_raw(cmdline
.line
, &cmdline
.bpos
, ch
);
40 void cmdline_backspace(void)
44 if (cmdline
.bpos
== 0)
48 u_prev_char_pos(cmdline
.line
, &bpos
);
49 size
= cmdline
.bpos
- bpos
;
51 memmove(cmdline
.line
+ bpos
,
52 cmdline
.line
+ cmdline
.bpos
,
53 cmdline
.blen
- cmdline
.bpos
+ 1);
60 void cmdline_backspace_to_bol(void)
66 void cmdline_delete_ch(void)
71 if (cmdline
.bpos
== cmdline
.blen
)
74 u_get_char(cmdline
.line
, &bpos
, &ch
);
75 size
= u_char_size(ch
);
78 memmove(cmdline
.line
+ cmdline
.bpos
,
79 cmdline
.line
+ cmdline
.bpos
+ size
,
80 cmdline
.blen
- cmdline
.bpos
+ 1);
83 void cmdline_set_text(const char *text
)
85 int len
= strlen(text
);
87 if (len
>= cmdline
.size
) {
88 while (len
>= cmdline
.size
)
90 cmdline
.line
= xrenew(char, cmdline
.line
, cmdline
.size
);
92 memcpy(cmdline
.line
, text
, len
+ 1);
93 cmdline
.cpos
= u_strlen(cmdline
.line
);
95 cmdline
.clen
= cmdline
.cpos
;
99 void cmdline_clear(void)
108 void cmdline_clear_end(void)
110 cmdline
.line
[cmdline
.bpos
] = 0;
112 cmdline
.clen
= u_strlen(cmdline
.line
);
113 cmdline
.blen
= strlen(cmdline
.line
);
116 void cmdline_move_left(void)
118 if (cmdline
.bpos
> 0) {
120 u_prev_char_pos(cmdline
.line
, &cmdline
.bpos
);
124 void cmdline_move_right(void)
126 if (cmdline
.bpos
< cmdline
.blen
) {
129 u_get_char(cmdline
.line
, &cmdline
.bpos
, &ch
);
134 void cmdline_move_home(void)
140 void cmdline_move_end(void)
142 cmdline
.cpos
= cmdline
.clen
;
143 cmdline
.bpos
= cmdline
.blen
;