File: VteTest.cs

package info (click to toggle)
gtk-sharp2 2.8.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 21,208 kB
  • ctags: 5,843
  • sloc: xml: 245,420; cs: 24,183; sh: 8,547; ansic: 2,739; makefile: 1,582; perl: 1,177
file content (107 lines) | stat: -rw-r--r-- 2,857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections;
using Gtk;
using Vte;

class T
{
	private Gtk.Window window;

	static void Main (string[] args)
	{
		new T (args);
	}
	
	T (string[] args)
	{

		Application.Init();
		window = new Gtk.Window("Test for vte widget");
		window.SetDefaultSize(600, 450);
		window.DeleteEvent += new DeleteEventHandler (OnAppDelete);
		
		HBox hbox = new HBox ();
		Terminal term = new Terminal ();
		term.EncodingChanged += new EventHandler (OnEncodingChanged);
		term.CursorBlinks = true;
		term.MouseAutohide = true;
		term.ScrollOnKeystroke = true;
		term.DeleteBinding = TerminalEraseBinding.Auto;
		term.BackspaceBinding = TerminalEraseBinding.Auto;
		term.Encoding = "UTF-8";
		term.FontFromString = "Monospace 12";
		term.TextDeleted += new EventHandler (OnTextDeleted);
		term.ChildExited += new EventHandler (OnChildExited);

		VScrollbar vscroll = new VScrollbar (term.Adjustment);
		hbox.PackStart (term);
		hbox.PackStart (vscroll);

		Gdk.Color white = new Gdk.Color ();
		Gdk.Color.Parse ("white", ref white);
		// FIXME: following line is broken
		//term.ColorBackground = white;

		Gdk.Color black = new Gdk.Color ();
		Gdk.Color.Parse ("black", ref black);
		// FIXME: following line is broken
		//term.ColorForeground = black;
		
		// Create a palette with 0 colors. this could be replaced with
		// a palette of colors with a size of 0, 8, 16, or 24.
		Gdk.Color[] palette = new Gdk.Color[0];
		
		term.SetColors (black, white, palette, palette.Length);
		
		//Console.WriteLine (term.UsingXft);
		//Console.WriteLine (term.Encoding);
		//Console.WriteLine (term.StatusLine);

		string[] argv = Environment.GetCommandLineArgs ();
		// seems to want an array of "variable=value"
		string[] envv = new string [Environment.GetEnvironmentVariables ().Count];
		int i = 0;
		foreach (DictionaryEntry e in Environment.GetEnvironmentVariables ())
		{
			if (e.Key == "" || e.Value == "")
				continue;
			string tmp = String.Format ("{0}={1}", e.Key, e.Value);
			envv[i] = tmp;
			i ++;
		}
		
		int pid = term.ForkCommand (Environment.GetEnvironmentVariable ("SHELL"), argv, envv, Environment.CurrentDirectory, false, true, true);
		Console.WriteLine ("Child pid: {0}", pid);

		window.Add(hbox);
		window.ShowAll();
		Application.Run();
	}

	private void OnTextDeleted (object o, EventArgs args)
	{
		Console.WriteLine ("text deleted");
	}
	
	private void OnEncodingChanged (object o, EventArgs args)
	{
		Console.WriteLine ("encoding changed");
	}
	
	private void OnTextInserted (object o, EventArgs args)
	{
		Console.WriteLine ("text inserted");
	}

	private void OnChildExited (object o, EventArgs args)
	{
		// optionally we could just reset instead of quitting
		Console.WriteLine ("child exited");
		Application.Quit ();
	}
	
	private void OnAppDelete (object o, DeleteEventArgs args)
	{
		Application.Quit ();
	}
}