You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
3.8 KiB
66 lines
3.8 KiB
using Mindmagma.Curses;
|
|
|
|
namespace Fahrplan;
|
|
|
|
public class AsciiArt {
|
|
/// <summary>
|
|
/// Shows ASCII art centered vertically and horizontally on screen
|
|
/// </summary>
|
|
/// <param name="window">Window to print the ASCII art to</param>
|
|
/// <param name="asciiArt">ASCII art string</param>
|
|
/// <param name="altText">Text to show if the ASCII art does not fit the window</param>
|
|
public static void ShowCentered (nint window, string asciiArt, string altText = "failed_ascii_render") {
|
|
int longestLine = 0;
|
|
|
|
// Capture each line as seperate string in list for easier iteration later
|
|
var lines = new List<string> ();
|
|
|
|
// Find the longest line of the specified ASCII art
|
|
using StringReader strReader = new StringReader (asciiArt);
|
|
string? line;
|
|
while ((line = strReader.ReadLine ()) is not null) {
|
|
lines.Add (line);
|
|
if (line.Length > longestLine) longestLine = line.Length;
|
|
}
|
|
|
|
int amountLines = lines.Count;
|
|
|
|
// Get window geometry
|
|
NCurses.GetMaxYX (window, out int height, out int width);
|
|
|
|
int centerX = width / 2;
|
|
int centerY = height / 2;
|
|
|
|
// Show alt text if ASCII art is too big for window
|
|
if (longestLine > width || amountLines > height) {
|
|
int textBeginX = centerX - (altText.Length / 2);
|
|
NCurses.MoveWindowAddString (window, centerY, textBeginX, altText);
|
|
NCurses.Refresh ();
|
|
NCurses.WindowRefresh (window);
|
|
return;
|
|
}
|
|
|
|
int textCurrentY = centerY - (amountLines / 2);
|
|
|
|
foreach (string strline in lines) {
|
|
int textBeginX = centerX - (strline.Length / 2);
|
|
NCurses.MoveWindowAddString (window, textCurrentY, textBeginX, strline);
|
|
|
|
textCurrentY ++;
|
|
}
|
|
|
|
NCurses.Refresh ();
|
|
NCurses.WindowRefresh (window);
|
|
}
|
|
|
|
public static string lorem_ipsum { get {
|
|
return
|
|
@"
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer euismod in sapien id rhoncus. Suspendisse potenti. Nam bibendum risus lobortis mollis commodo. Donec ac ante nec augue vestibulum consequat. In condimentum id nisl sed placerat. Suspendisse rhoncus lectus a risus sollicitudin accumsan. Quisque semper dui a erat aliquet, ac venenatis felis blandit. In id eros quis tellus condimentum luctus et sit amet enim. Aliquam malesuada erat augue, in euismod libero rhoncus quis. Nam augue sapien, pellentesque quis congue ac, semper nec nisl. Donec accumsan vitae justo ac volutpat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus in dictum ipsum. Nunc venenatis egestas metus id maximus. Aliquam erat volutpat.
|
|
|
|
Fusce vitae tortor a tortor hendrerit condimentum quis non libero. Proin eget dignissim neque. Aliquam ac justo tempus, semper diam eget, finibus eros. Nullam elementum odio ante, eu volutpat sapien aliquet quis. Nulla eget volutpat lorem. Sed feugiat est vel tellus sodales, ac mollis libero faucibus. Vestibulum auctor dapibus quam, eu efficitur dolor feugiat id. Vestibulum tincidunt maximus arcu. Integer a urna posuere sapien efficitur tincidunt ut nec nibh. Etiam eu ultrices metus, in pretium leo. Duis egestas arcu quis tristique pretium. Maecenas dapibus enim vel quam malesuada elementum. Fusce vulputate mollis fringilla. Nullam fermentum magna velit, ac pharetra ante viverra ac.
|
|
|
|
In at urna ut dui pretium elementum et a nunc. Aliquam non rutrum velit, vitae mollis justo. Etiam tempus, odio ac finibus semper, ipsum turpis pretium dolor, maximus volutpat metus ante sed ligula. Phasellus interdum odio at tempor consectetur. Curabitur sit amet semper enim, vel sagittis urna. Integer sit amet nulla quis nisi sagittis consectetur fringilla eu diam. Nam lacinia libero eu ornare placerat. Nunc lacinia lacus felis, at efficitur tortor euismod non. Donec eget mi maximus, suscipit dolor sed, sagittis tortor. Proin nec consectetur lectus. Cras vulputate tempus ante at tristique. Morbi eu sodales lorem. Etiam eget pharetra ex. Donec in dictum sem.
|
|
";
|
|
}}
|
|
} |