Przeglądaj źródła

2006-02-11 Zoltan Varga <[email protected]>

	* console-io.c (ves_icall_System_ConsoleDriver_GetTtySize): New icall
	to obtain the terminal size using an ioctl.

svn path=/trunk/mono/; revision=56807
Zoltan Varga 20 lat temu
rodzic
commit
f3d586e446

+ 3 - 0
mono/metadata/ChangeLog

@@ -1,5 +1,8 @@
 2006-02-11  Zoltan Varga  <[email protected]>
 
+	* console-io.c (ves_icall_System_ConsoleDriver_GetTtySize): New icall
+	to obtain the terminal size using an ioctl.
+
 	* object.c (mono_nullable_init): Revert this as nullable reference
 	types are not valid.
 	(mono_nullable_box): Ditto.

+ 27 - 0
mono/metadata/console-io.c

@@ -76,6 +76,12 @@ ves_icall_System_ConsoleDriver_TtySetup (MonoString *teardown)
 	return FALSE;
 }
 
+MonoBoolean
+ves_icall_System_ConsoleDriver_GetTtySize (HANDLE handle, gint32 *width, gint32 *height)
+{
+	return FALSE;
+}
+
 #else
 static struct termios initial_attr;
 
@@ -210,5 +216,26 @@ ves_icall_System_ConsoleDriver_TtySetup (MonoString *teardown)
 
 	return TRUE;
 }
+
+MonoBoolean
+ves_icall_System_ConsoleDriver_GetTtySize (HANDLE handle, gint32 *width, gint32 *height)
+{
+#ifdef TIOCGWINSZ
+	struct winsize ws;
+	int res;
+
+	res = ioctl (GPOINTER_TO_INT (handle), TIOCGWINSZ, &ws);
+
+	if (!res) {
+		*width = ws.ws_col;
+		*height = ws.ws_row;
+		return TRUE;
+	}
+	else
+		return FALSE;
+#else
+	return FALSE;
 #endif
+}
 
+#endif /* !PLATFORM_WIN32 */

+ 1 - 0
mono/metadata/console-io.h

@@ -23,6 +23,7 @@ gint32 ves_icall_System_ConsoleDriver_InternalKeyAvailable (gint32 timeout);
 MonoBoolean ves_icall_System_ConsoleDriver_SetEcho (MonoBoolean echo);
 MonoBoolean ves_icall_System_ConsoleDriver_SetBreak (MonoBoolean want_break);
 MonoBoolean ves_icall_System_ConsoleDriver_TtySetup (MonoString *teardown);
+MonoBoolean ves_icall_System_ConsoleDriver_GetTtySize (HANDLE handle, gint32 *width, gint32 *height);
 
 G_END_DECLS
 

+ 2 - 0
mono/metadata/icall.c

@@ -5445,6 +5445,7 @@ ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
 
 	utf8_name = mono_string_to_utf8 (name);	/* FIXME: this should be ascii */
 	value = g_getenv (utf8_name);
+
 	g_free (utf8_name);
 
 	if (value == 0)
@@ -6340,6 +6341,7 @@ static const IcallEntry defaultconf_icalls [] = {
 };
 
 static const IcallEntry consoledriver_icalls [] = {
+	{"GetTtySize", ves_icall_System_ConsoleDriver_GetTtySize },
 	{"InternalKeyAvailable", ves_icall_System_ConsoleDriver_InternalKeyAvailable },
 	{"Isatty", ves_icall_System_ConsoleDriver_Isatty },
 	{"SetBreak", ves_icall_System_ConsoleDriver_SetBreak },