- Timestamp:
- Sep 18, 2008, 4:01:32 AM (16 years ago)
- Location:
- trunk/ab5.0/ablib/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/Console.ab
r623 r627 27 27 Magenta = FOREGROUND_RED Or FOREGROUND_BLUE Or FOREGROUND_INTENSITY 28 28 End Enum 29 29 30 30 31 /* … … 44 45 Exit Sub 45 46 Else 46 Dim h = This.GetStdOutputHandle() 47 If h = NULL Then 47 If Console.hconsoleout = NULL Then 48 48 Exit Sub 49 49 Else 50 50 Dim csbi As CONSOLE_SCREEN_BUFFER_INFO 51 Dim ret = GetConsoleScreenBufferInfo( h,csbi)51 Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi) 52 52 If ret = 0 Then Throw New IO.IOException() 53 53 csbi.wAttributes And = &HFF0F'背景色だけ変更できるようにマスク処理 54 ret = SetConsoleTextAttribute( h,csbi.wAttributes Or (This.ConsoleColorToTextAttribute(value)<<4) As Word/* foreをbackへ変換 */)54 ret = SetConsoleTextAttribute(Console.hconsoleout,csbi.wAttributes Or (This.ConsoleColorToTextAttribute(value)<<4) As Word/* foreをbackへ変換 */) 55 55 If ret = 0 Then Throw New IO.IOException() 56 56 End If … … 61 61 Return ConsoleColor.Gray 62 62 Else 63 Dim h = This.GetStdOutputHandle() 64 If h = NULL Then 63 If Console.hconsoleout = NULL Then 65 64 Return ConsoleColor.Gray 66 65 Else 67 66 Dim csbi As CONSOLE_SCREEN_BUFFER_INFO 68 Dim ret = GetConsoleScreenBufferInfo( h,csbi)67 Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi) 69 68 If ret = 0 Then Throw New IO.IOException() 70 69 Dim attributes = csbi.wAttributes And &H00F0'背景色だけ取り出せるようにマスク処理 … … 104 103 Dim width As Long, height As Long 105 104 This.GetBufferSize(width,height) 106 Return height105 Return width 107 106 End Function 108 107 … … 129 128 */ 130 129 Static Sub CursorSize ( value As Long ) 131 Dim h = This.GetStdOutputHandle() 132 If h = NULL Then 130 If Console.hconsoleout = NULL Then 133 131 Exit Sub 134 132 Else 135 133 Dim cci As CONSOLE_CURSOR_INFO 136 Dim ret = GetConsoleCursorInfo( h,cci)134 Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci) 137 135 If ret = 0 Then Throw New IO.IOException() 138 136 cci.dwSize = value As DWord 139 ret = SetConsoleCursorInfo( h,cci)137 ret = SetConsoleCursorInfo(Console.hconsoleout,cci) 140 138 If ret = 0 Then Throw New IO.IOException() 141 139 End If 142 140 End Sub 143 141 Static Function CursorSize () As Long 144 Dim h = This.GetStdOutputHandle() 145 If h = NULL Then 142 If Console.hconsoleout = NULL Then 146 143 Return -1 As Long 147 144 Else 148 145 Dim cci As CONSOLE_CURSOR_INFO 149 Dim ret = GetConsoleCursorInfo( h,cci)146 Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci) 150 147 If ret = 0 Then Throw New IO.IOException() 151 148 Return cci.dwSize As Long … … 175 172 */ 176 173 Static Sub CursorVisible ( visible As Boolean ) 177 Dim h = This.GetStdOutputHandle() 178 If h = NULL Then 174 If Console.hconsoleout = NULL Then 179 175 Exit Sub 180 176 Else 181 177 Dim cci As CONSOLE_CURSOR_INFO 182 Dim ret = GetConsoleCursorInfo( h,cci)178 Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci) 183 179 If ret = 0 Then Throw New IO.IOException() 184 180 cci.bVisible = visible As BOOL 185 ret = SetConsoleCursorInfo( h,cci)181 ret = SetConsoleCursorInfo(Console.hconsoleout,cci) 186 182 If ret = 0 Then Throw New IO.IOException() 187 183 End If 188 184 End Sub 189 185 Static Function CursorVisible () As Boolean 190 Dim h = This.GetStdOutputHandle() 191 If h = NULL Then 186 If Console.hconsoleout = NULL Then 192 187 Return False 193 188 Else 194 189 Dim cci As CONSOLE_CURSOR_INFO 195 Dim ret = GetConsoleCursorInfo( h,cci)190 Dim ret = GetConsoleCursorInfo(Console.hconsoleout,cci) 196 191 If ret = 0 Then Throw New IO.IOException() 197 192 Return cci.bVisible As Boolean … … 208 203 Exit Sub 209 204 Else 210 Dim h = This.GetStdOutputHandle() 211 If h = NULL Then 205 If Console.hconsoleout = NULL Then 212 206 Exit Sub 213 207 Else 214 208 Dim csbi As CONSOLE_SCREEN_BUFFER_INFO 215 Dim ret = GetConsoleScreenBufferInfo( h,csbi)209 Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi) 216 210 If ret = 0 Then Throw New IO.IOException() 217 211 csbi.wAttributes And = &HFFF0'前景色だけ変更できるようにマスク処理 218 ret = SetConsoleTextAttribute( h,csbi.wAttributes Or This.ConsoleColorToTextAttribute(value))212 ret = SetConsoleTextAttribute(Console.hconsoleout,csbi.wAttributes Or This.ConsoleColorToTextAttribute(value)) 219 213 If ret = 0 Then Throw New IO.IOException() 220 214 End If … … 225 219 Return ConsoleColor.Gray 226 220 Else 227 Dim h = This.GetStdOutputHandle() 228 If h = NULL Then 221 If Console.hconsoleout = NULL Then 229 222 Return ConsoleColor.Gray 230 223 Else 231 224 Dim csbi As CONSOLE_SCREEN_BUFFER_INFO 232 Dim ret = GetConsoleScreenBufferInfo( h,csbi)225 Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi) 233 226 If ret = 0 Then Throw New IO.IOException() 234 227 Dim attributes = csbi.wAttributes And &H000F'前景色だけ取り出せるようにマスク処理 … … 244 237 */ 245 238 Static Sub Title( title As String ) 246 Dim h = This.GetStdOutputHandle() 247 If h=NULL Then 239 If Console.hconsoleout =NULL Then 248 240 Exit Sub 249 241 Else … … 253 245 Static Function Title() As String 254 246 Dim sb = New Text.StringBuilder(24500*SizeOf(Char)) 255 Dim h = This.GetStdOutputHandle() 256 If h=NULL Then 247 If Console.hconsoleout =NULL Then 257 248 Return "" 258 249 Else … … 271 262 Throw New ArgumentNullException("newErr") 272 263 End If 273 err = newErr 264 Console.err = newErr 265 Dim sw = Console.err As IO.StreamWriter 266 Dim fs = sw.BaseStream() As IO.FileStream 267 Console.hconsoleerr = fs.Handle() 274 268 End Sub 275 269 … … 292 286 Throw New ArgumentNullException("newOut") 293 287 End If 294 out = newOut 288 Console.out = newOut 289 Dim sw = Console.out As IO.StreamWriter 290 Dim fs = sw.BaseStream() As IO.FileStream 291 Console.hconsoleout = fs.Handle() 295 292 End Sub 296 293 … … 434 431 Throw New ArgumentNullException("newIn") 435 432 End If 436 in = newIn 433 Console.in = newIn 434 Dim sr = Console.in As IO.StreamReader 435 Dim fs = sr.BaseStream() As IO.FileStream 436 Console.hconsolein = fs.Handle() 437 437 End Sub 438 438 … … 465 465 466 466 /* 467 @brief コンソール バッファおよび対応するコンソール ウィンドウをクリア468 @date 2008/09/02467 @brief コンソール バッファおよび対応するコンソール ウィンドウをクリア 468 @date 2008/09/02 469 469 @auther NoWest 470 470 */ 471 471 Static Sub Clear() 472 Dim h = This.GetStdOutputHandle() 473 If h = NULL Then 472 If Console.hconsoleout = NULL Then 474 473 Exit Sub 475 474 Else 476 475 Dim csbi As CONSOLE_SCREEN_BUFFER_INFO 477 Dim ret = GetConsoleScreenBufferInfo( h,csbi)476 Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi) 478 477 If ret = 0 Then Throw New IO.IOException() 479 478 Dim length = csbi.dwSize.X * csbi.dwSize.Y 480 479 Dim written As DWord 481 480 Dim s = New String(" ") 482 ret = FillConsoleOutputCharacter(h,s[0],length,0,written) 483 If ret = 0 Then Throw New IO.IOException() 484 ret = FillConsoleOutputAttribute(h,csbi.wAttributes,length,0,written) 485 If ret = 0 Then Throw New IO.IOException() 486 ret = SetConsoleCursorPosition(h,0) 487 If ret = 0 Then Throw New IO.IOException() 488 End If 481 ret = FillConsoleOutputCharacter(Console.hconsoleout,s[0],length,0,written) 482 If ret = 0 Then Throw New IO.IOException() 483 ret = FillConsoleOutputAttribute(Console.hconsoleout,csbi.wAttributes,length,0,written) 484 If ret = 0 Then Throw New IO.IOException() 485 ret = SetConsoleCursorPosition(Console.hconsoleout,0) 486 If ret = 0 Then Throw New IO.IOException() 487 End If 488 End Sub 489 490 /* 491 @brief 標準エラー ストリームを取得 492 @date 2008/09/07 493 @auther NoWest 494 */ 495 Static Sub OpenStandardError() 496 Console.SetError(System.IO.TextWriter.Synchronized(New System.IO.StreamWriter(New System.IO.FileStream(GetStdHandle(STD_ERROR_HANDLE), System.IO.FileAccess.Write, False)))) 497 End Sub 498 499 /* 500 @brief 標準入力ストリーム ストリームを取得 501 @date 2008/09/07 502 @auther NoWest 503 */ 504 Static Sub OpenStandardInput() 505 Console.SetIn(System.IO.TextReader.Synchronized(New System.IO.StreamReader(New System.IO.FileStream(GetStdHandle(STD_INPUT_HANDLE), System.IO.FileAccess.Read, False)))) 506 End Sub 507 508 /* 509 @brief 標準出力ストリーム ストリームを取得 510 @date 2008/09/07 511 @auther NoWest 512 */ 513 Static Sub OpenStandardOutput() 514 Console.SetOut(System.IO.TextWriter.Synchronized(New System.IO.StreamWriter(New System.IO.FileStream(GetStdHandle(STD_OUTPUT_HANDLE), System.IO.FileAccess.Write, False)))) 515 End Sub 516 517 /* 518 @brief コンソールの前景色および背景色を既定値に設定(前景色=gray 背景色=black) 519 @date 2008/09/07 520 @auther NoWest 521 */ 522 Static Sub ResetColor() 523 Console.BackgroundColor(ConsoleColor.Black) 524 Console.ForegroundColor(ConsoleColor.Gray) 489 525 End Sub 490 526 … … 495 531 */ 496 532 Static Sub SetBufferSize ( width As Long, height As Long ) 497 Dim h = This.GetStdOutputHandle() 498 If h = NULL Then 533 If Console.hconsoleout = NULL Then 499 534 Exit Sub 500 535 Else … … 502 537 size.X = width As Integer 503 538 size.Y = height As Integer 504 Dim ret = SetConsoleScreenBufferSize( h,COORDtoDWORD(size))539 Dim ret = SetConsoleScreenBufferSize(Console.hconsoleout,COORDtoDWORD(size)) 505 540 If ret = 0 Then Throw New IO.IOException() 506 541 End If … … 513 548 */ 514 549 Static Sub SetCursorPosition ( left As Long, top As Long ) 515 Dim h = This.GetStdOutputHandle() 516 If h = NULL Then 550 If Console.hconsoleout = NULL Then 517 551 Exit Sub 518 552 Else … … 520 554 pos.X = left As Integer 521 555 pos.Y = top As Integer 522 Dim ret = SetConsoleCursorPosition( h,COORDtoDWORD(pos))556 Dim ret = SetConsoleCursorPosition(Console.hconsoleout,COORDtoDWORD(pos)) 523 557 If ret = 0 Then Throw New IO.IOException() 524 558 End If … … 539 573 End If 540 574 enter = cs.Enter 541 End Function542 543 Function GetStdOutputHandle() As HANDLE544 Dim sw = Console.out As IO.StreamWriter545 Dim fs = sw.BaseStream() As IO.FileStream546 Return fs.Handle()547 575 End Function 548 576 … … 592 620 593 621 Sub GetCursorPosition ( ByRef left As Long, ByRef top As Long ) 594 Dim h = This.GetStdOutputHandle() 595 If h = NULL Then 622 If Console.hconsoleout = NULL Then 596 623 Exit Sub 597 624 Else 598 625 Dim csbi As CONSOLE_SCREEN_BUFFER_INFO 599 Dim ret = GetConsoleScreenBufferInfo( h,csbi)626 Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi) 600 627 If ret = 0 Then Throw New IO.IOException() 601 628 left = csbi.dwCursorPosition.X … … 605 632 606 633 Sub GetBufferSize ( ByRef width As Long, ByRef height As Long ) 607 Dim h = This.GetStdOutputHandle() 608 If h = NULL Then 634 If Console.hconsoleout = NULL Then 609 635 Exit Sub 610 636 Else 611 637 Dim csbi As CONSOLE_SCREEN_BUFFER_INFO 612 Dim ret = GetConsoleScreenBufferInfo( h,csbi)638 Dim ret = GetConsoleScreenBufferInfo(Console.hconsoleout,csbi) 613 639 If ret = 0 Then Throw New IO.IOException() 614 640 width = csbi.dwSize.X … … 617 643 End Sub 618 644 645 Static hconsoleerr = NULL As HANDLE 646 Static hconsolein = NULL As HANDLE 647 Static hconsoleout = NULL As HANDLE 619 648 Static in = Nothing As IO.TextReader 620 649 Static out = Nothing As IO.TextWriter -
trunk/ab5.0/ablib/src/Classes/System/IO/StreamReader.ab
r605 r627 27 27 init(stream) 28 28 End Sub 29 30 Public 31 /* 32 @brief 基になるストリームを取得する 33 @date 2008/09/02 34 @auther NoWest 35 */ 36 Function BaseStream () As Stream 37 Return s 38 End Function 29 39 30 40 /* -
trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab
r622 r627 36 36 @auther NoWest 37 37 */ 38 Function BaseStream () As S tream38 Function BaseStream () As System.IO.Stream 39 39 Return s 40 40 End Function -
trunk/ab5.0/ablib/src/basic/dos_console.sbp
r606 r627 6 6 #define _INC_DOS_CONSOLE 7 7 8 9 Dim _System_hConsoleErr = GetStdHandle(STD_ERROR_HANDLE) 10 Dim _System_hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE) 11 Dim _System_hConsoleIn = GetStdHandle(STD_INPUT_HANDLE) 12 System.Console.SetError( 13 System.IO.TextWriter.Synchronized(New System.IO.StreamWriter( 14 New System.IO.FileStream(_System_hConsoleErr, System.IO.FileAccess.Write, False)))) 15 16 System.Console.SetOut( 17 System.IO.TextWriter.Synchronized(New System.IO.StreamWriter( 18 New System.IO.FileStream(_System_hConsoleOut, System.IO.FileAccess.Write, False)))) 19 System.Console.SetIn( 20 System.IO.TextReader.Synchronized(New System.IO.StreamReader( 21 New System.IO.FileStream(_System_hConsoleIn, System.IO.FileAccess.Read, False)))) 8 System.Console.OpenStandardError() 9 System.Console.OpenStandardInput() 10 System.Console.OpenStandardOutput() 22 11 23 12 '---------- command.sbp内で定義済み ---------- … … 55 44 End Sub 56 45 46 /* 47 @brief コンソール出力の内容を削除 48 @date 2008/9/18 49 @auther NoWest 50 */ 51 Macro CLS()(num As Long) 52 Select Case num 53 Case 2 54 Exit Macro 55 Case Else 56 System.Console.Clear() 57 End Select 58 End Macro 59 60 /* 61 @brief コンソール出力の前景色・背景色を変更 62 @date 2008/9/18 63 @auther NoWest 64 */ 65 Macro COLOR(TextColorCode As Long)(BackColorCode=-1 As Long) 66 Select Case TextColorCode 67 Case 1 68 System.Console.ForegroundColor = System.ConsoleColor.Blue 69 Case 2 70 System.Console.ForegroundColor = System.ConsoleColor.Red 71 Case 3 72 System.Console.ForegroundColor = System.ConsoleColor.Magenta 73 Case 4 74 System.Console.ForegroundColor = System.ConsoleColor.Green 75 Case 5 76 System.Console.ForegroundColor = System.ConsoleColor.Cyan 77 Case 6 78 System.Console.ForegroundColor = System.ConsoleColor.Yellow 79 Case 7 80 System.Console.ForegroundColor = System.ConsoleColor.Gray 81 Case Else 82 System.Console.ForegroundColor = System.ConsoleColor.Black 83 End Select 84 85 Select Case BackColorCode 86 Case -1 87 Exit Macro 88 Case 1 89 System.Console.BackgroundColor = System.ConsoleColor.Blue 90 Case 2 91 System.Console.BackgroundColor = System.ConsoleColor.Red 92 Case 3 93 System.Console.BackgroundColor = System.ConsoleColor.Magenta 94 Case 4 95 System.Console.BackgroundColor = System.ConsoleColor.Green 96 Case 5 97 System.Console.BackgroundColor = System.ConsoleColor.Cyan 98 Case 6 99 System.Console.BackgroundColor = System.ConsoleColor.Yellow 100 Case 7 101 System.Console.BackgroundColor = System.ConsoleColor.Gray 102 Case Else 103 System.Console.BackgroundColor = System.ConsoleColor.Black 104 End Select 105 End Macro 106 107 /* 108 @brief コンソール出力のカーソル位置を変更 109 @date 2008/9/18 110 @auther NoWest 111 */ 57 112 Macro LOCATE(x As Long, y As Long) 58 S etConsoleCursorPosition(_System_hConsoleOut, MAKELONG(x, y))113 System.Console.SetCursorPosition(x,y) 59 114 End Macro 60 115
Note:
See TracChangeset
for help on using the changeset viewer.