1313using SMA = System . Management . Automation ;
1414using Microsoft . PowerShell . EditorServices . Hosting ;
1515using System . Globalization ;
16+ using System . Collections ;
17+
18+ // TODO: Remove this when we drop support for PS6.
19+ #if CoreCLR
20+ using System . Runtime . InteropServices ;
21+ #endif
1622
1723#if DEBUG
1824using System . Diagnostics ;
@@ -30,6 +36,14 @@ namespace Microsoft.PowerShell.EditorServices.Commands
3036 [ Cmdlet ( VerbsLifecycle . Start , "EditorServices" , DefaultParameterSetName = "NamedPipe" ) ]
3137 public sealed class StartEditorServicesCommand : PSCmdlet
3238 {
39+ // TODO: Remove this when we drop support for PS6.
40+ private static bool s_isWindows =
41+ #if CoreCLR
42+ RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
43+ #else
44+ true ;
45+ #endif
46+
3347 private readonly List < IDisposable > _disposableResources ;
3448
3549 private readonly List < IDisposable > _loggerUnsubscribers ;
@@ -376,6 +390,11 @@ private string GetProfilePathFromProfileObject(PSObject profileObject, ProfileUs
376390 $ "{ HostProfileId } _profile.ps1") ;
377391 }
378392
393+ // We should only use PSReadLine if we specificied that we want a console repl
394+ // and we have not explicitly said to use the legacy ReadLine.
395+ // We also want it if we are either:
396+ // * On Windows on any version OR
397+ // * On Linux or macOS on any version greater than or equal to 7
379398 private ConsoleReplKind GetReplKind ( )
380399 {
381400 _logger . Log ( PsesLogLevel . Diagnostic , "Determining REPL kind" ) ;
@@ -386,7 +405,12 @@ private ConsoleReplKind GetReplKind()
386405 return ConsoleReplKind . None ;
387406 }
388407
389- if ( UseLegacyReadLine )
408+ // TODO: Remove this when we drop support for PS6.
409+ var psVersionTable = ( Hashtable ) this . SessionState . PSVariable . GetValue ( "PSVersionTable" ) ;
410+ dynamic version = psVersionTable [ "PSVersion" ] ;
411+ var majorVersion = ( int ) version . Major ;
412+
413+ if ( UseLegacyReadLine || ( ! s_isWindows && majorVersion == 6 ) )
390414 {
391415 _logger . Log ( PsesLogLevel . Diagnostic , "REPL configured as Legacy" ) ;
392416 return ConsoleReplKind . LegacyReadLine ;
0 commit comments