Shorten the bandmap hover text to frequency, spotter, age and comment
The first line reads "14025.0 by K1TTT, 41m ago". The comment follows on a second line and is left out when it is only LSB, USB or SSB. Control characters are removed from the comment: cluster lines end in bell and carriage-return characters, which the tooltip drew as boxes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,23 +2,38 @@ using System.Globalization;
|
||||
|
||||
namespace Nonemm.Spotting;
|
||||
|
||||
/// What the bandmap shows when the pointer rests on a spot: who spotted it,
|
||||
/// when, and the comment they sent.
|
||||
/// What the bandmap shows when the pointer rests on a spot: the frequency,
|
||||
/// who spotted it and how long ago, and the comment if it says more than the
|
||||
/// sideband.
|
||||
public static class SpotDescription
|
||||
{
|
||||
public static string Of(Spot spot)
|
||||
public static string Of(Spot spot, DateTime? nowUtc = null)
|
||||
{
|
||||
string time = spot.AtUtc.ToString("HH:mm", CultureInfo.InvariantCulture);
|
||||
string age = Age((nowUtc ?? DateTime.UtcNow) - spot.AtUtc);
|
||||
string kilohertz = spot.Frequency.Kilohertz.ToString("0.0", CultureInfo.InvariantCulture);
|
||||
string who = spot.Spotter.Length > 0
|
||||
? $"Spotted by {spot.Spotter} at {time}Z"
|
||||
: spot.Source switch
|
||||
{
|
||||
SpotSource.Log => $"Worked at {time}Z",
|
||||
SpotSource.Operator => $"Spotted here at {time}Z",
|
||||
_ => $"Spotted at {time}Z",
|
||||
};
|
||||
string text = $"{spot.Call.Text} {kilohertz}\n{who}";
|
||||
return spot.Comment.Trim().Length > 0 ? $"{text}\n{spot.Comment.Trim()}" : text;
|
||||
string first = spot.Spotter.Length > 0
|
||||
? $"{kilohertz} by {spot.Spotter}, {age}"
|
||||
: $"{kilohertz}, {age}";
|
||||
string comment = Comment(spot.Comment);
|
||||
return comment.Length > 0 ? $"{first}\n{comment}" : first;
|
||||
}
|
||||
|
||||
private static string Age(TimeSpan span)
|
||||
{
|
||||
int minutes = Math.Max(0, (int)span.TotalMinutes);
|
||||
return minutes switch
|
||||
{
|
||||
< 60 => $"{minutes}m ago",
|
||||
_ => $"{minutes / 60}h {minutes % 60}m ago",
|
||||
};
|
||||
}
|
||||
|
||||
/// Cluster lines end in bell and carriage-return characters, which a
|
||||
/// tooltip draws as boxes, so control characters are dropped.
|
||||
private static string Comment(string text)
|
||||
{
|
||||
string clean = new([.. text.Where(c => !char.IsControl(c))]);
|
||||
clean = clean.Trim();
|
||||
return clean.ToUpperInvariant() is "LSB" or "USB" or "SSB" ? "" : clean;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user