@@ -55,6 +55,7 @@ open Microsoft.FSharp.Compiler.Tastops
5555open Microsoft.FSharp .Compiler .TcGlobals
5656
5757open Internal.Utilities .Collections
58+ open Internal.Utilities .StructuredFormat
5859
5960type FormatOptions = Internal.Utilities.StructuredFormat.FormatOptions
6061
@@ -148,6 +149,45 @@ module internal Utilities =
148149let m = match typeArgswith [||] -> m| _ -> m.MakeGenericMethod( typeArgs)
149150 m.Invoke( obj, [| v1; v2; v3|]) |> unbox
150151
152+ let colorPrintL ( outWriter : TextWriter ) opts layout =
153+ let renderer =
154+ { new LayoutRenderer< NoResult, NoState> with
155+ member r.Start () = NoState
156+
157+ member r.AddText z s =
158+ let color =
159+ match swith
160+ | Keyword_ -> ConsoleColor.Blue
161+ | TypeParameter_
162+ | Alias_
163+ | Class_ -> ConsoleColor.Cyan
164+ | StringLiteral_ -> ConsoleColor.Red
165+ | NumericLiteral_ -> ConsoleColor.Magenta
166+ | _ -> Console.ForegroundColor
167+
168+ DoWithColor color( fun () -> outWriter.Write s.Value)
169+
170+ z
171+
172+ member r.AddBreak z n =
173+ outWriter.WriteLine()
174+ outWriter.Write( String.replicate n" " )
175+ z
176+
177+ member r.AddTag z ( tag , attrs , start ) = z
178+
179+ member r.Finish z =
180+ outWriter.WriteLine()
181+ NoResult
182+ }
183+
184+ layout
185+ |> Internal.Utilities.StructuredFormat.Display.squash_ layout opts
186+ |> Layout.renderL renderer
187+ |> ignore
188+
189+ outWriter.WriteLine()
190+
151191let referencedAssemblies = Dictionary< string, DateTime>()
152192
153193#if FX_ RESHAPED_ REFLECTION
@@ -237,7 +277,7 @@ type public FsiEvaluationSessionHostConfig () =
237277
238278/// Used to print value signatures along with their values, according to the current
239279/// set of pretty printers installed in the system, and default printing rules.
240- type internal FsiValuePrinter ( fsi : FsiEvaluationSessionHostConfig , g : TcGlobals , generateDebugInfo , resolvePath , outWriter ) =
280+ type internal FsiValuePrinter ( fsi : FsiEvaluationSessionHostConfig , g : TcGlobals , generateDebugInfo , resolvePath , outWriter : TextWriter ) =
241281
242282/// This printer is used by F# Interactive if no other printers apply.
243283let DefaultPrintingIntercept ( ienv : Internal.Utilities.StructuredFormat.IEnvironment ) ( obj : obj ) =
@@ -405,10 +445,8 @@ type internal FsiValuePrinter(fsi: FsiEvaluationSessionHostConfig, g: TcGlobals,
405445 NicePrint.layoutValOrMember denv vref(* the rhs was suppressed by the printer, so no value to print*)
406446else
407447( NicePrint.layoutValOrMember denv vref++ wordL( TaggedTextOps.tagText" =" )) --- rhsL.Value
408- Internal.Utilities.StructuredFormat.Display.output_ layout opts outWriter fullL;
409- outWriter.WriteLine()
410-
411448
449+ Utilities.colorPrintL outWriter opts fullL
412450
413451/// Used to make a copy of input in order to include the input when displaying the error text.
414452type internal FsiStdinSyphon ( errorWriter : TextWriter ) =
@@ -450,10 +488,9 @@ type internal FsiStdinSyphon(errorWriter: TextWriter) =
450488 Utilities.ignoreAllErrors( fun () ->
451489let isError = true
452490 DoWithErrorColor isError( fun () ->
453- errorWriter.WriteLine();
454491 writeViaBufferWithEnvironmentNewLines errorWriter( OutputDiagnosticContext" " syphon.GetLine) err;
455492 writeViaBufferWithEnvironmentNewLines errorWriter( OutputDiagnostic( tcConfig.implicitIncludeDir, tcConfig.showFullPaths, tcConfig.flatErrors, tcConfig.errorStyle, isError)) err;
456- errorWriter.WriteLine()
493+ errorWriter.WriteLine( " \n " )
457494 errorWriter.Flush()))
458495
459496
@@ -498,7 +535,7 @@ type internal ErrorLoggerThatStopsOnFirstError(tcConfigB:TcConfigBuilder, fsiStd
498535 fsiConsoleOutput.Error.WriteLine()
499536 writeViaBufferWithEnvironmentNewLines fsiConsoleOutput.Error( OutputDiagnosticContext" " fsiStdinSyphon.GetLine) err
500537 writeViaBufferWithEnvironmentNewLines fsiConsoleOutput.Error( OutputDiagnostic( tcConfigB.implicitIncludeDir, tcConfigB.showFullPaths, tcConfigB.flatErrors, tcConfigB.errorStyle, isError)) err
501- fsiConsoleOutput.Error.WriteLine())
538+ fsiConsoleOutput.Error.WriteLine( " \n " ))
502539
503540override x.ErrorCount = errorCount
504541
@@ -1049,12 +1086,9 @@ type internal FsiDynamicCompiler
10491086
10501087for ( TImplFile(_ qname,_, mexpr,_,_)) in declaredImplsdo
10511088let responseL = NicePrint.layoutInferredSigOfModuleExprfalse denv infoReader AccessibleFromSomewhere rangeStdin mexpr
1052- if not ( Layout.isEmptyL responseL) then
1053- fsiConsoleOutput.uprintfn" " ;
1089+ if not ( Layout.isEmptyL responseL) then
10541090let opts = valuePrinter.GetFsiPrintOptions()
1055- let responseL = Internal.Utilities.StructuredFormat.Display.squash_ layout opts responseL
1056- Layout.renderL( Layout.channelR outWriter) responseL|> ignore
1057- fsiConsoleOutput.uprintfnn" "
1091+ Utilities.colorPrintL outWriter opts responseL|> ignore
10581092
10591093// Build the new incremental state.
10601094let istate = { istatewith optEnv= optEnv;
@@ -1741,7 +1775,7 @@ type internal FsiInteractionProcessor
17411775 initialInteractiveState) =
17421776
17431777let mutable currState = initialInteractiveState
1744- let event = Event< unit>()
1778+ let event = Control. Event< unit>()
17451779let setCurrState s = currState<- s; event.Trigger()
17461780let runCodeOnEventLoop errorLogger f istate =
17471781try