Skip to content

Commit

Permalink
Merge pull request #1997 from nelak/release/next
Browse files Browse the repository at this point in the history
Migrated UserInputHelper into Fake.Core.UserInput
  • Loading branch information
matthid authored Jun 17, 2018
2 parents 79fdc8e + 484d28d commit 15b55d2
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 5 deletions.
17 changes: 16 additions & 1 deletion Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "template", "template", "{87
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "fake-template", "src\template\fake-template\fake-template.fsproj", "{29B66A06-1A45-4D65-AC31-7D746449E5D6}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.DotNet.Cli.IntegrationTests", "src\test\Fake.DotNet.Cli.IntegrationTests\Fake.DotNet.Cli.IntegrationTests.fsproj", "{48ECC58D-468C-4D44-98B3-854C21EB0D40}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.Cli.IntegrationTests", "src\test\Fake.DotNet.Cli.IntegrationTests\Fake.DotNet.Cli.IntegrationTests.fsproj", "{48ECC58D-468C-4D44-98B3-854C21EB0D40}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Core.UserInput", "src\app\Fake.Core.UserInput\Fake.Core.UserInput.fsproj", "{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -958,6 +960,18 @@ Global
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|x64.Build.0 = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|x86.ActiveCfg = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|x86.Build.0 = Release|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Debug|x64.ActiveCfg = Debug|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Debug|x64.Build.0 = Debug|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Debug|x86.ActiveCfg = Debug|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Debug|x86.Build.0 = Debug|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|Any CPU.Build.0 = Release|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|x64.ActiveCfg = Release|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|x64.Build.0 = Release|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|x86.ActiveCfg = Release|Any CPU
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1031,6 +1045,7 @@ Global
{872B282D-8A3E-459A-B63D-C43C5D73506D} = {539D7B9A-18A1-4D79-86AB-C8B48090CA84}
{29B66A06-1A45-4D65-AC31-7D746449E5D6} = {872B282D-8A3E-459A-B63D-C43C5D73506D}
{48ECC58D-468C-4D44-98B3-854C21EB0D40} = {E09B72E4-D890-46A8-8D14-7367C2E23E9D}
{3B0A5EE3-6696-4EBA-BCF9-8136C7F17040} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {058A0C5E-2216-4306-8AFB-0AE28320C26A}
Expand Down
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ let dotnetAssemblyInfos =
"Fake.Core.Target", "Defining and running Targets"
"Fake.Core.Tasks", "Repeating and managing Tasks"
"Fake.Core.Trace", "Core Logging functionality"
"Fake.Core.UserInput", "User input helpers"
"Fake.Core.Xml", "Core Xml functionality"
"Fake.Documentation.DocFx", "Documentation with DocFx"
"Fake.DotNet.AssemblyInfoFile", "Writing AssemblyInfo files"
Expand Down
1 change: 1 addition & 0 deletions help/templates/template.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<li><a href="/apidocs/v5/fake-core-taskrunner.html">Tasks</a></li>
<li><a href="/apidocs/v5/fake-core-releasenotes.html">ReleaseNotes</a></li>
<li><a href="/apidocs/v5/fake-core-changelog.html">ChangeLog</a></li>
<li><a href="/apidocs/v5/fake-core-userinput.html">UserInput</a></li>
</ul>
</li>
<li>
Expand Down
17 changes: 17 additions & 0 deletions src/app/Fake.Core.UserInput/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make User input helpers")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.1")>]
[<assembly: AssemblyInformationalVersionAttribute("5.1.0-alpha.1")>]
[<assembly: AssemblyFileVersionAttribute("5.1.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make User input helpers"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.1"
let [<Literal>] AssemblyInformationalVersion = "5.1.0-alpha.1"
let [<Literal>] AssemblyFileVersion = "5.1.0"
18 changes: 18 additions & 0 deletions src/app/Fake.Core.UserInput/Fake.Core.UserInput.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<AssemblyName>Fake.Core.UserInput</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);DOTNETCORE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="UserInput.fs" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
63 changes: 63 additions & 0 deletions src/app/Fake.Core.UserInput/UserInput.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace Fake.Core
open System

/// Helpers for capturing user input
///
/// ## Sample
///
/// UserInput.getUserInput prompt
[<RequireQualifiedAccess>]
module UserInput =
let internal erasePreviousChar () =
try
let left = if Console.CursorLeft <> 0 then Console.CursorLeft-1 else Console.BufferWidth-1
let top = if Console.CursorLeft <> 0 then Console.CursorTop else Console.CursorTop-1

Console.SetCursorPosition(left, top)
Console.Write(' ')
Console.SetCursorPosition(left, top)
with
| :? IO.IOException ->
// Console is dumb, might be redirected. We don't care,
// if it isn't a screen the visual feedback isn't required
()

let internal readString (echo: bool) : string =
let rec loop cs =
let key = Console.ReadKey(true)
match (key.Key, cs) with
| (ConsoleKey.Backspace, []) -> loop []
| (ConsoleKey.Backspace, _::cs) ->
erasePreviousChar ()
loop cs
| (ConsoleKey.Enter, _) -> cs
| _ ->
if echo then Console.Write(key.KeyChar) else Console.Write('*')
loop (key.KeyChar :: cs)

loop []
|> List.rev
|> Array.ofList
|> fun cs -> new String(cs)

let internal color (color: ConsoleColor) (code : unit -> _) =
let before = Console.ForegroundColor
try
Console.ForegroundColor <- color
code ()
finally
Console.ForegroundColor <- before


let getUserInput prompt =
color ConsoleColor.White (fun _ -> printf "%s" prompt)
let s = readString true
printfn ""
s


let getUserPassword prompt =
color ConsoleColor.White (fun _ -> printf "%s" prompt)
let s = readString false
printfn ""
s
3 changes: 3 additions & 0 deletions src/app/Fake.Core.UserInput/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group netcore

NETStandard.Library
5 changes: 4 additions & 1 deletion src/legacy/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
<Compile Include="..\..\app\Fake.Core.Target\TargetOperators.fs">
<Link>Fake.Core.Target/TargetOperators.fs</Link>
</Compile>
<Compile Include="..\..\app\Fake.Core.UserInput\UserInput.fs">
<Link>Fake.Core.UserInput/UserInput.fs</Link>
</Compile>
<Compile Include="..\..\app\Fake.DotNet.MSBuild\MSBuildLogger.fs">
<Link>Fake.DotNet.MSBuild/MSBuildLogger.fs</Link>
</Compile>
Expand Down Expand Up @@ -3393,4 +3396,4 @@
<Import Project="..\..\..\packages\runtime.win10-x86.Microsoft.Net.Native.Compiler\build\runtime.win10-x86.Microsoft.Net.Native.Compiler.targets" Condition="Exists('..\..\..\packages\runtime.win10-x86.Microsoft.Net.Native.Compiler\build\runtime.win10-x86.Microsoft.Net.Native.Compiler.targets')" Label="Paket" />
<Import Project="..\..\..\packages\runtime.win10-x86.Microsoft.Net.Native.SharedLibrary\build\runtime.win10-x86.Microsoft.Net.Native.SharedLibrary.targets" Condition="Exists('..\..\..\packages\runtime.win10-x86.Microsoft.Net.Native.SharedLibrary\build\runtime.win10-x86.Microsoft.Net.Native.SharedLibrary.targets')" Label="Paket" />
<Import Project="..\..\..\packages\runtime.win10-x86.Microsoft.Net.UWPCoreRuntimeSdk\build\runtime.win10-x86.Microsoft.Net.UWPCoreRuntimeSdk.targets" Condition="Exists('..\..\..\packages\runtime.win10-x86.Microsoft.Net.UWPCoreRuntimeSdk\build\runtime.win10-x86.Microsoft.Net.UWPCoreRuntimeSdk.targets')" Label="Paket" />
</Project>
</Project>
6 changes: 3 additions & 3 deletions src/legacy/FakeLib/UserInputHelper.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[<AutoOpen>]
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Core.UserInput module instead")>]
/// This module contains functions which allow to interactively input values
module Fake.UserInputHelper

Expand Down Expand Up @@ -46,15 +46,15 @@ let internal color (color: ConsoleColor) (code : unit -> _) =
Console.ForegroundColor <- before

/// Return a string entered by the user followed by enter. The input is echoed to the screen.
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Core.UserInput module instead")>]
let getUserInput prompt =
color ConsoleColor.White (fun _ -> printf "%s" prompt)
let s = readString true
printfn ""
s

/// Return a string entered by the user followed by enter. The input is replaced by '*' on the screen.
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Core.UserInput module instead")>]
let getUserPassword prompt =
color ConsoleColor.White (fun _ -> printf "%s" prompt)
let s = readString false
Expand Down

0 comments on commit 15b55d2

Please sign in to comment.