2 * Copyright 2005 Timo Hirvonen
10 struct cmdline cmdline
;
12 void cmdline_init(void)
19 cmdline
.line
= xnew(char, cmdline
.size
);
23 void cmdline_insert_ch(uchar ch
)
27 size
= u_char_size(ch
);
28 if (cmdline
.blen
+ size
> cmdline
.size
) {
30 cmdline
.line
= xrenew(char, cmdline
.line
, cmdline
.size
);
32 memmove(cmdline
.line
+ cmdline
.bpos
+ size
,
33 cmdline
.line
+ cmdline
.bpos
,
34 cmdline
.blen
- cmdline
.bpos
+ 1);
35 u_set_char_raw(cmdline
.line
, &cmdline
.bpos
, ch
);
41 void cmdline_backspace(void)
45 if (cmdline
.bpos
== 0)
49 u_prev_char_pos(cmdline
.line
, &bpos
);
50 size
= cmdline
.bpos
- bpos
;
52 memmove(cmdline
.line
+ bpos
,
53 cmdline
.line
+ cmdline
.bpos
,
54 cmdline
.blen
- cmdline
.bpos
+ 1);
61 void cmdline_backspace_to_bol(void)
67 void cmdline_delete_ch(void)
72 if (cmdline
.bpos
== cmdline
.blen
)
75 u_get_char(cmdline
.line
, &bpos
, &ch
);
76 size
= u_char_size(ch
);
79 memmove(cmdline
.line
+ cmdline
.bpos
,
80 cmdline
.line
+ cmdline
.bpos
+ size
,
81 cmdline
.blen
- cmdline
.bpos
+ 1);
84 void cmdline_set_text(const char *text
)
86 int len
= strlen(text
);
88 if (len
>= cmdline
.size
) {
89 while (len
>= cmdline
.size
)
91 cmdline
.line
= xrenew(char, cmdline
.line
, cmdline
.size
);
93 memcpy(cmdline
.line
, text
, len
+ 1);
94 cmdline
.cpos
= u_strlen(cmdline
.line
);
96 cmdline
.clen
= cmdline
.cpos
;
100 void cmdline_clear(void)
109 void cmdline_clear_end(void)
111 cmdline
.line
[cmdline
.bpos
] = 0;
113 cmdline
.clen
= u_strlen(cmdline
.line
);
114 cmdline
.blen
= strlen(cmdline
.line
);
117 void cmdline_move_left(void)
119 if (cmdline
.bpos
> 0) {
121 u_prev_char_pos(cmdline
.line
, &cmdline
.bpos
);
125 void cmdline_move_right(void)
127 if (cmdline
.bpos
< cmdline
.blen
) {
130 u_get_char(cmdline
.line
, &cmdline
.bpos
, &ch
);
135 void cmdline_move_home(void)
141 void cmdline_move_end(void)
143 cmdline
.cpos
= cmdline
.clen
;
144 cmdline
.bpos
= cmdline
.blen
;