-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1997 from nelak/release/next
Migrated UserInputHelper into Fake.Core.UserInput
- Loading branch information
Showing
9 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
group netcore | ||
|
||
NETStandard.Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters