Skip to content

Commit

Permalink
added foreground and background color for the question text in the Ye…
Browse files Browse the repository at this point in the history
…sNoQuestion control.
  • Loading branch information
lastunicorn committed Jan 4, 2020
1 parent 64ae1fa commit 33e8074
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
30 changes: 30 additions & 0 deletions sources/ConsoleTools/ConsoleTools/InlineControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public abstract class InlineControl : Control
/// </summary>
public int MarginRight { get; set; }

/// <summary>
/// Gets or sets the number of spaces to be written before the content (to the left).
/// Default value: 0
/// </summary>
public int PaddingLeft { get; set; }

/// <summary>
/// Gets or sets the number of spaces to be written after the content (to the right).
/// Default value: 0
/// </summary>
public int PaddingRight { get; set; }

/// <summary>
/// Gets or sets the foreground color used to write the text.
/// Default value: <c>null</c>
Expand All @@ -61,8 +73,14 @@ protected override void DoDisplay()
if (MarginLeft > 0)
DisplayLeftMargin();

if (PaddingLeft > 0)
DisplayPaddingLeft();

DoDisplayContent();

if (PaddingRight > 0)
DisplayPaddingRight();

if (MarginRight > 0)
DisplayRightMargin();
}
Expand All @@ -79,6 +97,18 @@ private void DisplayRightMargin()
Console.Write(space);
}

private void DisplayPaddingLeft()
{
string paddingLeft = new string(' ', PaddingLeft);
WriteText(paddingLeft);
}

private void DisplayPaddingRight()
{
string paddingRight = new string(' ', PaddingRight);
WriteText(paddingRight);
}

/// <summary>
/// When implemented in a derived class, it displays the content of the control.
/// This method is not responsible to display the margins.
Expand Down
40 changes: 32 additions & 8 deletions sources/ConsoleTools/ConsoleTools/InputControls/YesNoQuestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ namespace DustInTheWind.ConsoleTools.InputControls
/// </summary>
public class YesNoQuestion : BlockControl
{
private readonly Label labelControl = new Label
{
ForegroundColor = CustomConsole.EmphasiesColor
};

/// <summary>
/// Gets or sets trhe question that is displayed to the user.
/// </summary>
public string QuestionText { get; set; }

/// <summary>
/// Gets or sets the foreground color used for displaying the question.
/// </summary>
public ConsoleColor? QuestionForegroundColor { get; set; } = CustomConsole.EmphasiesColor;

/// <summary>
/// Gets or sets the background color used for displaying the question.
/// </summary>
public ConsoleColor? QuestionBackgroundColor { get; set; }

/// <summary>
/// Gets or sets the number of spaces to be displayed after the question and the before the user types the answer.
/// Default value: 1
Expand Down Expand Up @@ -161,14 +166,27 @@ protected override void DoDisplayContent(ControlDisplay display)

private void DisplayQuestion()
{
labelControl.Text = QuestionText;
InlineTextBlock labelControl = new InlineTextBlock
{
PaddingRight = 1,
ForegroundColor = QuestionForegroundColor ?? ForegroundColor,
BackgroundColor = QuestionBackgroundColor ?? BackgroundColor,
Text = QuestionText
};
labelControl.Display();
}

private void DisplaySpaceAfterQuestion()
{
string space = new string(' ', SpaceAfterQuestion);
Console.Write(space);

InlineTextBlock inlineTextBlock = new InlineTextBlock
{
Text = space,
ForegroundColor = ForegroundColor,
BackgroundColor = BackgroundColor
};
inlineTextBlock.Display();
}

/// <summary>
Expand Down Expand Up @@ -204,7 +222,13 @@ protected virtual void DisplayPossibleAnswersList()

sb.Append("]");

Console.Write(sb);
InlineTextBlock inlineTextBlock = new InlineTextBlock
{
Text = sb.ToString(),
ForegroundColor = ForegroundColor,
BackgroundColor = BackgroundColor
};
inlineTextBlock.Display();
}

private YesNoAnswer ReadAnswerInternal()
Expand Down

0 comments on commit 33e8074

Please sign in to comment.