diff --git a/src/Agent.Sdk/Knob/AgentKnobs.cs b/src/Agent.Sdk/Knob/AgentKnobs.cs index bccf5ca689..f67295f98d 100644 --- a/src/Agent.Sdk/Knob/AgentKnobs.cs +++ b/src/Agent.Sdk/Knob/AgentKnobs.cs @@ -149,6 +149,12 @@ public class AgentKnobs new EnvironmentKnobSource("USE_LATEST_GIT_VERSION"), new BuiltInDefaultKnobSource("false")); + public static readonly Knob AgentTerminalEncoding = new Knob( + nameof(AgentTerminalEncoding), + "If the correct encoding name is specified, the encoding from the environment will be used instead of default UTF-8", + new EnvironmentKnobSource("AGENT_TERMINAL_ENCODING"), + new BuiltInDefaultKnobSource(string.Empty)); + public static readonly Knob TfVCUseSecureParameterPassing = new Knob( nameof(TfVCUseSecureParameterPassing), "If true, don't pass auth token in TFVC parameters", diff --git a/src/Microsoft.VisualStudio.Services.Agent/Terminal.cs b/src/Microsoft.VisualStudio.Services.Agent/Terminal.cs index 9c8e5cc79c..a31d33454e 100644 --- a/src/Microsoft.VisualStudio.Services.Agent/Terminal.cs +++ b/src/Microsoft.VisualStudio.Services.Agent/Terminal.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; +using System.Text; +using Agent.Sdk.Knob; using Agent.Sdk.Util; namespace Microsoft.VisualStudio.Services.Agent @@ -37,6 +39,25 @@ public override void Initialize(IHostContext hostContext) { base.Initialize(hostContext); Console.CancelKeyPress += Console_CancelKeyPress; + + var terminalEncoding = Encoding.UTF8; + var endEncodingName = AgentKnobs.AgentTerminalEncoding.GetValue(hostContext).AsString(); + + try + { + if (!string.IsNullOrEmpty(endEncodingName)) + { + terminalEncoding = Encoding.GetEncoding(endEncodingName); + } + } + catch (Exception ex) + { + Trace.Error($@"Encoding ""{endEncodingName}"" not found:"); + Trace.Error(ex); + } + + Console.OutputEncoding = terminalEncoding; + Console.InputEncoding = terminalEncoding; } private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)