Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit ad8665c

Browse files
Merge pull request #2 from sheridanchris/cross-platform
Only call win32 apis on windows
2 parents ccf49c3 + de9d471 commit ad8665c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Fargo/Console.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module Fargo.Console
2+
23
open System
4+
open System.Runtime.InteropServices
35

46
module Native =
5-
open System.Runtime.InteropServices
6-
77
let STD_OUTPUT_HANDLE = -11
88
let ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4u
99
let DISABLE_NEWLINE_AUTO_RETURN = 8u
@@ -15,8 +15,8 @@ module Native =
1515
[<DllImport("kernel32.dll", SetLastError=true)>]
1616
extern bool SetConsoleMode(IntPtr hConsoleHandle, uint32 dwMode )
1717

18-
19-
let supportVT100 =
18+
19+
let checkWin32VT100 () =
2020
let h = Native.GetStdHandle(Native.STD_OUTPUT_HANDLE)
2121
let mutable x = 0u
2222
let r = Native.GetConsoleMode(h, &x)
@@ -28,6 +28,11 @@ let supportVT100 =
2828
let r = Native.SetConsoleMode(h, x ||| Native.ENABLE_VIRTUAL_TERMINAL_PROCESSING ||| Native.DISABLE_NEWLINE_AUTO_RETURN)
2929
r
3030

31+
let supportVT100 =
32+
RuntimeInformation.IsOSPlatform OSPlatform.Linux ||
33+
RuntimeInformation.IsOSPlatform OSPlatform.OSX ||
34+
checkWin32VT100 ()
35+
3136
module Colors =
3237
let esc = "\x1B"
3338
let color n = if supportVT100 then $"{esc}[%d{n}m" else ""

tests/Fargo.Test/AllAtOnce.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ let ``completion of command on a full token in the middle``() =
227227
complete2 12 "voice select --voice funny"
228228
=! "select"
229229

230-
231-
232-
230+
[<Fact>]
231+
let ``test cross platform support`` () =
232+
let ex = Record.Exception(Action(fun () -> ignore Console.supportVT100))
233+
Assert.Null(ex)

0 commit comments

Comments
 (0)