Index: trunk/ab5.0/ablib/src/Classes/System/Console.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/System/Console.ab	(revision 624)
+++ trunk/ab5.0/ablib/src/Classes/System/Console.ab	(revision 627)
@@ -27,4 +27,5 @@
 	Magenta		= FOREGROUND_RED Or FOREGROUND_BLUE Or FOREGROUND_INTENSITY
 End Enum
+
 
 /*
@@ -44,13 +45,12 @@
 			Exit Sub
 		Else
-			Dim h = This.GetStdOutputHandle()
-			If h = NULL Then
+			If Console.hconsoleout = NULL Then
 				Exit Sub
 			Else
 				Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
-				Dim ret = GetConsoleScreenBufferInfo(h,csbi)
+				Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi)
 				If ret = 0 Then Throw New IO.IOException()
 				csbi.wAttributes And = &HFF0F'背景色だけ変更できるようにマスク処理
-				ret = SetConsoleTextAttribute(h,csbi.wAttributes Or (This.ConsoleColorToTextAttribute(value)<<4) As Word/* foreをbackへ変換 */)			
+				ret = SetConsoleTextAttribute(Console.hconsoleout,csbi.wAttributes Or (This.ConsoleColorToTextAttribute(value)<<4) As Word/* foreをbackへ変換 */)			
 				If ret = 0 Then Throw New IO.IOException()
 			End If
@@ -61,10 +61,9 @@
 			Return ConsoleColor.Gray
 		Else
-			Dim h = This.GetStdOutputHandle()
-			If h = NULL Then
+			If Console.hconsoleout = NULL Then
 				Return ConsoleColor.Gray
 			Else
 				Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
-				Dim ret = GetConsoleScreenBufferInfo(h,csbi)
+				Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi)
 				If ret = 0 Then Throw New IO.IOException()
 				Dim attributes = csbi.wAttributes And &H00F0'背景色だけ取り出せるようにマスク処理
@@ -104,5 +103,5 @@
 		Dim width As Long, height As Long
 		This.GetBufferSize(width,height)
-		Return height
+		Return width
 	End Function
 
@@ -129,23 +128,21 @@
 	*/
 	Static Sub CursorSize ( value As Long )
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Exit Sub
 		Else
 			Dim cci As CONSOLE_CURSOR_INFO
-			Dim ret = GetConsoleCursorInfo(h,cci)
+			Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci)
 			If ret = 0 Then Throw New IO.IOException()
 			cci.dwSize = value As DWord
-			ret = SetConsoleCursorInfo(h,cci)
+			ret = SetConsoleCursorInfo(Console.hconsoleout,cci)
 			If ret = 0 Then Throw New IO.IOException()
 		End If
 	End Sub
 	Static Function CursorSize () As Long
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Return -1 As Long
 		Else
 			Dim cci As CONSOLE_CURSOR_INFO
-			Dim ret = GetConsoleCursorInfo(h,cci)
+			Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci)
 			If ret = 0 Then Throw New IO.IOException()
 			Return cci.dwSize As Long
@@ -175,23 +172,21 @@
 	*/
 	Static Sub CursorVisible ( visible As Boolean )
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Exit Sub
 		Else
 			Dim cci As CONSOLE_CURSOR_INFO
-			Dim ret = GetConsoleCursorInfo(h,cci)
+			Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci)
 			If ret = 0 Then Throw New IO.IOException()
 			cci.bVisible = visible As BOOL
-			ret = SetConsoleCursorInfo(h,cci)
+			ret = SetConsoleCursorInfo(Console.hconsoleout,cci)
 			If ret = 0 Then Throw New IO.IOException()
 		End If
 	End Sub
 	Static Function CursorVisible () As Boolean
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Return False
 		Else
 			Dim cci As CONSOLE_CURSOR_INFO
-			Dim ret = GetConsoleCursorInfo(h,cci)
+			Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci)
 			If ret = 0 Then Throw New IO.IOException()
 			Return cci.bVisible As Boolean
@@ -208,13 +203,12 @@
 			Exit Sub
 		Else
-			Dim h = This.GetStdOutputHandle()
-			If h = NULL Then
+			If Console.hconsoleout = NULL Then
 				Exit Sub
 			Else
 				Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
-				Dim ret = GetConsoleScreenBufferInfo(h,csbi)
+				Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi)
 				If ret = 0 Then Throw New IO.IOException()
 				csbi.wAttributes And = &HFFF0'前景色だけ変更できるようにマスク処理
