Skip to content

Commit

Permalink
(chocolateyGH-181) Same-line short prompts input
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Rondeau committed Mar 25, 2015
1 parent 616033b commit c738ce1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure/adapters/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace chocolatey.infrastructure.adapters

public sealed class Console : IConsole
{
public void Write(string value)
{
System.Console.Write(value);
}

public string ReadLine()
{
return System.Console.ReadLine();
Expand Down
6 changes: 6 additions & 0 deletions src/chocolatey/infrastructure/adapters/IConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace chocolatey.infrastructure.adapters

public interface IConsole
{
/// <summary>
/// Writes the specified string value to the standard output stream.
/// </summary>

This comment has been minimized.

Copy link
@ferventcoder

ferventcoder Mar 29, 2015

Looks like a copying issue from .NET framework?

This comment has been minimized.

Copy link
@christianrondeau

christianrondeau Mar 29, 2015

Owner

Correct; that's what I thought was the intent when I looked at the ReadLine method below. It would indeed be wise not to do this... I can just remove the comment, should I do the same for ReadLine?

/// <param name="value">The value to write. </param><exception cref="T:System.IO.IOException">An I/O error occurred. </exception><filterpriority>1</filterpriority>
void Write(string value);

/// <summary>
/// Reads the next line of characters from the standard input stream.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ public static string prompt_for_confirmation_short(string prompt, IEnumerable<st
c => c.Select(entry => entry.FirstOrDefault()).Distinct().Count() == c.Count(),
(name, value) => { throw new ApplicationException("Multiple choices have the same first letter. Please ensure you pass choices with different first letters."); });

"chocolatey".Log().Info(ChocolateyLoggers.Important, "{0} ({1}): ".format_with(prompt, String.Join("/", choices)));

var promptWithChoices = "{0} ({1}): ".format_with(prompt, String.Join("/", choices));

Console.Write(promptWithChoices);
var selection = Console.ReadLine();

"chocolatey".Log().Info(ChocolateyLoggers.LogFileOnly, "{0}{1}".format_with(promptWithChoices, selection));

// check to see if value was passed
foreach (var choice in choices)
{
Expand Down
2 changes: 2 additions & 0 deletions src/chocolatey/infrastructure/logging/ChocolateyLoggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public enum ChocolateyLoggers
Normal,
Verbose,
Important,
// Used to output prompt results in log file, but not in the console
LogFileOnly,
}
}
4 changes: 4 additions & 0 deletions src/chocolatey/infrastructure/logging/log4net.config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
<appender-ref ref="VerboseLoggingColoredConsoleAppender" />
</logger>

<logger name="LogFileOnly">
<level value="INFO" />
</logger>

<logger name="chocolatey">
<level value="INFO"/>
<appender-ref ref="NormalLoggingColoredConsoleAppender" />
Expand Down

0 comments on commit c738ce1

Please sign in to comment.