/// <summary> /// This method displays the menu on the console application. /// </summary> /// <param name="state">The optional state.</param> /// <param name="pageLength">This is the number of menu items per page. The default is 9.</param> /// <param name="shortcut">This property allows a supported shortcut to the executed automatically</param> /// <param name="contextInfo">This method allows the menu context to be inherited by a child menu. If ContextInfoInherit is set to false, this is ignored.</param> public virtual void Show(object state = null, int pageLength = 9, string shortcut = null, ConsoleInfoContext contextInfo = null) { if (contextInfo != null && ContextInfoInherit) { ContextInfo = contextInfo; } Context.State = state; Context.PageCurrent = 1; Context.PageSet(pageLength); if (Context.ConsoleTitle != null) { System.Console.Title = Context.ConsoleTitle; } //Execute any registered shortcut if (shortcut != null) { ShortcutInvoke(Context, shortcut); } Display(); OnClose?.Invoke(this, null); }
/// <summary> /// This method displays the info messages on the console. /// </summary> public static void DisplaySummary(this ConsoleInfoContext context, int count = 3) { if (context.InfoMessages.Count > 0) { count = DisplaySummaryMessages(context, count); } while (count-- > 0) { System.Console.WriteLine(); } }
/// <summary> /// This is the main constructor for the menu. /// </summary> /// <param name="title">The page title.</param> /// <param name="options">The child options for the menu.</param> public ConsoleMenu( string title , params ConsoleOption[] options ) { Context = new ConsoleMenuContext(options); ContextInfo = new ConsoleInfoContext(); Context.Title = title; Context.ConsoleTitle = title; Context.Subtitle = "Please select from the following options"; Context.EscapeText = "Press escape to exit"; Context.EscapeWrapper = true; Context.Indent1 = 3; Context.Indent2 = 6; CustomInfo = new Dictionary <string, ConsoleInfoContext>(); }
private static int DisplaySummaryMessages(ConsoleInfoContext context, int count) { int current = 0; foreach (var info in context.GetCurrent(count)) { ConsoleColor infoColor; switch (info.Type) { case LoggingLevel.Error: case LoggingLevel.Fatal: infoColor = ConsoleColor.Red; break; case LoggingLevel.Warning: infoColor = ConsoleColor.Yellow; break; default: infoColor = ConsoleColor.Gray; break; } current++; bool showUp = current == 1 && info.LoggingId < (context.Count - 1); bool showDown = current == count && info.LoggingId > 0; ConsoleHelper.HeaderBar( $"{info.LoggingId+1}. {info.Message}" , character: ' ' , titleColour: infoColor , startChar: showUp ? (char)8593 : (char?)null , endChar: showDown ? (char)8595 : (char?)null ); } return(count - current); }