static void Test_labels() { var frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "Labels" }; frm.AddChild(new Label(2, 2, "A single line label next to a multi line label") { ForegroundColor = ConsoleColor.DarkGray }); frm.AddChild(new Label(2, 4, "Macbeth:")); frm.AddChild(new Label(11, 4, 15) { Name = "lbl", CanBeMultiline = true, Text = "She should have died hereafter, there would have been a time for such a word.", BackgroundColor = ConsoleColor.DarkRed }); frm.AddChild(new Button(2, 11, 10, "Close") { OnPressed = (s, e) => { BashForms.Close(); } }); BashForms.Open(frm); }
static void Test_text_editing() { var frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "Text editing" }; frm.AddChild(new TextLine(2, 2, frm.Size.width - 4) { Label = "Single text line" }); frm.AddChild(new TextArea(2, 4, 16, 5) { Label = "Multi-line text" }); frm.AddChild(new Button(2, 10, 10, "Close") { OnPressed = (s, e) => { BashForms.Close(); } }); BashForms.Open(frm); }
public TaskDialog() { _dlg = new Dialog <bool>(2, 2, Console.WindowWidth * 2 / 3, Console.WindowHeight * 3 / 4) { Title = "Edit task" }; _txtSubject = new TextLine(2, 2, _dlg.Size.width - 4) { Label = "subject" }; _dlg.AddChild(_txtSubject); _txtDescription = new TextArea(2, 4, _txtSubject.Size.width / 2, _dlg.Size.height - 7) { Label = "description" }; _dlg.AddChild(_txtDescription); _txtDueDate = new TextLine(_txtDescription.Position.left + _txtDescription.Size.width + 2, 4, 10) { Label = "due date" }; _dlg.AddChild(_txtDueDate); _cboPriority = new Combobox(_txtDueDate.Position.left, _txtDueDate.Position.top + 2, _txtDueDate.Size.width, 6, new[] { "", "Low", "Medium", "High", "ASAP" }) { LimitTextToItems = true }; _dlg.AddChild(_cboPriority); _txtTags = new TextLine(_cboPriority.Position.left, _cboPriority.Position.top + 2, _cboPriority.Size.width) { Label = "tags" }; _dlg.AddChild(_txtTags); var btnSave = new Button(2, _txtDescription.Position.top + _txtDescription.Size.height + 1, 10, "Save") { OnPressed = (w, e) => { _dlg.Result = true; BashForms.Close(); } }; _dlg.AddChild(btnSave); _dlg.AddChild(new Button(14, btnSave.Position.top, 10, "Cancel") { OnPressed = (w, e) => { _dlg.Result = false; BashForms.Close(); } }); }
static void Test_lists() { var frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "Options" }; frm.AddChild(new Label(2, 2, "Listbox")); var lb = new Listbox(2, 3, 10, 5, new[] { "Balin", "Dwalin", "Kili", "Fili", "Oin", "Gloin", "Ori", "Nori", "Dori", "Bifur", "Bofur", "Bombur", "Thorin" }); lb.Items[0].BackgroundColor = ConsoleColor.DarkYellow; lb.Items[1].ForegroundColor = ConsoleColor.Red; lb.OnPressed += (s, e) => MessageBox.ShowInfo("Dwarf selected: " + lb.Items[lb.CurrentItemIndex].Text); frm.AddChild(lb); frm.AddChild(new Label(2, 9, "Combobox")); var cb = new Combobox(2, 10, 21, 5, new[] { "Paris", "London", "Oslo", "Berlin", "New York", "Tokyo", "Rio", "Prague" }) { Label = "Your favorite city" }; frm.AddChild(cb); frm.AddChild(new Label(24, 10, 20) { Text = "Press down-arrow to open list of choices.\nPress ESC to close list of choices.", CanBeMultiline = true, ForegroundColor = ConsoleColor.DarkGray }); frm.AddChild(new Label(2, 9, "Combobox with text limited to list items")); var cb2 = new Combobox(2, 12, 21, 4, new[] { "XS", "S", "M", "L", "XL", "XXL" }) { Label = "Select your t-shirt size", LimitTextToItems = true }; frm.AddChild(cb2); frm.AddChild(new Button(2, 14, 10, "Close") { OnPressed = (s, e) => { BashForms.Close(); } }); BashForms.Open(frm); }
static void Test_filesystemdlg() { var frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "Filesystem Dialog" }; frm.AddChild(new Label(2, 2, "Path to open dialog on: ")); frm.AddChild(new TextLine(26, 2, 20) { Text = "../..", Name = "txtPath" }); frm.AddChild(new Option(26, 3, 20, "Directories only") { Name = "optDirsOnly" }); frm.AddChild(new Option(26, 4, 20, "Allow new name") { Name = "optNewFileOrFoldername" }); frm.AddChild(new Listbox(50, 2, 20, 20) { Name = "lbSelected", TabIndex = -1, BackgroundColor = ConsoleColor.DarkGray }); frm.AddChild(new Button(26, 5, 10, "Open...") { OnPressed = (s, e) => { var fsdlg = new FilesystemDialog(frm.Child <TextLine>("txtPath").Text) { ListDirectoriesOnly = frm.Child <Option>("optDirsOnly").Selected, AllowNewFileOrFoldername = frm.Child <Option>("optNewFileOrFoldername").Selected }; var selection = BashForms.OpenModal(fsdlg); frm.Child <Listbox>("lbSelected").Clear(); frm.Child <Listbox>("lbSelected").AddRange(selection.Select(fn => new Listbox.Item(fn))); } }); frm.AddChild(new Button(26, 7, 10, "Close") { OnPressed = (s, e) => BashForms.Close() }); BashForms.Open(frm); }
static void Test_messageboxes() { var frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "MessageBox" }; frm.AddChild(new Label(2, 2, "Messagebox result:")); frm.AddChild(new Label(2, 3, 18) { BackgroundColor = ConsoleColor.DarkRed, Name = "lblResult" }); frm.MenuBar.Menu.AddItem("Ok"); frm.MenuBar.Menu.AddItem("YesNo"); frm.MenuBar.Menu.AddItem("OkCancelIgnore"); frm.MenuBar.Menu.AddItem("None"); frm.MenuBar.Menu.AddItem("Exit"); frm.MenuBar.OnSelected += (mnuItem, e) => { switch (mnuItem.Text) { case "Ok": var result = MessageBox.Show("Gimme an ok!", (MessageBox.Results.Ok, "Okay!")); frm.Child <Label>("lblResult").Text = result.ToString(); break; case "YesNo": result = MessageBox.Show("Shall I?", (MessageBox.Results.Yes, "YES"), (MessageBox.Results.No, "No,no!"), "Question"); frm.Child <Label>("lblResult").Text = result.ToString(); break; case "OkCancelIgnore": result = MessageBox.Show("Shall I?", (MessageBox.Results.Continue, "Continue"), (MessageBox.Results.Cancel, "Cancel"), (MessageBox.Results.Ignore, "Never mind"), "What's your choice?"); frm.Child <Label>("lblResult").Text = result.ToString(); break; case "None": result = MessageBox.Show("I am confused", (MessageBox.Results.None, "Continue"), (MessageBox.Results.None, "Cancel"), (MessageBox.Results.None, "Never mind"), "No choice?"); frm.Child <Label>("lblResult").Text = result.ToString(); break; case "Exit": BashForms.Close(); break; } }; frm.AddChild(new Label(2, 5, 40, "Switch to the menu with F2 and choose a MessageBox demo.\n\nIn the message boxes use (shift-)TAB to switch between buttons.") { ForegroundColor = ConsoleColor.DarkGray }); BashForms.Open(frm); }
static void Choose_a_demo() { var frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "Choose a demo" }; var mnusw = frm.MenuBar.Menu.AddItem("Single widgets"); mnusw.Submenu.AddItem("Lbls", "mnuLabels"); mnusw.Submenu.AddItem("Texts", "mnuText"); mnusw.Submenu.AddItem("Options", "mnuOptions"); mnusw.Submenu.AddItem("Lists", "mnuLists"); mnusw.Submenu.AddItem("Dialogs") .Submenu.AddItems(new[] { new MenuItem("MsgBox", "mnuMsgBox"), new MenuItem("FileSys", "mnuFileSys") }); var mnusc = frm.MenuBar.Menu.AddItem("Scenarios"); mnusc.Submenu.AddItem("ToDo App", "mnuToDo"); frm.MenuBar.Menu.AddItem("Exit", "mnuExit"); frm.MenuBar.OnSelected += (mnuItem, e) => { switch (mnuItem.Name) { case "mnuExit": BashForms.Close(); break; case "mnuLabels": Test_labels(); break; case "mnuText": Test_text_editing(); break; case "mnuOptions": Test_options(); break; case "mnuLists": Test_lists(); break; case "mnuMsgBox": Test_messageboxes(); break; case "mnuFileSys": Test_filesystemdlg(); break; case "mnuToDo": ToDoApp.Enterypoint(); break; } }; frm.AddChild(new Label(2, 3, 40) { Text = "* Press F2 to enter menu.\n* Use left/right arrow to move between menu item.\n* Use ENTER to select menu item/enter next menu level.\n* Use ESC to back up menu level.\n\n* Use (shift-)TAB to move between controls.\n\n* Use F5 to refresh screen.", CanBeMultiline = true, ForegroundColor = ConsoleColor.DarkGray }); BashForms.Open(frm); }
static void Test_options() { var frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "Options" }; frm.AddChild(new Label(2, 2, "Which animals are mammals?")); frm.AddChild(new Option(4, 3, 20, "Dog") { Name = "optDog" }); frm.AddChild(new Option(4, 4, 20, "Ant") { Name = "optAnt" }); frm.AddChild(new Option(4, 5, 20, "Cat") { Name = "optCat" }); frm.AddChild(new Option(4, 6, 20, "Dolphin") { Name = "optDolphin" }); frm.AddChild(new Button(4, 7, 10, "Check") { OnPressed = (s, _) => { var correct = frm.Child <Option>("optDog").Selected&& frm.Child <Option>("optCat").Selected&& frm.Child <Option>("optDolphin").Selected&& !frm.Child <Option>("optAnt").Selected; MessageBox.ShowInfo(correct ? "Correct! You're the best!" : "Sorry, wrong. Try again", " Quiz Result"); } }); frm.AddChild(new Label(2, 9, "Who's your favorite hero?")); var grp = new SingleOptionGroup(); grp.OnSelected += (s, _) => MessageBox.ShowInfo("Good choice: " + s.Text); frm.AddChild(new Option(4, 10, 20, "Superman") { OptionGroup = grp }); frm.AddChild(new Option(4, 11, 20, "Donald Duck") { OptionGroup = grp }); frm.AddChild(new Option(4, 12, 20, "Batman") { OptionGroup = grp }); frm.AddChild(new Option(4, 13, 20, "Antman") { OptionGroup = grp }); frm.AddChild(new Label(32, 2, 30, "Move between the options using (shift-)TAB!\nEach is a control of its own.\n\nPress ENTER or SPACE to toggle an option.") { ForegroundColor = ConsoleColor.DarkGray }); frm.AddChild(new Button(2, 15, 10, "Close") { OnPressed = (s, e) => { BashForms.Close(); } }); BashForms.Open(frm); }
public FilesystemDialog(string path = "", string title = "") : base(0, 0, 1, 1) { _width = Console.WindowWidth / 2; _height = (int)(Console.WindowHeight * 0.8); _top = (Console.WindowHeight - _height) / 2; _left = (Console.WindowWidth - _width) / 2; _title = title == "" ? "Select file or folder" : title; _listDirectoriesOnly = false; this.AddChild(new Label(2, 2, "Path: ") { BackgroundColor = ConsoleColor.DarkGray }); this.AddChild( new Label(8, 2, _width - 10, path) { Name = "lblPath", BackgroundColor = ConsoleColor.DarkGray }); _lbFilesystem = new FilesystemListbox(2, 3, _width - 4, _height - 8) { SelectionMode = Listbox.SelectionModes.SingleSelection }; _lbFilesystem.OnExpandRequested += Handle_expand_request; _lbFilesystem.OnCollapseRequested += Handle_collapse_request; this.AddChild(_lbFilesystem); this.AddChild(new TextLine(2, _height - 4, _width - 4) { Label = "file or folder name", Name = "txtFileOrFoldername", Visible = false }); const int BUTTON_WIDTH = 10; var totalButtonWidth = 2 * BUTTON_WIDTH + 2; var buttonLeft = (_width - totalButtonWidth) / 2; this.AddChild(new Button(buttonLeft, _height - 2, BUTTON_WIDTH, "Select") { OnPressed = (s, e) => { var selections = _lbFilesystem.SelectedItemIndexes.Select(i => ((FilesystemAttachment)_lbFilesystem.Items[i].Attachment).Path); if (this.AllowNewFileOrFoldername) { selections = selections.Concat(new[] { this.Child <TextLine>("txtFileOrFoldername").Text }); } base.Result = selections.ToArray(); BashForms.Close(); } }); this.AddChild(new Button(buttonLeft + BUTTON_WIDTH + 2, _height - 2, BUTTON_WIDTH, "Cancel") { OnPressed = (s, e) => { base.Result = new string[0]; BashForms.Close(); } }); if (path != "") { Fill(path); } }
public MainWindow() { _frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight) { Title = "ToDoBeDoBeDo Task Management" }; _frm.MenuBar.Menu.AddItem(new MenuItem("File")).Submenu.AddItem(new MenuItem("Close", "mnuClose") { Shortcut = 'x' }); _frm.MenuBar.Menu.AddItem(new MenuItem("Edit")).Submenu.AddItems(new[] { new MenuItem("Add", "mnuAdd") { Shortcut = '+' }, new MenuItem("Delete", "mnuDel") { Shortcut = '-' } }); var mnuFilterOverdue = new MenuItem("Filter for overdue", "mnuFilterOverdue"); var mnuFilterDue = new MenuItem("Filter for due", "mnuFilterDue"); var mnuFilterASAP = new MenuItem("Filter for ASAP", "mnuFilterASAP"); _frm.MenuBar.Menu.AddItem(new MenuItem("View")).Submenu.AddItems(new[] { mnuFilterOverdue, mnuFilterDue, mnuFilterASAP }); _frm.MenuBar.OnSelected += (item, e) => { switch (item.Name) { case "mnuAdd": OnNewTaskRequest(); _frm.MenuBar.HasFocus = false; break; case "mnuDel": if (_lstTasks.CurrentItemIndex >= 0 && MessageBox.AskForYes("Delete current item?")) { OnDeleteTaskRequest((string)_lstTasks.CurrentItem.Attachment); } _frm.MenuBar.HasFocus = false; break; case "mnuFilterOverdue": case "mnuFilterDue": case "mnuFilterASAP": item.Checked = !item.Checked; OnQueryTasksRequest(Build_query()); break; case "mnuClose": BashForms.Close(); _frm.MenuBar.HasFocus = false; break; } }; const int SUBJECT_COL_WIDTH = 20; const int DESC_COL_WIDTH = 30; const int DUE_COL_WIDTH = 10; const int PRIO_COL_WIDTH = 13; _frm.AddChild(new Label(2, 2, "Subject".PadRight(SUBJECT_COL_WIDTH) + "|" + "Description".PadRight(DESC_COL_WIDTH) + "|" + "Due".PadRight(DUE_COL_WIDTH) + "|" + "Priority".PadRight(PRIO_COL_WIDTH)) { BackgroundColor = ConsoleColor.DarkBlue, ForegroundColor = ConsoleColor.White }); _lstTasks = new Listbox(2, 3, _frm.Size.width - 4, _frm.Size.height - 6) { FocusBackgroundColor = ConsoleColor.Black, Columns = new[] { SUBJECT_COL_WIDTH, DESC_COL_WIDTH, DUE_COL_WIDTH, PRIO_COL_WIDTH } }; _lstTasks.OnPressed = (w, e) => { if (_lstTasks.CurrentItemIndex >= 0) { OnEditTaskRequest((string)_lstTasks.CurrentItem.Attachment); } }; _frm.AddChild(_lstTasks); _txtQuery = new TextLine(2, _lstTasks.Position.top + _lstTasks.Size.height + 1, 45) { Label = "query: words or #tags separated by spaces" }; _frm.AddChild(_txtQuery); _frm.AddChild(new Button(_txtQuery.Position.left + _txtQuery.Size.width + 2, _txtQuery.Position.top, 10, "Filter") { OnPressed = (s, e) => { OnQueryTasksRequest(Build_query()); } }); string Build_query() { var query = _txtQuery.Text; if (mnuFilterOverdue.Checked) { query += " !overdue"; } if (mnuFilterDue.Checked) { query += " !due"; } if (mnuFilterASAP.Checked) { query += " !asap"; } return(query); } }