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

Commit ef62689

Browse files
committed
Only call win32 apis on windows
1 parent ccf49c3 commit ef62689

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Fargo/Console.fs

Lines changed: 10 additions & 5 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,9 +15,9 @@ module Native =
1515
[<DllImport("kernel32.dll", SetLastError=true)>]
1616
extern bool SetConsoleMode(IntPtr hConsoleHandle, uint32 dwMode )
1717

18-
19-
let supportVT100 =
20-
let h = Native.GetStdHandle(Native.STD_OUTPUT_HANDLE)
18+
19+
let checkWin32VT100 () =
20+
let h = Native.GetStdHandle(Native.STD_OUTPUT_HANDLE)
2121
let mutable x = 0u
2222
let r = Native.GetConsoleMode(h, &x)
2323
if not r then
@@ -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 ""

0 commit comments

Comments
 (0)