1 /*
2  * $Id: MainWindow.cs 192 2007-04-22 11:48:12Z meebey $
3  * $URL: svn+ssh://svn.qnetp.net/svn/smuxi/smuxi/trunk/src/Frontend-GNOME/MainWindow.cs $
4  * $Rev: 192 $
5  * $Author: meebey $
6  * $Date: 2007-04-22 13:48:12 +0200 (Sun, 22 Apr 2007) $
7  *
8  * Smuxi - Smart MUltipleXed Irc
9  *
10  * Copyright (c) 2005-2006 Mirco Bauer <meebey@meebey.net>
11  *
12  * Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
27  */
28 
29 using System;
30 using System.IO;
31 using System.Reflection;
32 using Mono.Unix;
33 using Mono.Terminal;
34 using Smuxi.Common;
35 using Smuxi.Engine;
36 
37 namespace Smuxi.Frontend.Curses
38 {
39     public class LogWidget : Widget {
40     	string [] messages = new string [80];
41     	int head, tail;
42 
LogWidget(int x, int y, int w, int h)43     	public LogWidget (int x, int y, int w, int h) : base (x, y, w, h)
44     	{
45     		//Fill = Fill.Horizontal | Fill.Vertical;
46 			AddText ("Started");
47 		}
48 
AddText(string s)49 		public void AddText (string s)
50 		{
51 			messages [head] = s;
52 			head++;
53 			if (head == messages.Length)
54 				head = 0;
55 			if (head == tail)
56 				tail = (tail+1) % messages.Length;
57 		}
58 
Redraw()59 		public override void Redraw ()
60 		{
61 			Mono.Terminal.Curses.attrset(ColorNormal);
62 
63 			int i = 0;
64 			int l;
65 			int n = head > tail ? head-tail : (head + messages.Length) - tail;
66 			for (l = h-1; l >= 0 && n-- > 0; l--){
67 				int item = head-1-i;
68 				if (item < 0)
69 					item = messages.Length+item;
70 
71 				Move (y+l, x);
72 
73 				int sl = messages [item].Length;
74 				if (sl < w){
75 					Mono.Terminal.Curses.addstr (messages [item]);
76 					for (int fi = 0; fi < w-sl; fi++)
77 						Mono.Terminal.Curses.addch (' ');
78 				} else {
79 					Mono.Terminal.Curses.addstr (messages [item].Substring (0, sl));
80 				}
81 				i++;
82 			}
83 
84 			for (; l >= 0; l--) {
85 				Move (y+l, x);
86 				for (i = 0; i < w; i++)
87 					Mono.Terminal.Curses.addch (' ');
88 			}
89 		}
90 	}
91 }
92