1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 (** GUI for console. *)
25 module M
= Gui_messages
27 module O
= Gui_options
29 let (!!) = Options.(!!)
31 let max_console_lines = ref 500
32 let line_threshold = 50
36 inherit Gui_console_base.box
() as box
38 val mutable lines
= Fifo.create
()
39 val mutable removed_size
= 0
40 val mutable current_pos
= 0
41 val mutable history
= Fifo.create
()
43 method set_list_bg bg font
=
44 let style = text#misc#
style#copy
in
45 style#set_base
[ (`NORMAL
, bg
)];
47 text#misc#set_style
style
49 method insert_line t
=
50 if Fifo.length lines
> !max_console_lines + line_threshold then begin
51 let (line_pos
, len
) = Fifo.take lines
in
52 let line_pos = line_pos - removed_size
in
54 if n
= 0 then len
else
55 let (_
, addlen
) = Fifo.take lines
in
56 iter (n
-1) (len
+addlen
)
58 let len = iter line_threshold len in
59 text#delete_text ~start
: line_pos ~stop
: (line_pos+len);
60 removed_size
<- removed_size
+ len;
62 let len = String.length t
in
63 Fifo.put lines
(current_pos
, len);
64 current_pos
<- current_pos
+ len;
65 ignore
(text#insert_text t ~pos
: text#length
(* ~pos:0 *) );
72 | s
:: tail
-> self#insert_line
(s ^
"\n"); iter tail
74 iter (String2.split t '
\n'
);
76 text#set_position text#length
79 method on_entry_return
() =
80 match we_command#entry#text
with
83 Gui_com.send
(GuiProto.Command s
);
84 if not
(Fifo.mem history s
) then begin
86 (* we_command#set_item_string (GList.list_item ~label:s ()) s;*)
88 let list = we_command#
list in
89 let strings = Fifo.to_list history
in
91 we_command#disable_activate
();
92 list#clear_items ~start
:0 ~stop
:(-1);
94 let li = GList.list_item ~label
: s
() in
100 (*we_command#set_popdown_strings strings*)
102 we_command#entry#set_text
"";
106 let font = Gdk.Font.load_fontset
"fixed" in
107 let style = text#misc#
style#copy
in
109 text#misc#set_style
style;
111 we_command#set_use_arrows `ALWAYS
;
112 Okey.add we_command#entry
115 self#on_entry_return
;
117 ignore
(wb_clear_console#connect#clicked
119 text#delete_text
0 text#length
;