|
|
|
|
using SCI.CursesWrapper;
|
|
|
|
|
using SCI.CursesWrapper.UiElements;
|
|
|
|
|
using Fahrplan.Screens;
|
|
|
|
|
using Mindmagma.Curses;
|
|
|
|
|
using Fahrplan.Plan;
|
|
|
|
|
|
|
|
|
|
namespace Fahrplan;
|
|
|
|
|
|
|
|
|
|
class Program {
|
|
|
|
|
private static void Main (string [] args) {
|
|
|
|
|
/**
|
|
|
|
|
* General procedure:
|
|
|
|
|
* - Draw welcome screen
|
|
|
|
|
* - User picks the view they want to see
|
|
|
|
|
* - Data is being pulled from server
|
|
|
|
|
* - Data is being read, processed and displayed in the selected view
|
|
|
|
|
* - User can scroll up and down with Up and Down the view if it is longer than one page
|
|
|
|
|
* - User can change date, room, speaker etc. by pressing left and right
|
|
|
|
|
* - User can change the list type with function keys
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
var screen = CursesWrapper.InitNCurses ();
|
|
|
|
|
|
|
|
|
|
// -- Screen-wide input handler -- //
|
|
|
|
|
var inputHandler = new InputHandler ();
|
|
|
|
|
inputHandler.StartListening ();
|
|
|
|
|
|
|
|
|
|
// Register global quit key
|
|
|
|
|
inputHandler.OnKeyPressPrivileged += (object sender, NCursesKeyPressEventArgs e) => {
|
|
|
|
|
if (!CursesWrapper.KeyPressIsCtrl (e.KeyCode, 'q')) return;
|
|
|
|
|
|
|
|
|
|
NCurses.EndWin ();
|
|
|
|
|
Console.WriteLine ("Bye-bye!");
|
|
|
|
|
Environment.Exit (0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// -- Content Window -- //
|
|
|
|
|
//
|
|
|
|
|
// This window contains all the dynamic content between
|
|
|
|
|
// the menu and status bars
|
|
|
|
|
var contentWindow = new ContentWindow (screen, inputHandler) {
|
|
|
|
|
BorderEnabled = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// -- Intro screen -- //
|
|
|
|
|
var introScreen = new IntroScreen (contentWindow);
|
|
|
|
|
introScreen.RegisterInputHandler (inputHandler);
|
|
|
|
|
introScreen.SetWindowActive ();
|
|
|
|
|
|
|
|
|
|
// Whilst the intro screen is shown, get the Fahrplan
|
|
|
|
|
var fahrplan = Network.PlanPuller.GetFahrplanAsync ().Result;
|
|
|
|
|
|
|
|
|
|
// Wait until intro screen is closed
|
|
|
|
|
while (introScreen.WindowId > -1) Thread.Sleep (50); // TODO; Unjank this
|
|
|
|
|
introScreen = null;
|
|
|
|
|
|
|
|
|
|
// -- Create footer bar -- //
|
|
|
|
|
var footerWindow = new FooterWindow (screen);
|
|
|
|
|
footerWindow.DrawFooter ("Fahrplan", "LLLeft", "RRRRRight");
|
|
|
|
|
|
|
|
|
|
// -- Create menu bar -- //
|
|
|
|
|
var menuItems = CreateMenuItems (contentWindow, footerWindow, fahrplan.schedule.conference);
|
|
|
|
|
var topMenu = new TopMenu (screen, inputHandler, menuItems);
|
|
|
|
|
topMenu.ActivateItem (topMenu.MenuItems [1]);
|
|
|
|
|
|
|
|
|
|
// Wait until the input handler routine stops
|
|
|
|
|
while (inputHandler.IsListening ()) Thread.Sleep (50);
|
|
|
|
|
|
|
|
|
|
NCurses.EndWin ();
|
|
|
|
|
Console.WriteLine ("Oh wow, the input handler crashed, that's not supposed to happen. Sorry!");
|
|
|
|
|
Environment.Exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<MenuItem> CreateMenuItems (
|
|
|
|
|
ContentWindow contentWindow,
|
|
|
|
|
FooterWindow footer,
|
|
|
|
|
Plan.Conference planConference
|
|
|
|
|
) {
|
|
|
|
|
var helpItem = new MenuItem ("Help", "F1");
|
|
|
|
|
var upcomingItem = new MenuItem ("Upcoming", "u");
|
|
|
|
|
var byDayItem = new MenuItem ("By Day", "d");
|
|
|
|
|
var byRoomItem = new MenuItem ("By Room", "r");
|
|
|
|
|
var bySpeakerItem = new MenuItem ("By Speaker", "s");
|
|
|
|
|
var quitItem = new MenuItem ("Quit (C-q)");
|
|
|
|
|
|
|
|
|
|
helpItem.OnItemActivated += (object sender, MenuItemActivatedEventArgs e) => {
|
|
|
|
|
var scrollWindow = contentWindow.CreateInnerScrollWindow ();
|
|
|
|
|
for (int i = 0; i <= 100; i++)
|
|
|
|
|
scrollWindow.AddContent ($"Line {i} {AsciiArt.lorem_ipsum}\n");
|
|
|
|
|
scrollWindow.RenderCurrentViewport ();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
upcomingItem.OnItemActivated += (object sender, MenuItemActivatedEventArgs e) => {
|
|
|
|
|
var scrollWindow = contentWindow.CreateInnerScrollWindow ();
|
|
|
|
|
scrollWindow.AddContent ("-- Upcoming --");
|
|
|
|
|
|
|
|
|
|
scrollWindow.RenderCurrentViewport ();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
byRoomItem.OnItemActivated += (object sender, MenuItemActivatedEventArgs e) => {
|
|
|
|
|
var scrollWindow = contentWindow.CreateInnerScrollWindow ();
|
|
|
|
|
footer.DrawFooter (" Day 1 ->");
|
|
|
|
|
|
|
|
|
|
// TODO: Do the actual foo-magic of formatting the plan as a nice text table
|
|
|
|
|
// and key handling to switch between days
|
|
|
|
|
foreach (var day in planConference.days) {
|
|
|
|
|
scrollWindow.AddContent (DateTime.Parse (day.date).ToString ("dd.MM.yyyy") + $" (Day {day.index})");
|
|
|
|
|
foreach (var room in day.rooms) {
|
|
|
|
|
scrollWindow.AddContent ($"- {room.Key}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scrollWindow.RenderCurrentViewport ();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new List<MenuItem> {
|
|
|
|
|
helpItem,
|
|
|
|
|
upcomingItem,
|
|
|
|
|
byDayItem,
|
|
|
|
|
byRoomItem,
|
|
|
|
|
bySpeakerItem,
|
|
|
|
|
quitItem
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|