-				ret = SetConsoleTextAttribute(h,csbi.wAttributes Or This.ConsoleColorToTextAttribute(value))			
+				ret = SetConsoleTextAttribute(Console.hconsoleout,csbi.wAttributes Or This.ConsoleColorToTextAttribute(value))			
 				If ret = 0 Then Throw New IO.IOException()
 			End If
@@ -225,10 +219,9 @@
 			Return ConsoleColor.Gray
 		Else
-			Dim h = This.GetStdOutputHandle()
-			If h = NULL Then
+			If Console.hconsoleout = NULL Then
 				Return ConsoleColor.Gray
 			Else
 				Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
-				Dim ret = GetConsoleScreenBufferInfo(h,csbi)
+				Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi)
 				If ret = 0 Then Throw New IO.IOException()
 				Dim attributes = csbi.wAttributes And &H000F'前景色だけ取り出せるようにマスク処理
@@ -244,6 +237,5 @@
 	*/
 	Static Sub Title( title As String )
-		Dim h = This.GetStdOutputHandle()
-		If h=NULL Then
+		If Console.hconsoleout =NULL Then
 			Exit Sub
 		Else
@@ -253,6 +245,5 @@
 	Static Function Title() As String
 		Dim sb = New Text.StringBuilder(24500*SizeOf(Char))
-		Dim h = This.GetStdOutputHandle()
-		If h=NULL Then
+		If Console.hconsoleout =NULL Then
 			Return ""
 		Else
@@ -271,5 +262,8 @@
 			Throw New ArgumentNullException("newErr")
 		End If
-		err = newErr
+		Console.err = newErr
+		Dim sw = Console.err As IO.StreamWriter
+		Dim fs = sw.BaseStream() As IO.FileStream
+		Console.hconsoleerr = fs.Handle()
 	End Sub
 
@@ -292,5 +286,8 @@
 			Throw New ArgumentNullException("newOut")
 		End If
-		out = newOut
+		Console.out = newOut
+		Dim sw = Console.out As IO.StreamWriter
+		Dim fs = sw.BaseStream() As IO.FileStream
+		Console.hconsoleout = fs.Handle()
 	End Sub
 
@@ -434,5 +431,8 @@
 			Throw New ArgumentNullException("newIn")
 		End If
-		in = newIn
+		Console.in = newIn
+		Dim sr = Console.in As IO.StreamReader
+		Dim fs = sr.BaseStream() As IO.FileStream
+		Console.hconsolein = fs.Handle()
 	End Sub
 
@@ -465,26 +465,62 @@
 
 	/*
-	@brief コンソール バッファおよび対応するコンソール ウィンドウをクリア
-	@date 2008/09/02
+	@brief  コンソール バッファおよび対応するコンソール ウィンドウをクリア
+	@date   2008/09/02
 	@auther NoWest
 	*/
 	Static Sub Clear()
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Exit Sub
 		Else
 			Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
-			Dim ret = GetConsoleScreenBufferInfo(h,csbi)
+			Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi)
 			If ret = 0 Then Throw New IO.IOException()
 			Dim length = csbi.dwSize.X * csbi.dwSize.Y
 			Dim written As DWord
 			Dim s = New String(" ")
-			ret = FillConsoleOutputCharacter(h,s[0],length,0,written)
-			If ret = 0 Then Throw New IO.IOException()
-			ret = FillConsoleOutputAttribute(h,csbi.wAttributes,length,0,written)
-			If ret = 0 Then Throw New IO.IOException()
-			ret = SetConsoleCursorPosition(h,0)
-			If ret = 0 Then Throw New IO.IOException()
-		End If
+			ret = FillConsoleOutputCharacter(Console.hconsoleout,s[0],length,0,written)
+			If ret = 0 Then Throw New IO.IOException()
+			ret = FillConsoleOutputAttribute(Console.hconsoleout,csbi.wAttributes,length,0,written)
+			If ret = 0 Then Throw New IO.IOException()
+			ret = SetConsoleCursorPosition(Console.hconsoleout,0)
+			If ret = 0 Then Throw New IO.IOException()
+		End If
+	End Sub
+
+	/*
+	@brief  標準エラー ストリームを取得
+	@date   2008/09/07
+	@auther NoWest
+	*/
+	Static Sub OpenStandardError()
+		Console.SetError(System.IO.TextWriter.Synchronized(New System.IO.StreamWriter(New System.IO.FileStream(GetStdHandle(STD_ERROR_HANDLE), System.IO.FileAccess.Write, False))))
+	End Sub
+
+	/*
+	@brief  標準入力ストリーム ストリームを取得
+	@date   2008/09/07
+	@auther NoWest
+	*/
+	Static Sub OpenStandardInput()
+		Console.SetIn(System.IO.TextReader.Synchronized(New System.IO.StreamReader(New System.IO.FileStream(GetStdHandle(STD_INPUT_HANDLE), System.IO.FileAccess.Read, False))))
+	End Sub
+
+	/*
+	@brief  標準出力ストリーム ストリームを取得
+	@date   2008/09/07
+	@auther NoWest
+	*/
+	Static Sub OpenStandardOutput()
+		Console.SetOut(System.IO.TextWriter.Synchronized(New System.IO.StreamWriter(New System.IO.FileStream(GetStdHandle(STD_OUTPUT_HANDLE), System.IO.FileAccess.Write, False))))
+	End Sub
+
+	/*
+	@brief  コンソールの前景色および背景色を既定値に設定(前景色=gray 背景色=black)
+	@date   2008/09/07
+	@auther NoWest
+	*/
+	Static Sub ResetColor()
+		Console.BackgroundColor(ConsoleColor.Black)
+		Console.ForegroundColor(ConsoleColor.Gray)
 	End Sub
 
