diff --git a/src/ShellProgressBar/ProgressBar.cs b/src/ShellProgressBar/ProgressBar.cs
index 4262541..4198c0f 100644
--- a/src/ShellProgressBar/ProgressBar.cs
+++ b/src/ShellProgressBar/ProgressBar.cs
@@ -147,6 +147,10 @@ private static void CondensedProgressBar(
var truncatedMessage = StringExtensions.Excerpt(message, messageWidth - 2) + " ";
var width = (Console.WindowWidth - (depth * 2) + 2) - truncatedMessage.Length;
+ if (!string.IsNullOrWhiteSpace(ProgressBarOptions.ProgressMessageEncodingName))
+ {
+ width = width + message.Length - System.Text.Encoding.GetEncoding(ProgressBarOptions.ProgressMessageEncodingName).GetBytes(message).Length;
+ }
var newWidth = (int) ((width * percentage) / 100d);
var progBar = new string(progressCharacter, newWidth);
@@ -180,6 +184,10 @@ private static void ProgressBarBottomHalf(double percentage, DateTime startDate,
var column1Width = Console.WindowWidth - durationString.Length - (depth * 2) + 2;
var column2Width = durationString.Length;
+ if (!string.IsNullOrWhiteSpace(ProgressBarOptions.ProgressMessageEncodingName))
+ {
+ column1Width = column1Width + message.Length - System.Text.Encoding.GetEncoding(ProgressBarOptions.ProgressMessageEncodingName).GetBytes(message).Length;
+ }
if (progressBarOnBottom)
DrawTopHalfPrefix(indentation, depth);
diff --git a/src/ShellProgressBar/ProgressBarOptions.cs b/src/ShellProgressBar/ProgressBarOptions.cs
index 6fed7f0..d13a4b1 100644
--- a/src/ShellProgressBar/ProgressBarOptions.cs
+++ b/src/ShellProgressBar/ProgressBarOptions.cs
@@ -11,6 +11,20 @@ public class ProgressBarOptions
private bool _enableTaskBarProgress;
public static readonly ProgressBarOptions Default = new ProgressBarOptions();
+ public static string ProgressMessageEncodingName { get; set; }
+
+ public string MessageEncodingName
+ {
+ get
+ {
+ return ProgressMessageEncodingName;
+ }
+ set
+ {
+ ProgressMessageEncodingName = value;
+ }
+ }
+
/// The foreground color of the progress bar, message and time
public ConsoleColor ForegroundColor { get; set; } = ConsoleColor.Green;
@@ -83,7 +97,7 @@ public bool EnableTaskBarProgress
}
///
- /// Take ownership of writing a message that is intended to be displayed above the progressbar.
+ /// Take ownership of writing a message that is intended to be displayed above the progressbar.
/// The delegate is expected to return the number of messages written to the console as a result of the string argument.
/// Use case: pretty print or change the console colors, the progressbar will reset back
///