Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Layers
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.PlatformService
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScriptTest fakes
The platform services expose wide interfaces. Implement the double for each once, in a test helper, rather than in
every test. This page holds a recording IConsole; the HTTP testing guide covers the
one-method IHttp fake and its scripted variant.
Recording console
Show page setup
// Setup for the checked examples on this page.
open System
open System.IO
open Axial
open Axial.Console
/// Fails the docs test when an example's result differs from the value shown.
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actualtype RecordingConsole(input: string) =
let reader = new StringReader(input)
let output = new StringWriter()
let error = new StringWriter()
let mutable inputEncoding = Text.Encoding.UTF8
let mutable outputEncoding = Text.Encoding.UTF8
let mutable foreground = ConsoleColor.Gray
let mutable background = ConsoleColor.Black
let mutable cursorLeft = 0
let mutable cursorTop = 0
let mutable cursorVisible = true
let mutable title = ""
let mutable treatControlC = false
member _.Written = output.ToString()
member _.IsCursorVisible = cursorVisible
interface IConsole with
member _.In = reader
member _.Out = output
member _.Error = error
member _.InputEncoding with get () = inputEncoding and set value = inputEncoding <- value
member _.OutputEncoding with get () = outputEncoding and set value = outputEncoding <- value
member _.IsInputRedirected = true
member _.IsOutputRedirected = true
member _.IsErrorRedirected = true
member _.KeyAvailable = false
member _.Read() = reader.Read()
member _.ReadLine() = reader.ReadLine()
member _.ReadKey _ = ConsoleKeyInfo()
member _.Write value = output.Write value
member _.WriteLine value = output.WriteLine value
member _.WriteError value = error.Write value
member _.WriteErrorLine value = error.WriteLine value
member _.OpenStandardInput() = Stream.Null
member _.OpenStandardOutput() = Stream.Null
member _.OpenStandardError() = Stream.Null
member _.Clear() = ()
member _.Beep() = ()
member _.ResetColor() = ()
member _.ForegroundColor with get () = foreground and set value = foreground <- value
member _.BackgroundColor with get () = background and set value = background <- value
member _.CursorLeft with get () = cursorLeft and set value = cursorLeft <- value
member _.CursorTop with get () = cursorTop and set value = cursorTop <- value
member _.CursorVisible with get () = cursorVisible and set value = cursorVisible <- value
member _.SetCursorPosition(left, top) = cursorLeft <- left; cursorTop <- top
member _.Title with get () = title and set value = title <- value
member _.TreatControlCAsInput with get () = treatControlC and set value = treatControlC <- value
FsLiveDocsGeneratedPage13_10B692608C6D.RecordingConsoleinput: stringstringAn abbreviation for the CLI type . Basic Types
reader: StringReaderSystem.IO.StringReaderImplements a that reads from a string.
output: StringWriterSystem.IO.StringWriterImplements a for writing information to a string. The information is stored in an underlying .
error: StringWriterinputEncoding: Text.EncodingTextUTF8: Text.EncodingGets an encoding for the UTF-8 format. An encoding for the UTF-8 format.
System.Text.EncodingRepresents a character encoding.
outputEncoding: Text.Encodingforeground: ConsoleColorSystem.ConsoleColorSpecifies constants that define foreground and background colors for the console.
Gray: ConsoleColorThe color gray.
background: ConsoleColorBlack: ConsoleColorThe color black.
cursorLeft: intcursorTop: intcursorVisible: booltitle: stringtreatControlC: bool_: RecordingConsoleWritten: RecordingConsole -> unit -> stringToString: unit -> stringReturns a string containing the characters written to the current so far. The string containing the characters written to the current .
IsCursorVisible: RecordingConsole -> unit -> boolAxial.Console.IConsoleProvides explicit access to standard console and terminal I/O.
In: RecordingConsole -> unit -> TextReaderOut: RecordingConsole -> unit -> TextWriterError: RecordingConsole -> unit -> TextWriterInputEncoding: RecordingConsole -> unit -> Text.Encodingvalue: Text.EncodingOutputEncoding: RecordingConsole -> unit -> Text.EncodingIsInputRedirected: RecordingConsole -> unit -> boolIsOutputRedirected: RecordingConsole -> unit -> boolIsErrorRedirected: RecordingConsole -> unit -> boolKeyAvailable: RecordingConsole -> unit -> boolRead: RecordingConsole -> unit -> intRead: unit -> intReads the next character from the input string and advances the character position by one character. The next character from the underlying string, or -1 if no more characters are available. The current reader is closed.
ReadLine: RecordingConsole -> unit -> stringReadLine: unit -> stringReads a line of characters from the current string and returns the data as a string. The next line from the current string, or if the end of the string is reached. The current reader is closed. There is insufficient memory to allocate a buffer for the returned string.
ReadKey: RecordingConsole -> bool -> ConsoleKeyInfo``.ctor``: unitWrite: RecordingConsole -> string -> unitvalue: stringWrite: string -> unitWrites a string to the current string. The string to write. The writer is closed.
WriteLine: RecordingConsole -> string -> unitWriteLine: string -> unitWrites a string to the text stream, followed by a line terminator. The string to write. If is , only the line terminator is written. The is closed. An I/O error occurs.
WriteError: RecordingConsole -> string -> unitWriteErrorLine: RecordingConsole -> string -> unitOpenStandardInput: RecordingConsole -> unit -> StreamSystem.IO.StreamProvides a generic view of a sequence of bytes. This is an abstract class.
Null: StreamA with no backing store.
OpenStandardOutput: RecordingConsole -> unit -> StreamOpenStandardError: RecordingConsole -> unit -> StreamClear: RecordingConsole -> unit -> unitBeep: RecordingConsole -> unit -> unitResetColor: RecordingConsole -> unit -> unitForegroundColor: RecordingConsole -> unit -> ConsoleColorvalue: ConsoleColorBackgroundColor: RecordingConsole -> unit -> ConsoleColorCursorLeft: RecordingConsole -> unit -> intvalue: intCursorTop: RecordingConsole -> unit -> intCursorVisible: RecordingConsole -> unit -> boolvalue: boolSetCursorPosition: RecordingConsole -> int * int -> unitleft: inttop: intTitle: RecordingConsole -> unit -> stringTreatControlCAsInput: RecordingConsole -> unit -> boolRequires & types
Requires: open Axial.Console; open System; open System.IO (packages: Axial.Console)It reads its input from a string, records what is written, and keeps terminal state in fields:
type AppEnv =
{ Console: IConsole }
interface IHasConsole with
member this.Console = this.Console
let confirm question : Flow<AppEnv, Never, bool> =
flow {
do! Console.write $"{question} [y/N] "
let! answer = Console.readLine
return
match answer with
| null -> false
| value -> value.Trim().ToLowerInvariant() = "y"
}
FsLiveDocsGeneratedPage13_10B692608C6D.AppEnvConsole: IConsoleAxial.Console.IConsoleProvides explicit access to standard console and terminal I/O.
Axial.Console.IHasConsoleDeclares that an environment supplies the console service. Implement this on the environment supplied at the host edge. A workflow that reads or writes the console constrains its environment with 'env :> IHasConsole.
this: AppEnvConsole: AppEnv -> unit -> IConsoleconfirm: 'a -> Flow<AppEnv,Never,bool>question: 'aAxial.Flow`3Axial.NeverRepresents an error channel that cannot occur.
boolAn abbreviation for the CLI type . Basic Types
flow: FlowBuilderThe universal flow { } computation expression.
Axial.Console.ConsoleModulewrite: string -> Flow<'env,'error,unit>answer: stringreadLine: Flow<'env,'error,string>value: StringTrim: unit -> stringRemoves all leading and trailing white-space characters from the current object. The string that remains after all white-space characters are removed from the start and end of the current string. If no characters can be trimmed from the current instance, the method returns the current instance unchanged.
ToLowerInvariant: unit -> stringReturns a copy of this object converted to lowercase using the casing rules of the invariant culture. The lowercase equivalent of the current string.
(=): 'T -> 'T -> boolStructural equality The first parameter. The second parameter. The result of the comparison. 5 = 5 // Evaluates to true 5 = 6 // Evaluates to false [1; 2] = [1; 2] // Evaluates to true (1, 5) = (1, 6) // Evaluates to false
Requires & types
Requires: open Axial; open Axial.Console (packages: Axial, Axial.Console)val confirm: 'a -> Flow<AppEnv,Never,bool>let answeredYes = RecordingConsole "y\n"
confirm "Continue?" |> Flow.run { Console = answeredYes } |> shouldEqual (Exit.Success true)
answeredYes.Written |> shouldEqual "Continue? [y/N] "
let answeredEof = RecordingConsole ""
confirm "Continue?" |> Flow.run { Console = answeredEof } |> shouldEqual (Exit.Success false)
answeredYes: RecordingConsole``.ctor``: string -> RecordingConsoleconfirm: 'a -> Flow<AppEnv,Never,bool>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Flowrun: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
Console: IConsoleshouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
Written: stringansweredEof: RecordingConsoleRequires & types
Requires: open Axial (packages: Axial)val answeredYes: RecordingConsoleval answeredEof: RecordingConsoleRead the console guide for the service's usage; this fake exercises it without a terminal.

