Changeset 676 for trunk/ab5.0/ablib/src/Classes/System/Console.ab
- Timestamp:
- Jan 13, 2009, 2:01:38 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/Console.ab
r636 r676 272 272 End If 273 273 Console.err = newErr 274 Dim sw = Console.err As IO.StreamWriter275 Dim fs = sw.BaseStream() As IO.FileStream276 Console.hconsoleerr = fs.Handle()274 ' Dim sw = Console.err As IO.StreamWriter 275 ' Dim fs = sw.BaseStream() As IO.FileStream 276 ' Console.hconsoleerr = fs.Handle() 277 277 End Sub 278 278 … … 296 296 End If 297 297 Console.out = newOut 298 Dim sw = Console.out As IO.StreamWriter299 Dim fs = sw.BaseStream() As IO.FileStream300 Console.hconsoleout = fs.Handle()301 298 End Sub 302 299 … … 441 438 End If 442 439 Console.in = newIn 443 Dim sr = Console.in As IO.StreamReader444 Dim fs = sr.BaseStream() As IO.FileStream445 Console.hconsolein = fs.Handle()446 440 End Sub 447 441 … … 503 497 */ 504 498 Static Sub OpenStandardError() 505 Console.SetError(System.IO.TextWriter.Synchronized(New System.IO.StreamWriter(New System.IO.FileStream(GetStdHandle(STD_ERROR_HANDLE), System.IO.FileAccess.Write, False)))) 499 Dim w = New Detail.ConsoleWriter(hconsoleerr) 500 Console.SetOut(System.IO.TextWriter.Synchronized(w)) 506 501 End Sub 507 502 … … 512 507 */ 513 508 Static Sub OpenStandardInput() 514 Console.SetIn(System.IO.TextReader.Synchronized(New System.IO.StreamReader(New System.IO.FileStream(GetStdHandle(STD_INPUT_HANDLE), System.IO.FileAccess.Read, False)))) 509 Dim w = New Detail.ConsoleReader(hconsolein) 510 Console.SetIn(System.IO.TextReader.Synchronized(w)) 515 511 End Sub 516 512 … … 521 517 */ 522 518 Static Sub OpenStandardOutput() 523 Console.SetOut(System.IO.TextWriter.Synchronized(New System.IO.StreamWriter(New System.IO.FileStream(GetStdHandle(STD_OUTPUT_HANDLE), System.IO.FileAccess.Write, False)))) 519 Dim w = New Detail.ConsoleWriter(hconsoleout) 520 Console.SetOut(System.IO.TextWriter.Synchronized(w)) 524 521 Console.defBC = This.ConsoleColorToTextAttribute(Console.BackgroundColor) 525 522 Console.defFC = This.ConsoleColorToTextAttribute(Console.ForegroundColor) … … 654 651 End Sub 655 652 656 Static hconsoleerr = NULLAs HANDLE657 Static hconsolein = NULLAs HANDLE658 Static hconsoleout = NULLAs HANDLE653 Static hconsoleerr = GetStdHandle(STD_ERROR_HANDLE) As HANDLE 654 Static hconsolein = GetStdHandle(STD_INPUT_HANDLE) As HANDLE 655 Static hconsoleout = GetStdHandle(STD_OUTPUT_HANDLE) As HANDLE 659 656 Static in = Nothing As IO.TextReader 660 657 Static out = Nothing As IO.TextWriter … … 665 662 End Class 666 663 664 Namespace Detail 665 666 Class ConsoleWriter 667 Inherits IO.TextWriter 668 Public 669 Sub ConsoleWriter(hOut As HANDLE) 670 h = hOut 671 End Sub 672 673 Override Sub Flush() 674 Dim b = Buffer 675 Dim written As DWord 676 WriteConsole(h, StrPtr(b), b.Length As DWord, written, 0) 677 b.Remove(0, written As Long) 678 End Sub 679 680 Private 681 h As HANDLE 682 End Class 683 684 Class ConsoleReader 685 Inherits IO.TextReader 686 Public 687 Sub ConsoleReader(hIn As HANDLE) 688 h = hIn 689 End Sub 690 691 Protected 692 Override Function Underflow() As Boolean 693 Dim b = Buffer 694 Dim currentBufLength = b.Length 695 b.Length = currentBufLength + 256 696 Dim p = StrPtr(b) 697 Dim read As DWord 698 If ReadConsole(h, VarPtr(p[currentBufLength]), 256, read, 0) = 0 Then 699 IO.Detail.ThrowWinLastErrorIOException() 700 End If 701 b.Length = currentBufLength + read 702 End Function 703 704 Private 705 h As HANDLE 706 End Class 707 708 End Namespace 'Detail 709 667 710 End Namespace 'System
Note:
See TracChangeset
for help on using the changeset viewer.