コード例 #1
0
        static void Main(string[] args)
        {
            try {
                ShellNetworkGlue.Init();
            } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); return; }
            Console.WriteLine("connected");


            var CState = new ConsoleState {
                Exec = (str_in) => {
                    var req_eval = new EVAL_Req {
                        expr = str_in
                    };
                    EVAL_Resp resp = ShellNetworkGlue.EVAL(req_eval);
                    return
                        ("\n" +
                         (resp.success ? "OK" : "Error") +
                         resp.msg +
                         string.Join("\n", resp.result.Select(_ => _.ToString()).ToArray()));
                },

                AC = (str_in, offs) => {
                    var req_ac = new AC_Req {
                        arg = str_in, offs = offs
                    };
                    AC_Resp resp = ShellNetworkGlue.AC(req_ac);

                    return(resp);
                }
            };
            Action <string> DBG_push = (in_str) => {
                /*
                 * var TL = new TokenLine();
                 * var Tok = new ShellToken { s_offs = 0 , e_offs = in_str.Length , orig = in_str , id = ShellTokenE.Error };
                 * TL.SetTokens ( new [] { Tok } );
                 * CState.H_push( TL);
                 */
            };


            DBG_push("ZingType ::  .lel");

            while (true)
            {
                CState.STEP();
            }
        }
コード例 #2
0
        public void STEP()   // blocks on keyboard in addition to the blocking caused by the callback functions
        {
            ConsoleKeyInfo KeyInfo = Console.ReadKey(intercept: true);

            if (KeyInfo.Key == ConsoleKey.UpArrow)
            {
                if (scroll && hist_len == 0)
                {
                    throw new Exception("inv1 bug");
                }

                if (scroll)
                {
                    hist_pos = Math.Min(hist_pos + 1, hist_len - 1);
                }
                else if (hist_len > 0)
                {
                    scroll = true; hist_pos = 0;
                }
                // else hist is empty. simply do nothing for vertical pos
                currLine.bare_line_clamped_CX = global_hor_pos;
            }
            else if (KeyInfo.Key == ConsoleKey.DownArrow)
            {
                if (scroll && hist_pos == 0)
                {
                    scroll = false;
                }
                if (scroll && hist_pos > 0)
                {
                    hist_pos--;
                }
                // if state is edit, down arrow does nothing
                currLine.bare_line_clamped_CX = global_hor_pos;
            }

            /*
             *  TokenLine, as currently implemented, holds the horizontal position of the cursor - each line its own
             *  they need this to "render themselves" properly (can't write to console without moving it )
             */
            else if (KeyInfo.Key == ConsoleKey.LeftArrow)
            {
                global_hor_pos = Math.Max(0, global_hor_pos - 1);
                currLine.bare_line_clamped_CX = global_hor_pos;
            }
            else if (KeyInfo.Key == ConsoleKey.RightArrow)
            {
                currLine.bare_line_clamped_CX = (global_hor_pos + 1);
                global_hor_pos = currLine.bare_line_clamped_CX;            // <- contains all the clamping and stuff needed
            }
            else if (KeyInfo.Key == ConsoleKey.Delete)
            {
                StartModify();
                TL_e.KillCharAtPoint();
                global_hor_pos = TL_e.bare_line_clamped_CX;
            }
            else if (KeyInfo.Key == ConsoleKey.Backspace)
            {
                StartModify();
                TL_e.KillPrevChar();
                global_hor_pos = TL_e.bare_line_clamped_CX;
            }
            else if (KeyInfo.Key == ConsoleKey.Home)
            {
                currLine.Home();
                global_hor_pos = 0;
            }
            else if (KeyInfo.Key == ConsoleKey.End)
            {
                currLine.End();
                global_hor_pos = currLine.bare_line_clamped_CX;
            }
            else if (KeyInfo.Key == ConsoleKey.Enter)
            {
                var string_arg = currLine.bareTokenLine.plain_string;
                if (!Regex.Match(string_arg, @"^\s*$").Success)
                {
                    H_push(currLine);                                                    // don't litter hist with empty lines
                }
                scroll = false;
                TL_e   = new RenderableTokenLine();
                var string_res = Exec(string_arg);
                Console.WriteLine("\n" + string_res + "\n");
            }
            else if (KeyInfo.Key == ConsoleKey.Tab)
            {
                AC_Resp res = AC(TL_e.bareTokenLine.plain_string, TL_e.bare_line_clamped_CX);
                if (res.msg != null)
                {
                    Console.WriteLine();
                    Console.WriteLine("MSG : " + res.msg);
                }
                if (res.suggs != null && res.suggs.Length > 0)         // overapproximate current protocoll (null should not occur )
                {
                    Console.WriteLine();
                    foreach (var sugg in res.suggs)
                    {
                        Console.WriteLine(sugg);
                    }
                }
                if (res.toks_changed)
                {
                    StartModify();
                    TL_e.SetTokens(res.toks);
                    TL_e.bare_line_clamped_CX = res.nu_offs;
                    global_hor_pos            = TL_e.bare_line_clamped_CX;
                }
            }
            else   // actually edit something
            {
                StartModify();
                TL_e.InsertAtPoint(new string ( new [] { KeyInfo.KeyChar } ));
                global_hor_pos = TL_e.bare_line_clamped_CX;
            }
            DisplayCurrentLine();
        }