From 9adb3beba259883dd5dfb11da73a03d118fefe1c Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Tue, 20 Dec 2016 12:03:32 +0000 Subject: [PATCH] fix console width issue --- RELEASE_NOTES.md | 3 +++ src/Argu/ArgumentParser.fs | 4 +--- src/Argu/AssemblyInfo.fs | 8 ++++---- src/Argu/Utils.fs | 5 +++++ src/Argu/project.json | 2 +- tests/Argu.Tests/project.json | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f4c3c438..bb39ce47 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +### 3.6.1 +* Fix default character width issue in console apps. + ### 3.6.0 * Fix wordwrapping issue in usage strings. diff --git a/src/Argu/ArgumentParser.fs b/src/Argu/ArgumentParser.fs index d68f2506..0edfbaf5 100644 --- a/src/Argu/ArgumentParser.fs +++ b/src/Argu/ArgumentParser.fs @@ -89,8 +89,6 @@ and [] // memoize parser generation for given template type static let argInfoLazy = lazy(preComputeUnionArgInfo<'Template> ()) - static let getUsageWidth() = try min Console.WindowWidth 80 with _ -> 80 - let mkUsageString argInfo msgOpt = mkUsageString argInfo _programName false _usageStringCharacterWidth msgOpt |> StringExpr.build let (|ParserExn|_|) (e : exn) = @@ -109,7 +107,7 @@ and [] /// Text width used when formatting the usage string. Defaults to 80 chars. /// The implementation of IExiter used for error handling. Exception is default. new (?programName : string, ?helpTextMessage : string, ?usageStringCharacterWidth : int, ?errorHandler : IExiter) = - let usageStringCharacterWidth = match usageStringCharacterWidth with None -> getUsageWidth() | Some w -> w + let usageStringCharacterWidth = match usageStringCharacterWidth with None -> getDefaultCharacterWidth() | Some w -> w let programName = match programName with Some pn -> pn | None -> currentProgramName.Value let errorHandler = match errorHandler with Some e -> e | None -> new ExceptionExiter() :> _ new ArgumentParser<'Template>(argInfoLazy.Value, programName, helpTextMessage, usageStringCharacterWidth, errorHandler) diff --git a/src/Argu/AssemblyInfo.fs b/src/Argu/AssemblyInfo.fs index c9f06f15..a1b1dc56 100644 --- a/src/Argu/AssemblyInfo.fs +++ b/src/Argu/AssemblyInfo.fs @@ -2,10 +2,10 @@ namespace System open System.Reflection -[] -[] +[] +[] do () module internal AssemblyVersionInformation = - let [] AssemblyVersion = "3.6.0" - let [] AssemblyFileVersion = "3.6.0" + let [] AssemblyVersion = "3.6.1" + let [] AssemblyFileVersion = "3.6.1" diff --git a/src/Argu/Utils.fs b/src/Argu/Utils.fs index d54eb76c..3a165e89 100644 --- a/src/Argu/Utils.fs +++ b/src/Argu/Utils.fs @@ -297,6 +297,11 @@ type PrefixDictionary<'Value>(keyVals : seq) = else kresult <- keys.[maxPos] ; vresult <- values.[maxPos] ; true +/// Gets the default width of the current console window, +/// if available. +let getDefaultCharacterWidth() = + max (try Console.WindowWidth - 1 with _ -> 80) 80 + // Wordwrap implementation kindly provided by @forki let wordwrap (width:int) (inputText:string) = let breakLine (text:string) (pos:int) (max:int) = diff --git a/src/Argu/project.json b/src/Argu/project.json index d64e9b47..128e1724 100644 --- a/src/Argu/project.json +++ b/src/Argu/project.json @@ -1,5 +1,5 @@ { - "version": "3.6.0", + "version": "3.6.1", "buildOptions": { "debugType": "portable", "compilerName": "fsc", diff --git a/tests/Argu.Tests/project.json b/tests/Argu.Tests/project.json index 85130023..2d50fb09 100644 --- a/tests/Argu.Tests/project.json +++ b/tests/Argu.Tests/project.json @@ -1,5 +1,5 @@ { - "version": "3.6.0", + "version": "3.6.1", "buildOptions": { "debugType": "portable", "compilerName": "fsc",