示例#1
0
        /// <summary>
        /// 依据给定的menu style,做菜单绘制前准备
        /// </summary>
        private void PrepareDrawingContext()
        {
            switch (Context.Style.DrawingStyle)
            {
            case MenuDrawingStyle.ClearSreen:
                Console.Clear();
                break;

            case MenuDrawingStyle.InheritStartPoint:
                var lastCursor = new CursorStatus();
                if (Context.CursorStatus.Left > lastCursor.Left || Context.CursorStatus.Top > lastCursor.Top)
                {
                    throw new Exception("consolemenu 启动环境信息已被破坏");
                }
                if (lastCursor.Top >= Console.BufferHeight - 1)
                {
                    throw new Exception("console 缓冲区已用尽");
                }
                else
                {
                    for (int i = Context.CursorStatus.Top; i < lastCursor.Top; i++)
                    {
                        Console.MoveBufferArea(0, Console.BufferHeight - 1, Console.BufferWidth, 1, 0, i);
                    }
                    Context.SetToConsole();
                }
                break;

            case MenuDrawingStyle.FollowSystem:
                break;

            default:
                throw new NotImplementedException(string.Format("未实现的绘制样式:{0}", Enum.GetName(typeof(MenuDrawingStyle), Context.Style.DrawingStyle)));
            }
        }
示例#2
0
        /// <summary>
        /// 菜单上下文。父菜单active时生成,用于绘制参考
        /// </summary>
        /// <param name="menuStyle"></param>
        public MenuContext(MenuDrawingStyle drawingStyle, MenuItemKeyStyle keyStyle, ConsoleColor disabledItemForegroundColor = System.ConsoleColor.DarkGray)
        {
            DrawingStyle = drawingStyle;
            KeyStyle     = keyStyle;
            DisabledItemForegroundColor = disabledItemForegroundColor;

            CursorStatus = new CursorStatus();
            ConsoleColor = new SafeConsoleColor();
        }
示例#3
0
 /// <summary>
 /// 恢复至console
 /// </summary>
 public void SetToConsole()
 {
     ConsoleColor.SetToConsole();
     CursorStatus.SetToConsole();
 }
示例#4
0
 /// <summary>
 /// 菜单上下文。父菜单active时生成,用于绘制参考
 /// </summary>
 /// <param name="menuStyle"></param>
 public MenuContext(MenuStyle menuStyle)
 {
     Style        = menuStyle ?? throw new ArgumentNullException(nameof(menuStyle));
     CursorStatus = new CursorStatus();
     ConsoleColor = new SafeConsoleColor();
 }