Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
mivano committed Sep 24, 2023
1 parent f3f6f08 commit 2899636
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/CostApi/AzureCostApiRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private async Task RetrieveToken(bool includeDebugOutput)
if (_tokenRetrieved)
return;

// Get the token by using the DefaultAzureCredential
// Get the token by using the DefaultAzureCredential, but try the AzureCliCredential first
var tokenCredential = new ChainedTokenCredential(
new AzureCliCredential(),
new DefaultAzureCredential());
Expand Down
19 changes: 8 additions & 11 deletions src/OutputFormatters/SpectreConsole/Money.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ namespace AzureCostCli.OutputFormatters.SpectreConsole;
public class Money : Renderable
{
private readonly Markup _paragraph;

public Money(double amount, string currency, Style? style = null, Justify justify = Justify.Right)
{

_paragraph = new Markup(FormatMoney(amount, currency), style)
{
Justification = justify
Expand All @@ -25,24 +24,22 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid

public static string FormatMoney(double amount, string currency)
{

// Get current culture info
// Get current culture info
var cultureInfo = CultureInfo.CurrentCulture;
// Get culture specific decimal separator
// Get culture specific decimal separator
var decimalSeparator = cultureInfo.NumberFormat.NumberDecimalSeparator;
// Get culture specific thousand separator
// Get culture specific thousand separator
var thousandSeparator = cultureInfo.NumberFormat.NumberGroupSeparator;

// Split the amount into integer and fraction parts
// Split the amount into integer and fraction parts
var amountParts = amount.ToString("N2", cultureInfo).Split(decimalSeparator);
string amountInteger = amountParts[0];
string amountFraction = amountParts.Length > 1 ? amountParts[1] : "00";

// Prepare styled string
string styledAmount = $"[bold dim]{amountInteger}[/]{decimalSeparator}[dim]{amountFraction}[/] [green]{currency}[/]";
// Prepare styled string
string styledAmount =
$"[bold dim]{amountInteger}[/]{decimalSeparator}[dim]{amountFraction}[/] [green]{currency}[/]";

return styledAmount;

}

}

0 comments on commit 2899636

Please sign in to comment.