@@ -495,6 +531,5 @@
 	*/
 	Static Sub SetBufferSize ( width As Long, height As Long )
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Exit Sub
 		Else
@@ -502,5 +537,5 @@
 			size.X = width As Integer
 			size.Y = height As Integer
-			Dim ret = SetConsoleScreenBufferSize(h,COORDtoDWORD(size))
+			Dim ret = SetConsoleScreenBufferSize(Console.hconsoleout,COORDtoDWORD(size))
 			If ret = 0 Then Throw New IO.IOException()
 		End If
@@ -513,6 +548,5 @@
 	*/
 	Static Sub SetCursorPosition ( left As Long, top As Long )
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Exit Sub
 		Else
@@ -520,5 +554,5 @@
 			pos.X = left As Integer
 			pos.Y = top As Integer
-			Dim ret = SetConsoleCursorPosition(h,COORDtoDWORD(pos))
+			Dim ret = SetConsoleCursorPosition(Console.hconsoleout,COORDtoDWORD(pos))
 			If ret = 0 Then Throw New IO.IOException()
 		End If
@@ -539,10 +573,4 @@
 		End If
 		enter = cs.Enter
-	End Function
-
-	Function GetStdOutputHandle() As HANDLE
-		Dim sw = Console.out As IO.StreamWriter
-		Dim fs = sw.BaseStream() As IO.FileStream
-		Return fs.Handle()
 	End Function
 
@@ -592,10 +620,9 @@
 
 	Sub GetCursorPosition ( ByRef left As Long, ByRef top As Long )
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Exit Sub
 		Else
 			Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
-			Dim ret = GetConsoleScreenBufferInfo(h,csbi)
+			Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi)
 			If ret = 0 Then Throw New IO.IOException()
 			left = csbi.dwCursorPosition.X
@@ -605,10 +632,9 @@
 
 	Sub GetBufferSize ( ByRef width As Long, ByRef height As Long )
-		Dim h = This.GetStdOutputHandle()
-		If h = NULL Then
+		If Console.hconsoleout = NULL Then
 			Exit Sub
 		Else
 			Dim csbi As CONSOLE_SCREEN_BUFFER_INFO
-			Dim ret = GetConsoleScreenBufferInfo(h,csbi)
+			Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi)
 			If ret = 0 Then Throw New IO.IOException()
 			width = csbi.dwSize.X
@@ -617,4 +643,7 @@
 	End Sub
 
+	Static hconsoleerr = NULL As HANDLE
+	Static hconsolein = NULL As HANDLE
+	Static hconsoleout = NULL As HANDLE
 	Static in = Nothing As IO.TextReader
 	Static out = Nothing As IO.TextWriter
Index: trunk/ab5.0/ablib/src/Classes/System/IO/StreamReader.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/System/IO/StreamReader.ab	(revision 624)
+++ trunk/ab5.0/ablib/src/Classes/System/IO/StreamReader.ab	(revision 627)
@@ -27,4 +27,14 @@
 		init(stream)
 	End Sub
+
+Public
+	/*
+	@brief 基になるストリームを取得する
+	@date 2008/09/02
+	@auther NoWest
+	*/
+	Function BaseStream () As Stream
+		Return s
+	End Function
 
 	/*
Index: trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab	(revision 624)
+++ trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab	(revision 627)
@@ -36,5 +36,5 @@
 	@auther NoWest
 	*/
-	Function BaseStream () As Stream
+	Function BaseStream () As System.IO.Stream
 		Return s
 	End Function
