standardio.bmx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. Strict
  2. Rem
  3. bbdoc: System/StandardIO
  4. End Rem
  5. Module BRL.StandardIO
  6. ModuleInfo "Version: 1.05"
  7. ModuleInfo "Author: Mark Sibly"
  8. ModuleInfo "License: zlib/libpng"
  9. ModuleInfo "Copyright: Blitz Research Ltd"
  10. ModuleInfo "Modserver: BRL"
  11. ModuleInfo "History: 1.05 Release"
  12. ModuleInfo "History: 1.04 Release"
  13. ModuleInfo "History: CStandardIO now goes through a UTF8 textstream"
  14. Import BRL.TextStream
  15. Type TCStandardIO Extends TStream
  16. Method Eof:Int()
  17. Return feof_( stdin_ )
  18. End Method
  19. Method Flush()
  20. fflush_ stdout_
  21. End Method
  22. Method Read( buf:Byte Ptr,count )
  23. Return fread_( buf,1,count,stdin_ )
  24. End Method
  25. Method Write( buf:Byte Ptr,count )
  26. Return fwrite_( buf,1,count,stdout_ )
  27. End Method
  28. End Type
  29. Rem
  30. bbdoc: BlitzMax Stream object used for Print and Input
  31. about: The #Print and #Input commands can be redirected by setting the @StandardIOStream Global to an alternative Stream Object.
  32. End Rem
  33. Global StandardIOStream:TStream=TTextStream.Create( New TCStandardIO,TTextStream.UTF8 )
  34. Rem
  35. bbdoc: Write a string to the standard IO stream
  36. about: A newline character is also written after @str.
  37. End Rem
  38. Function Print( str$="" )
  39. StandardIOStream.WriteLine str
  40. StandardIOStream.Flush
  41. End Function
  42. Rem
  43. bbdoc: Receive a line of text from the standard IO stream
  44. about: The optional @prompt is displayed before input is returned.
  45. End Rem
  46. Function Input$( prompt$=">" )
  47. StandardIOStream.WriteString prompt
  48. StandardIOStream.Flush
  49. Return StandardIOStream.ReadLine()
  50. End Function