File: GnuReadLine.cs

package info (click to toggle)
mono-debugger 0.60%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,556 kB
  • ctags: 22,787
  • sloc: ansic: 99,407; cs: 42,429; sh: 9,192; makefile: 376
file content (98 lines) | stat: -rw-r--r-- 2,698 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
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Mono.Debugger.Frontend
{
	public delegate void CompletionDelegate (string text, int start, int end);
	public delegate string CompletionGenerator (string text, int state);

	internal class GnuReadLine
	{
		[DllImport("libmonodebuggerreadline")]
		extern static void mono_debugger_readline_static_init ();

		[DllImport("libmonodebuggerreadline")]
		extern static int mono_debugger_readline_is_a_tty (int fd);

		[DllImport("libmonodebuggerreadline")]
		extern static string mono_debugger_readline_readline (string prompt);

		[DllImport("libmonodebuggerreadline")]
		extern static void mono_debugger_readline_add_history (string line);

		[DllImport("libmonodebuggerreadline")]
		extern static void mono_debugger_readline_enable_completion (Delegate handler);

		[DllImport("libmonodebuggerreadline")]
		extern static string mono_debugger_readline_current_line_buffer ();

		[DllImport("libmonodebuggerreadline")]
		extern static int mono_debugger_readline_get_columns ();

		[DllImport("libmonodebuggerreadline")]
		extern static void mono_debugger_readline_set_completion_matches (string[] matches, int count);

		[DllImport("libmonodebuggerreadline")]
		extern static int mono_debugger_readline_get_filename_completion_desired ();

		[DllImport("libmonodebuggerreadline")]
		extern static void mono_debugger_readline_set_filename_completion_desired (int v);

		static CompletionDelegate completion_handler;

		static GnuReadLine ()
		{
			mono_debugger_readline_static_init ();
		}

		public static bool IsTerminal (int fd)
		{
			return mono_debugger_readline_is_a_tty (fd) != 0;
		}

		public static string ReadLine (string prompt)
		{
			return mono_debugger_readline_readline (prompt);
		}

		public static void AddHistory (string line)
		{
			mono_debugger_readline_add_history (line);
		}

		public static int Columns {
			get {
				return mono_debugger_readline_get_columns ();
			}
		}

		public static void SetCompletionMatches (string[] matches)
		{
			mono_debugger_readline_set_completion_matches (matches, matches == null ? 0 : matches.Length);
		}

		public static void EnableCompletion (CompletionDelegate handler)
		{
			completion_handler = handler;
			mono_debugger_readline_enable_completion (completion_handler);
		}

		public static string CurrentLine
		{
			get {
				return mono_debugger_readline_current_line_buffer ();
			}
		}

		public static bool FilenameCompletionDesired
		{
			get {
				return mono_debugger_readline_get_filename_completion_desired () == 0 ? false : true;
			}
			set {
				mono_debugger_readline_set_filename_completion_desired (value == true ? 1 : 0);
			}
		}
	}
}