Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Fargo/Console.fs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,8 @@ module Native =
[<DllImport("kernel32.dll", SetLastError=true)>]
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)
Expand All @@ -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 ""
Expand Down
7 changes: 4 additions & 3 deletions tests/Fargo.Test/AllAtOnce.fs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ let ``completion of command on a full token in the middle``() =
complete2 12 "voice select --voice funny"
=! "select"




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