Skip to content

Commit 9665470

Browse files
committed
preserve original encoding
1 parent 2ca5cf5 commit 9665470

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/Compiler/Driver/fsc.fs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,23 @@ let AdjustForScriptCompile (tcConfigB: TcConfigBuilder, commandLineSourceFiles,
268268

269269
List.rev allSources
270270

271-
let SetProcessThreadLocals tcConfigB =
271+
let SetProcessThreadLocals tcConfigB (disposables: DisposablesTracker) =
272272
match tcConfigB.preferredUiLang with
273273
| Some s -> Thread.CurrentThread.CurrentUICulture <- CultureInfo(s)
274274
| None -> ()
275275

276276
if tcConfigB.utf8output then
277+
let originalEncoding = Console.OutputEncoding
277278
Console.OutputEncoding <- Encoding.UTF8
278279

279-
let ProcessCommandLineFlags (tcConfigB: TcConfigBuilder, lcidFromCodePage, argv) =
280+
disposables.Register(
281+
{ new IDisposable with
282+
member _.Dispose() =
283+
Console.OutputEncoding <- originalEncoding
284+
}
285+
)
286+
287+
let ProcessCommandLineFlags (tcConfigB: TcConfigBuilder, lcidFromCodePage, argv, disposables) =
280288
let mutable inputFilesRef = []
281289

282290
let collect name =
@@ -297,7 +305,7 @@ let ProcessCommandLineFlags (tcConfigB: TcConfigBuilder, lcidFromCodePage, argv)
297305
| Some _ -> ()
298306
| None -> tcConfigB.lcid <- lcidFromCodePage
299307

300-
SetProcessThreadLocals tcConfigB
308+
SetProcessThreadLocals tcConfigB disposables
301309

302310
(* step - get dll references *)
303311
let dllFiles, sourceFiles =
@@ -535,7 +543,7 @@ let main1
535543
// The ParseCompilerOptions function calls imperative function to process "real" args
536544
// Rather than start processing, just collect names, then process them.
537545
try
538-
let files = ProcessCommandLineFlags(tcConfigB, lcidFromCodePage, argv)
546+
let files = ProcessCommandLineFlags(tcConfigB, lcidFromCodePage, argv, disposables)
539547
let files = CheckAndReportSourceFileDuplicates(ResizeArray.ofList files)
540548
AdjustForScriptCompile(tcConfigB, files, lexResourceManager, dependencyProvider)
541549
with e ->

src/fsi/fsimain.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,19 @@ let MainMain argv =
359359
ignore argv
360360
let argv = System.Environment.GetCommandLineArgs()
361361

362+
let originalInputEncoding = Console.InputEncoding
363+
let originalOutputEncoding = Console.OutputEncoding
364+
365+
use __ =
366+
{ new IDisposable with
367+
member _.Dispose() =
368+
try
369+
Console.InputEncoding <- originalInputEncoding
370+
Console.OutputEncoding <- originalOutputEncoding
371+
with _ ->
372+
()
373+
}
374+
362375
let timesFlag = argv |> Array.exists (fun x -> x = "/times" || x = "--times")
363376

364377
if timesFlag then

0 commit comments

Comments
 (0)