@@ -449,6 +449,28 @@ public static object tcgetattr(CodeContext context, object? file)
449449 throw new PlatformNotSupportedException ( ) ;
450450 }
451451
452+ #if NETCOREAPP
453+ // TODO: remove .NET workaround
454+ if ( fd == 0
455+ && context . LanguageContext . SystemStandardIn is TextIOWrapper stdin
456+ && ! stdin . closed
457+ && stdin . isatty ( context )
458+ && stdin . fileno ( context ) == 0
459+ && ! Console . IsInputRedirected ) {
460+
461+ if ( when != TCSANOW ) {
462+ stdin . flush ( context ) ;
463+ }
464+
465+ ulong newLflag = ToUInt64 ( attrs [ LocalFlagIdx ] ) ;
466+ if ( ( newLflag & ( ECHO | ICANON | IEXTEN | ISIG ) ) == 0 ) {
467+ setraw ( context , stdin ) ;
468+ } else {
469+ setcbreak ( context , stdin ) ;
470+ }
471+ }
472+ #endif
473+
452474 return null ;
453475
454476 // Local functions ------------------------------------------------
@@ -694,6 +716,8 @@ private unsafe struct darwin__termios {
694716
695717 #region Private Helpers
696718
719+ #if NETCOREAPP
720+ // .NET workaround for stdin raw mode
697721 private static object ? _savedRawStdin ;
698722
699723 private static void setraw ( CodeContext context , TextIOWrapper stdin ) {
@@ -704,7 +728,7 @@ private static void setraw(CodeContext context, TextIOWrapper stdin) {
704728 }
705729
706730 private static void setcbreak ( CodeContext context , TextIOWrapper stdin ) {
707- if ( _savedRawStdin is not null
731+ if ( _savedRawStdin is not null
708732 && stdin . buffer is BufferedReader reader
709733 && reader . raw is RawConsole ) {
710734
@@ -718,13 +742,7 @@ public RawConsole(CodeContext context) : base(context) {
718742 }
719743
720744 public override object ? read ( CodeContext context , object ? size = null ) {
721- int intSize = size switch {
722- null => - 1 ,
723- int i => i ,
724- BigInteger bi => ( int ) bi ,
725- Extensible < BigInteger > ebi => ( int ) ebi . Value ,
726- _ => throw PythonOps . TypeErrorForBadInstance ( "integer argument expected, got '{0}'" , size )
727- } ;
745+ BigInteger intSize = PythonOps . ToIndex ( size ) ;
728746 if ( intSize == 0 ) return null ;
729747
730748 ConsoleKeyInfo info = Console . ReadKey ( intercept : true ) ;
@@ -734,6 +752,7 @@ public RawConsole(CodeContext context) : base(context) {
734752 public override int fileno ( CodeContext context ) => 0 ;
735753 public override bool isatty ( CodeContext context ) => true ;
736754 }
755+ #endif
737756
738757
739758 private static void CheckFileDescriptor ( int fd ) {
0 commit comments