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.

107 lines
3.5 KiB

using SCI.CursesWrapper;
using SCI.CursesWrapper.UiElements;
using ANSI_Fahrplan.Screens;
4 weeks ago
using Mindmagma.Curses;
4 weeks ago
using System.Reflection;
using Microsoft.Win32.SafeHandles;
4 weeks ago
namespace ANSI_Fahrplan;
class Program {
private static void Main (string [] args) {
4 weeks ago
/**
* 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 ();
4 weeks ago
4 weeks ago
// -- 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);
};
4 weeks ago
4 weeks ago
// -- Content Window -- //
//
// This window contains all the dynamic content between
// the menu and status bars
4 weeks ago
var contentWindow = new ContentWindow (screen, inputHandler) {
BorderEnabled = true
};
4 weeks ago
// -- Intro screen -- //
4 weeks ago
var introScreen = new IntroScreen (contentWindow);
introScreen.Draw ();
// Close intro screen on any keypress
introScreen.OnKeyPress += (object sender, NCursesKeyPressEventArgs e) => {
((Window) sender).Destroy ();
};
introScreen.RegisterInputHandler (inputHandler);
introScreen.SetWindowActive ();
// Wait until intro screen is closed
while (introScreen.WindowId > -1) Thread.Sleep (50); // TODO; Unjank this
// -- Create menu bar -- //
4 weeks ago
var topMenu = new TopMenu (screen, inputHandler, CreateMenuItems (contentWindow));
// Testing
var testwin = contentWindow.CreateInnerWindow ();
testwin.BackgroundColorId = ColorSchemes.TextInputField ();
NCurses.WindowAddString (testwin, "Hello World.");
contentWindow.Draw ();
4 weeks ago
// Wait until the input handler routine stops
while (inputHandler.IsListening ()) Thread.Sleep (50);
4 weeks ago
NCurses.EndWin ();
Console.WriteLine ("Oh wow, the input handler crashed, that's not supposed to happen. Sorry!");
Environment.Exit (1);
}
4 weeks ago
private static List<MenuItem> CreateMenuItems (ContentWindow contentWindow) {
var helpItem = new MenuItem ("Help", "F1");
var upcomingItem = new MenuItem ("Upcoming", "b"); //F2
var byDayItem = new MenuItem ("By Day", "n"); // F3
var byRoomItem = new MenuItem ("By Room", "F4");
var bySpeakerItem = new MenuItem ("By Speaker", "F5");
var quitItem = new MenuItem ("Quit (C-q)");
helpItem.OnItemActivated += (object sender, MenuItemActivatedEventArgs e) => {
4 weeks ago
contentWindow.Clean ();
if (contentWindow.TargetInputHandler is null) return;
var scrollWindow = new ScrollWindow (contentWindow, contentWindow.TargetInputHandler, 30);
for (int i = 0; i < scrollWindow.PadSize.Height - 1; i++)
NCurses.WindowAddString (scrollWindow.InnerPadId, $"Line {i}\n");
NCurses.WindowAddString (scrollWindow.InnerPadId, $"Line {scrollWindow.PadSize.Height}");
scrollWindow.ShowPad ();
};
return new List<MenuItem> {
helpItem,
upcomingItem,
byDayItem,
byRoomItem,
bySpeakerItem,
quitItem
};
}
4 weeks ago
}