diff --git a/src/Fargo/Console.fs b/src/Fargo/Console.fs index 6ed7b58..34b6235 100644 --- a/src/Fargo/Console.fs +++ b/src/Fargo/Console.fs @@ -1,9 +1,9 @@ module Fargo.Console + open System +open System.Runtime.InteropServices module Native = - open System.Runtime.InteropServices - let STD_OUTPUT_HANDLE = -11 let ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4u let DISABLE_NEWLINE_AUTO_RETURN = 8u @@ -15,8 +15,8 @@ module Native = [] extern bool SetConsoleMode(IntPtr hConsoleHandle, uint32 dwMode ) - -let supportVT100 = + +let checkWin32VT100 () = let h = Native.GetStdHandle(Native.STD_OUTPUT_HANDLE) let mutable x = 0u let r = Native.GetConsoleMode(h, &x) @@ -28,6 +28,11 @@ let supportVT100 = let r = Native.SetConsoleMode(h, x ||| Native.ENABLE_VIRTUAL_TERMINAL_PROCESSING ||| Native.DISABLE_NEWLINE_AUTO_RETURN) r +let supportVT100 = + RuntimeInformation.IsOSPlatform OSPlatform.Linux || + RuntimeInformation.IsOSPlatform OSPlatform.OSX || + checkWin32VT100 () + module Colors = let esc = "\x1B" let color n = if supportVT100 then $"{esc}[%d{n}m" else "" diff --git a/tests/Fargo.Test/AllAtOnce.fs b/tests/Fargo.Test/AllAtOnce.fs index 1c36477..e676b53 100644 --- a/tests/Fargo.Test/AllAtOnce.fs +++ b/tests/Fargo.Test/AllAtOnce.fs @@ -227,6 +227,7 @@ let ``completion of command on a full token in the middle``() = complete2 12 "voice select --voice funny" =! "select" - - - +[] +let ``test cross platform support`` () = + let ex = Record.Exception(Action(fun () -> ignore Console.supportVT100)) + Assert.Null(ex)