Exemple #1
0
            public short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
            {               // flush any waiting input and pause thie thread while it is looking for input
                if (m_temp != null && m_temp.Length > 0)
                {
                    m_conversation.WriteLine(m_temp); m_temp = "";
                }
                this.m_conversation.Suspend();

                // gather input
                short          ch = 0;
                ConsoleKeyInfo info;

                do
                {
                    lock (m_conversation.SyncRoot)
                    {
                        if (m_conversation.DataReady == false)
                        {                           // should never happen because this thread is only resumed when this mobile.OnThink()
                            //  sees that there is DataReady
                            Thread.Sleep(250);
                            continue;
                        }

                        info = new ConsoleKeyInfo(m_conversation.ReadKey, ConsoleKey.Y, false, false, false);
                    }

                    ch = translator(info.KeyChar);
                } while (ch == 0);
                return(ch);
            }
Exemple #2
0
            public string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
            {               // flush any waiting input and pause thie thread while it is looking for input
                if (m_temp != null && m_temp.Length > 0)
                {
                    m_conversation.WriteLine(m_temp); m_temp = "";
                }
                this.m_conversation.Suspend();

                // gather input
                terminator = 13;
                while (true)
                {
                    lock (m_conversation.SyncRoot)
                    {
                        if (m_conversation.DataReady == false)
                        {                           // should never happen because this thread is only resumed when this mobile.OnThink()
                            //  sees that there is DataReady
                            Thread.Sleep(250);
                            continue;
                        }

                        return(m_conversation.ReadLine);
                    }
                }
            }
Exemple #3
0
        public override short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
        {
            string inputLine;

            do
            {
                inputLine = inputBuffer.Dequeue();
            } while (inputLine.Length == 0);
            return(translator(inputLine[0]));
        }
Exemple #4
0
        public short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
        {
            short ch;

            do
            {
                ConsoleKeyInfo info = Console.ReadKey();
                ch = translator(info.KeyChar);
            } while (ch == 0);
            return(ch);
        }
 public short ReadKey(
     int time, TimedInputCallback callback, CharTranslator translator
     )
 {
     /*
      * short ch;
      * do
      * {
      * ConsoleKeyInfo info = Console.ReadKey();
      * ch = translator(info.KeyChar);
      * } while (ch == 0);
      */
     _ed.WriteMessage("\nReadKey called.\n");
     return(0);
 }
Exemple #6
0
        private static void DebuggerLoop(ZMachine zm, string[] sourcePath)
        {
            var console = new DebuggingConsole(zm, zm.IO, sourcePath);

            console.Activate();

            TimedInputCallback cb = () => false;

            byte[] terminatingKeys = { };

            while (console.Active)
            {
                byte   terminator;
                string cmd = zm.IO.ReadLine(string.Empty, 0, cb, terminatingKeys, out terminator);

                console.HandleCommand(cmd);
            }
        }
Exemple #7
0
        public short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
        {
            FlushBuffer();
            lineCount = 0;

            while (true)
            {
                if (time > 0)
                {
                    int sleeps = 0;
                    while (!Console.KeyAvailable)
                    {
                        Thread.Sleep(100);
                        if (Console.KeyAvailable)
                        {
                            break;
                        }

                        sleeps++;
                        if (sleeps == time)
                        {
                            sleeps = 0;
                            if (callback() == true)
                            {
                                return(0);
                            }
                        }
                    }
                }

                ConsoleKeyInfo info = Console.ReadKey(true);
                short          zkey = ConsoleKeyToZSCII(info.Key);
                if (zkey != 0)
                {
                    return(zkey);
                }

                zkey = translator(info.KeyChar);
                if (zkey != 0)
                {
                    return(zkey);
                }
            }
        }
        public string ReadLine(
            string initial, int time, TimedInputCallback callback,
            byte[] terminatingKeys, out byte terminator
            )
        {
            if (_non0.Count == 199)
            {
                _lastLoc = _non0[locIdx];

                var sb = new StringBuilder();
                sb.AppendFormat(
                    "{{\"id\":\"{0}\",\"name\":\"{1}\",\"dir\":\"{2}\"}}",
                    _curLoc, _lastLoc, _lastMove.ToUpper()
                    );
                acjsInvokeAsync("setloc", sb.ToString());
            }

            terminator = 13;
            var prompt =
                _non0.Count == 199 && _showProgress?
                String.Format(
                    "\n<Location: {0}, Score {1}, Moves {2}> ",
                    _non0[locIdx],
                    _non0[scoIdx],
                    _non0[movIdx]
                    ) : "";

            var pso = new PromptStringOptions(prompt);

            pso.AllowSpaces = true;
            var pr = _ed.GetString(pso);

            if (pr.Status == PromptStatus.OK && pr.StringResult == "-")
            {
                pr = _ed.GetString(pso);
            }
            _lastMove = pr.Status == PromptStatus.OK ? pr.StringResult : "";
            _non0.Clear();

            return(_lastMove);
        }
Exemple #9
0
        public string ReadLine(
            string initial, int time, TimedInputCallback callback,
            byte[] terminatingKeys, out byte terminator
            )
        {
            terminator = 13;
            var prompt =
                _non0.Count == 199 && _showProgress?
                String.Format(
                    "\n<Location: {0}, Score {1}, Moves {2}> ",
                    _non0[locIdx],
                    _non0[scoIdx],
                    _non0[movIdx]
                    ) : "";

            var pso = new PromptStringOptions(prompt);

            pso.AllowSpaces = true;
            var pr = _ed.GetString(pso);

            _non0.Clear();
            return(pr.Status == PromptStatus.OK ? pr.StringResult : "quit");
        }
Exemple #10
0
 public virtual string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
 {
     return(next.ReadLine(initial, time, callback, terminatingKeys, out terminator));
 }
Exemple #11
0
 public abstract string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator);
Exemple #12
0
 public abstract string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator);
Exemple #13
0
 public override string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
 {
     terminator = 13;
     return(inputBuffer.Dequeue());
 }
Exemple #14
0
        public string ReadLine(string initial, int time, TimedInputCallback callback,
            byte[] terminatingKeys, out byte terminator)
        {
            FlushBuffer();
            lineCount = 0;

            int histIdx = history.Count;
            string savedEntry = string.Empty;
            int sleeps = 0;

            StringBuilder sb;
            int cursor;
            if (initial.Length == 0)
            {
                sb = new StringBuilder(20);
                cursor = 0;
            }
            else
            {
                sb = new StringBuilder(initial);
                cursor = initial.Length;
            }

            while (true)
            {
                if (time > 0)
                {
                    while (!Console.KeyAvailable)
                    {
                        Thread.Sleep(100);
                        if (Console.KeyAvailable)
                            break;

                        sleeps++;
                        if (sleeps == time)
                        {
                            sleeps = 0;
                            int cx = Console.CursorLeft;
                            int cy = Console.CursorTop;
                            if (callback() == true)
                            {
                                terminator = 0;
                                return string.Empty;
                            }
                            else
                            {
                                // the game may have printed something anyway
                                if (Console.CursorLeft != cx ||
                                    Console.CursorTop != cy)
                                {
                                    Console.Write(sb.ToString());
                                    for (int i = cursor; i < sb.Length; i++)
                                        Console.Write('\x08');
                                }
                            }
                        }
                    }
                }

                ConsoleKeyInfo info = Console.ReadKey(true);
                byte special = ConsoleKeyToZSCII(info.Key);
                if (IsTerminator(special, terminatingKeys))
                {
                    terminator = special;
                    break;
                }

                switch (info.Key)
                {
                    case ConsoleKey.LeftArrow:
                        if (cursor > 0)
                        {
                            cursor--;
                            Console.Write('\x08');
                        }
                        break;

                    case ConsoleKey.RightArrow:
                        if (cursor < sb.Length)
                        {
                            Console.Write(sb[cursor]);
                            cursor++;
                        }
                        break;

                    case ConsoleKey.Home:
                        while (cursor > 0)
                        {
                            cursor--;
                            Console.Write('\x08');
                        }
                        break;

                    case ConsoleKey.End:
                        while (cursor < sb.Length)
                        {
                            Console.Write(sb[cursor]);
                            cursor++;
                        }
                        break;

                    case ConsoleKey.UpArrow:
                        if (histIdx > 0 && history.Count > 0)
                        {
                            if (histIdx == history.Count)
                                savedEntry = sb.ToString();

                            for (int i = cursor; i < sb.Length; i++)
                                Console.Write(' ');
                            for (int i = 0; i < sb.Length; i++)
                                Console.Write("\x08 \x08");

                            histIdx--;
                            sb.Length = 0;
                            sb.Append(history[histIdx]);
                            Console.Write(sb.ToString());
                            cursor = sb.Length;
                        }
                        break;

                    case ConsoleKey.DownArrow:
                        if (histIdx < history.Count && history.Count > 0)
                        {
                            for (int i = cursor; i < sb.Length; i++)
                                Console.Write(' ');
                            for (int i = 0; i < sb.Length; i++)
                                Console.Write("\x08 \x08");

                            histIdx++;
                            sb.Length = 0;
                            if (histIdx == history.Count)
                                sb.Append(savedEntry);
                            else
                                sb.Append(history[histIdx]);
                            Console.Write(sb.ToString());
                            cursor = sb.Length;
                        }
                        break;

                    case ConsoleKey.Backspace:
                        if (cursor > 0)
                        {
                            cursor--;
                            sb.Remove(cursor, 1);
                            Console.Write('\x08');
                            for (int i = cursor; i < sb.Length; i++)
                                Console.Write(sb[i]);
                            Console.Write(' ');
                            for (int i = cursor; i <= sb.Length; i++)
                                Console.Write('\x08');
                        }
                        break;

                    case ConsoleKey.Delete:
                        if (cursor < sb.Length)
                        {
                            sb.Remove(cursor, 1);
                            for (int i = cursor; i < sb.Length; i++)
                                Console.Write(sb[i]);
                            Console.Write(' ');
                            for (int i = cursor; i <= sb.Length; i++)
                                Console.Write('\x08');
                        }
                        break;

                    case ConsoleKey.Escape:
                        for (int i = cursor; i < sb.Length; i++)
                            Console.Write(' ');
                        for (int i = 0; i < sb.Length; i++)
                            Console.Write("\x08 \x08");
                        sb.Length = 0;
                        break;

                    default:
                        if (info.KeyChar != '\0')
                        {
                            sb.Insert(cursor, info.KeyChar);
                            Console.Write(info.KeyChar);
                            cursor++;
                            for (int i = cursor; i < sb.Length; i++)
                                Console.Write(sb[i]);
                            for (int i = cursor; i < sb.Length; i++)
                                Console.Write('\x08');
                        }
                        break;
                }
            }

            if (terminator == 13)
            {
                CheckScroll(true);
                Console.WriteLine();
            }

            string result = sb.ToString();

            history.Add(result);
            if (history.Count > MAX_COMMAND_HISTORY)
                history.RemoveAt(0);

            return result;
        }
Exemple #15
0
 public string ReadLine(string initial, int time, TimedInputCallback callback,
     byte[] terminatingKeys, out byte terminator)
 {
     terminator = 13;
     return Console.ReadLine() ?? "";
 }
Exemple #16
0
        public string ReadLine(string initial, int time, TimedInputCallback callback,
                               byte[] terminatingKeys, out byte terminator)
        {
            FlushBuffer();
            lineCount = 0;

            int    histIdx    = history.Count;
            string savedEntry = string.Empty;
            int    sleeps     = 0;

            StringBuilder sb;
            int           cursor;

            if (initial.Length == 0)
            {
                sb     = new StringBuilder(20);
                cursor = 0;
            }
            else
            {
                sb     = new StringBuilder(initial);
                cursor = initial.Length;
            }

            while (true)
            {
                if (time > 0)
                {
                    while (!Console.KeyAvailable)
                    {
                        Thread.Sleep(100);
                        if (Console.KeyAvailable)
                        {
                            break;
                        }

                        sleeps++;
                        if (sleeps == time)
                        {
                            sleeps = 0;
                            int cx = Console.CursorLeft;
                            int cy = Console.CursorTop;
                            if (callback() == true)
                            {
                                terminator = 0;
                                return(string.Empty);
                            }
                            else
                            {
                                // the game may have printed something anyway
                                if (Console.CursorLeft != cx ||
                                    Console.CursorTop != cy)
                                {
                                    Console.Write(sb.ToString());
                                    for (int i = cursor; i < sb.Length; i++)
                                    {
                                        Console.Write('\x08');
                                    }
                                }
                            }
                        }
                    }
                }

                ConsoleKeyInfo info    = Console.ReadKey(true);
                byte           special = ConsoleKeyToZSCII(info.Key);
                if (IsTerminator(special, terminatingKeys))
                {
                    terminator = special;
                    break;
                }

                switch (info.Key)
                {
                case ConsoleKey.LeftArrow:
                    if (cursor > 0)
                    {
                        cursor--;
                        Console.Write('\x08');
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (cursor < sb.Length)
                    {
                        Console.Write(sb[cursor]);
                        cursor++;
                    }
                    break;

                case ConsoleKey.Home:
                    while (cursor > 0)
                    {
                        cursor--;
                        Console.Write('\x08');
                    }
                    break;

                case ConsoleKey.End:
                    while (cursor < sb.Length)
                    {
                        Console.Write(sb[cursor]);
                        cursor++;
                    }
                    break;

                case ConsoleKey.UpArrow:
                    if (histIdx > 0 && history.Count > 0)
                    {
                        if (histIdx == history.Count)
                        {
                            savedEntry = sb.ToString();
                        }

                        for (int i = cursor; i < sb.Length; i++)
                        {
                            Console.Write(' ');
                        }
                        for (int i = 0; i < sb.Length; i++)
                        {
                            Console.Write("\x08 \x08");
                        }

                        histIdx--;
                        sb.Length = 0;
                        sb.Append(history[histIdx]);
                        Console.Write(sb.ToString());
                        cursor = sb.Length;
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (histIdx < history.Count && history.Count > 0)
                    {
                        for (int i = cursor; i < sb.Length; i++)
                        {
                            Console.Write(' ');
                        }
                        for (int i = 0; i < sb.Length; i++)
                        {
                            Console.Write("\x08 \x08");
                        }

                        histIdx++;
                        sb.Length = 0;
                        if (histIdx == history.Count)
                        {
                            sb.Append(savedEntry);
                        }
                        else
                        {
                            sb.Append(history[histIdx]);
                        }
                        Console.Write(sb.ToString());
                        cursor = sb.Length;
                    }
                    break;

                case ConsoleKey.Backspace:
                    if (cursor > 0)
                    {
                        cursor--;
                        sb.Remove(cursor, 1);
                        Console.Write('\x08');
                        for (int i = cursor; i < sb.Length; i++)
                        {
                            Console.Write(sb[i]);
                        }
                        Console.Write(' ');
                        for (int i = cursor; i <= sb.Length; i++)
                        {
                            Console.Write('\x08');
                        }
                    }
                    break;

                case ConsoleKey.Delete:
                    if (cursor < sb.Length)
                    {
                        sb.Remove(cursor, 1);
                        for (int i = cursor; i < sb.Length; i++)
                        {
                            Console.Write(sb[i]);
                        }
                        Console.Write(' ');
                        for (int i = cursor; i <= sb.Length; i++)
                        {
                            Console.Write('\x08');
                        }
                    }
                    break;

                case ConsoleKey.Escape:
                    for (int i = cursor; i < sb.Length; i++)
                    {
                        Console.Write(' ');
                    }
                    for (int i = 0; i < sb.Length; i++)
                    {
                        Console.Write("\x08 \x08");
                    }
                    sb.Length = 0;
                    break;

                default:
                    if (info.KeyChar != '\0')
                    {
                        sb.Insert(cursor, info.KeyChar);
                        Console.Write(info.KeyChar);
                        cursor++;
                        for (int i = cursor; i < sb.Length; i++)
                        {
                            Console.Write(sb[i]);
                        }
                        for (int i = cursor; i < sb.Length; i++)
                        {
                            Console.Write('\x08');
                        }
                    }
                    break;
                }
            }

            if (terminator == 13)
            {
                CheckScroll(true);
                Console.WriteLine();
            }

            string result = sb.ToString();

            history.Add(result);
            if (history.Count > MAX_COMMAND_HISTORY)
            {
                history.RemoveAt(0);
            }

            return(result);
        }
Exemple #17
0
 public override string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
 {
     terminator = 13;
     return inputBuffer.Dequeue();
 }
Exemple #18
0
        short IZMachineIO.ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
        {
            PerformSplit(targetSplit);

            if (unicode)
                Glk.glk_request_char_event_uni(currentWin);
            else
                Glk.glk_request_char_event(currentWin);

            Glk.glk_request_timer_events((uint)(time * 100));

            event_t ev;
            bool done = false;
            short result = 0;
            do
            {
                Glk.glk_select(out ev);

                switch (ev.type)
                {
                    case EvType.CharInput:
                        if (ev.win == currentWin)
                        {
                            if (ev.val1 <= 255 || (unicode && ev.val1 <= 0x10000))
                                result = translator((char)ev.val1);
                            else
                                result = GlkKeyToZSCII((KeyCode)ev.val1);

                            if (result != 0)
                                done = true;
                            else if (unicode)
                                Glk.glk_request_char_event_uni(currentWin);
                            else
                                Glk.glk_request_char_event(currentWin);
                        }
                        break;

                    case EvType.Timer:
                        if (callback() == true)
                        {
                            Glk.glk_cancel_char_event(currentWin);
                            done = true;
                        }
                        break;

                    case EvType.Arrange:
                        UpdateScreenSize();
                        break;

                    case EvType.SoundNotify:
                        SoundNotify();
                        break;
                }
            }
            while (!done);

            Glk.glk_request_timer_events(0);

            return result;
        }
Exemple #19
0
 short IZMachineIO.ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
 {
     throw new AssertFailedException("Unexpected character input request");
 }
Exemple #20
0
 public string ReadLine(string initial, int time, TimedInputCallback callback,
                        byte[] terminatingKeys, out byte terminator)
 {
     terminator = 13;
     return(Console.ReadLine() ?? "");
 }
Exemple #21
0
 string IZMachineIO.ReadLine(string initial, int time, TimedInputCallback callback,
                             byte[] terminatingKeys, out byte terminator)
 {
     throw new AssertFailedException("Unexpected line input request");
 }
        public string ReadLine(
            string initial, int time, TimedInputCallback callback,
            byte[] terminatingKeys, out byte terminator
            )
        {
            if (_non0.Count == 199)
              {
            _lastLoc = _non0[locIdx];

            var sb = new StringBuilder();
            sb.AppendFormat(
              "{{\"id\":\"{0}\",\"name\":\"{1}\",\"dir\":\"{2}\"}}",
              _curLoc, _lastLoc, _lastMove.ToUpper()
            );
            acjsInvokeAsync("setloc", sb.ToString());
              }

              terminator = 13;
              var prompt =
            _non0.Count == 199 && _showProgress ?
              String.Format(
            "\n<Location: {0}, Score {1}, Moves {2}> ",
            _non0[locIdx],
            _non0[scoIdx],
            _non0[movIdx]
              ) : "";
              var pso = new PromptStringOptions(prompt);
              pso.AllowSpaces = true;
              var pr = _ed.GetString(pso);

              if (pr.Status == PromptStatus.OK && pr.StringResult == "-")
              {
            pr = _ed.GetString(pso);
              }
              _lastMove = pr.Status == PromptStatus.OK ? pr.StringResult : "";
              _non0.Clear();

              return _lastMove;
        }
Exemple #23
0
 public override short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
 {
     ConsoleKeyInfo info = Console.ReadKey(true);
     return translator(info.KeyChar);
 }
Exemple #24
0
 public virtual short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
 {
     return(next.ReadKey(time, callback, translator));
 }
Exemple #25
0
 public virtual short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
 {
     return next.ReadKey(time, callback, translator);
 }
Exemple #26
0
 public short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
 {
     short ch;
     do
     {
         ConsoleKeyInfo info = Console.ReadKey();
         ch = translator(info.KeyChar);
     } while (ch == 0);
     return ch;
 }
Exemple #27
0
        short IZMachineIO.ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
        {
            PerformSplit(targetSplit);

            if (unicode)
            {
                Glk.glk_request_char_event_uni(currentWin);
            }
            else
            {
                Glk.glk_request_char_event(currentWin);
            }

            Glk.glk_request_timer_events((uint)(time * 100));

            event_t ev;
            bool    done   = false;
            short   result = 0;

            do
            {
                Glk.glk_select(out ev);

                switch (ev.type)
                {
                case EvType.CharInput:
                    if (ev.win == currentWin)
                    {
                        if (ev.val1 <= 255 || (unicode && ev.val1 <= 0x10000))
                        {
                            result = translator((char)ev.val1);
                        }
                        else
                        {
                            result = GlkKeyToZSCII((KeyCode)ev.val1);
                        }

                        if (result != 0)
                        {
                            done = true;
                        }
                        else if (unicode)
                        {
                            Glk.glk_request_char_event_uni(currentWin);
                        }
                        else
                        {
                            Glk.glk_request_char_event(currentWin);
                        }
                    }
                    break;

                case EvType.Timer:
                    if (callback() == true)
                    {
                        Glk.glk_cancel_char_event(currentWin);
                        done = true;
                    }
                    break;

                case EvType.Arrange:
                    UpdateScreenSize();
                    break;

                case EvType.SoundNotify:
                    SoundNotify();
                    break;
                }
            }while (!done);

            Glk.glk_request_timer_events(0);

            return(result);
        }
Exemple #28
0
 public override short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
 {
     string inputLine;
     do { inputLine = inputBuffer.Dequeue(); } while (inputLine.Length == 0);
     return translator(inputLine[0]);
 }
Exemple #29
0
			public string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
			{   // flush any waiting input and pause thie thread while it is looking for input
                if (m_temp != null && m_temp.Length > 0) { m_conversation.WriteLine(m_temp); m_temp = ""; }
                this.m_conversation.Suspend();
                
                // gather input
				terminator = 13;
				while (true)
				{
					lock (m_conversation.SyncRoot)
					{
						if (m_conversation.DataReady == false)
						{   // should never happen because this thread is only resumed when this mobile.OnThink()
                            //  sees that there is DataReady
							Thread.Sleep(250);
							continue;
						}

						return m_conversation.ReadLine;
					}
				}
			}
Exemple #30
0
        public override short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
        {
            ConsoleKeyInfo info = Console.ReadKey(true);

            return(translator(info.KeyChar));
        }
Exemple #31
0
			public short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
            {   // flush any waiting input and pause thie thread while it is looking for input
                if (m_temp != null && m_temp.Length > 0) { m_conversation.WriteLine(m_temp); m_temp = ""; }
                this.m_conversation.Suspend();

                // gather input
				short ch=0;
				ConsoleKeyInfo info;
				do
				{
					lock (m_conversation.SyncRoot)
					{
						if (m_conversation.DataReady == false)
                        {   // should never happen because this thread is only resumed when this mobile.OnThink()
                            //  sees that there is DataReady
							Thread.Sleep(250);
							continue;
						}

						info = new ConsoleKeyInfo(m_conversation.ReadKey, ConsoleKey.Y, false, false, false);
					}

					ch = translator(info.KeyChar);
				} while (ch == 0);
				return ch;
			}
Exemple #32
0
        public short ReadKey(int time, TimedInputCallback callback, CharTranslator translator)
        {
            FlushBuffer();
            lineCount = 0;

            while (true)
            {
                if (time > 0)
                {
                    int sleeps = 0;
                    while (!Console.KeyAvailable)
                    {
                        Thread.Sleep(100);
                        if (Console.KeyAvailable)
                            break;

                        sleeps++;
                        if (sleeps == time)
                        {
                            sleeps = 0;
                            if (callback() == true)
                                return 0;
                        }
                    }
                }

                ConsoleKeyInfo info = Console.ReadKey(true);
                short zkey = ConsoleKeyToZSCII(info.Key);
                if (zkey != 0)
                    return zkey;

                zkey = translator(info.KeyChar);
                if (zkey != 0)
                    return zkey;
            }
        }
Exemple #33
0
 public short ReadKey(
     int time, TimedInputCallback callback, CharTranslator translator
     )
 {
     /*
       short ch;
       do
       {
     ConsoleKeyInfo info = Console.ReadKey();
     ch = translator(info.KeyChar);
       } while (ch == 0);
       */
       _ed.WriteMessage("\nReadKey called.\n");
       return 0;
 }
Exemple #34
0
 public abstract short ReadKey(int time, TimedInputCallback callback, CharTranslator translator);
Exemple #35
0
        public string ReadLine(
            string initial, int time, TimedInputCallback callback,
            byte[] terminatingKeys, out byte terminator
            )
        {
            terminator = 13;
              var prompt =
            _non0.Count == 199 && _showProgress ?
              String.Format(
            "\n<Location: {0}, Score {1}, Moves {2}> ",
            _non0[locIdx],
            _non0[scoIdx],
            _non0[movIdx]
              ) : "";
              var pso = new PromptStringOptions(prompt);
              pso.AllowSpaces = true;
              var pr = _ed.GetString(pso);

              _non0.Clear();
              return pr.Status == PromptStatus.OK ? pr.StringResult : "quit";
        }
Exemple #36
0
        string IZMachineIO.ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
        {
            const int BUFSIZE = 256;
            IntPtr buf = Marshal.AllocHGlobal(unicode ? BUFSIZE * 4 : BUFSIZE);
            Encoding encoding = unicode ? Encoding.UTF32 : Encoding.GetEncoding(Glk.LATIN1);

            try
            {
                uint initlen = 0;

                if (initial.Length > 0)
                {
                    if (unicode)
                        Glk.garglk_unput_string_uni(initial);
                    else
                        Glk.garglk_unput_string(initial);

                    byte[] initBytes = encoding.GetBytes(initial);
                    Marshal.Copy(initBytes, 0, buf, initBytes.Length);

                    initlen = (uint)initBytes.Length;
                    if (unicode)
                        initlen /= 4;
                }

                if (unicode)
                    Glk.glk_request_line_event_uni(currentWin, buf, BUFSIZE, initlen);
                else
                    Glk.glk_request_line_event(currentWin, buf, BUFSIZE, initlen);
                Glk.glk_request_timer_events((uint)(time * 100));

                KeyCode[] glkTerminators = null;
                if (terminatingKeys != null && terminatingKeys.Length > 0)
                {
                    glkTerminators = GlkKeysFromZSCII(terminatingKeys);
                    Glk.garglk_set_line_terminators(currentWin, glkTerminators, (uint)glkTerminators.Length);
                }

                terminator = 0;

                event_t ev;
                bool done = false;
                do
                {
                    Glk.glk_select(out ev);

                    switch (ev.type)
                    {
                        case EvType.LineInput:
                            if (ev.win == currentWin)
                            {
                                done = true;
                                if (glkTerminators == null || ev.val2 == 0)
                                    terminator = 13;
                                else
                                    terminator = GlkKeyToZSCII((KeyCode)ev.val2);
                            }
                            break;

                        case EvType.Timer:
                            lineInputActive = true;
                            if (callback() == true)
                            {
                                done = true;
                            }
                            else if (!lineInputActive)
                            {
                                // the callback cancelled the line input request to print something...
                                if (unicode)
                                    Glk.glk_request_line_event_uni(currentWin, buf, BUFSIZE, canceledLineEvent.val1);
                                else
                                    Glk.glk_request_line_event(currentWin, buf, BUFSIZE, canceledLineEvent.val1);
                                if (glkTerminators != null)
                                    Glk.garglk_set_line_terminators(currentWin, glkTerminators, (uint)glkTerminators.Length);
                            }
                            break;

                        case EvType.Arrange:
                            UpdateScreenSize();
                            break;

                        case EvType.SoundNotify:
                            SoundNotify();
                            break;
                    }
                }
                while (!done);

                Glk.glk_request_timer_events(0);
                PerformSplit(targetSplit);

                // convert the string from Latin-1 or UTF-32
                int length = (int)ev.val1;
                if (unicode)
                    length *= 4;
                byte[] bytes = new byte[length];
                Marshal.Copy(buf, bytes, 0, length);
                return encoding.GetString(bytes);
            }
            finally
            {
                Marshal.FreeHGlobal(buf);
            }
        }
Exemple #37
0
 public abstract short ReadKey(int time, TimedInputCallback callback, CharTranslator translator);
Exemple #38
0
 public virtual string ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
 {
     return next.ReadLine(initial, time, callback, terminatingKeys, out terminator);
 }
Exemple #39
0
        string IZMachineIO.ReadLine(string initial, int time, TimedInputCallback callback, byte[] terminatingKeys, out byte terminator)
        {
            const int BUFSIZE  = 256;
            IntPtr    buf      = Marshal.AllocHGlobal(unicode ? BUFSIZE * 4 : BUFSIZE);
            Encoding  encoding = unicode ? Encoding.UTF32 : Encoding.GetEncoding(Glk.LATIN1);

            try
            {
                uint initlen = 0;

                if (initial.Length > 0)
                {
                    if (unicode)
                    {
                        Glk.garglk_unput_string_uni(initial);
                    }
                    else
                    {
                        Glk.garglk_unput_string(initial);
                    }

                    byte[] initBytes = encoding.GetBytes(initial);
                    Marshal.Copy(initBytes, 0, buf, initBytes.Length);

                    initlen = (uint)initBytes.Length;
                    if (unicode)
                    {
                        initlen /= 4;
                    }
                }

                if (unicode)
                {
                    Glk.glk_request_line_event_uni(currentWin, buf, BUFSIZE, initlen);
                }
                else
                {
                    Glk.glk_request_line_event(currentWin, buf, BUFSIZE, initlen);
                }
                Glk.glk_request_timer_events((uint)(time * 100));

                KeyCode[] glkTerminators = null;
                if (terminatingKeys != null && terminatingKeys.Length > 0)
                {
                    glkTerminators = GlkKeysFromZSCII(terminatingKeys);
                    Glk.garglk_set_line_terminators(currentWin, glkTerminators, (uint)glkTerminators.Length);
                }

                terminator = 0;

                event_t ev;
                bool    done = false;
                do
                {
                    Glk.glk_select(out ev);

                    switch (ev.type)
                    {
                    case EvType.LineInput:
                        if (ev.win == currentWin)
                        {
                            done = true;
                            if (glkTerminators == null || ev.val2 == 0)
                            {
                                terminator = 13;
                            }
                            else
                            {
                                terminator = GlkKeyToZSCII((KeyCode)ev.val2);
                            }
                        }
                        break;

                    case EvType.Timer:
                        lineInputActive = true;
                        if (callback() == true)
                        {
                            done = true;
                        }
                        else if (!lineInputActive)
                        {
                            // the callback cancelled the line input request to print something...
                            if (unicode)
                            {
                                Glk.glk_request_line_event_uni(currentWin, buf, BUFSIZE, canceledLineEvent.val1);
                            }
                            else
                            {
                                Glk.glk_request_line_event(currentWin, buf, BUFSIZE, canceledLineEvent.val1);
                            }
                            if (glkTerminators != null)
                            {
                                Glk.garglk_set_line_terminators(currentWin, glkTerminators, (uint)glkTerminators.Length);
                            }
                        }
                        break;

                    case EvType.Arrange:
                        UpdateScreenSize();
                        break;

                    case EvType.SoundNotify:
                        SoundNotify();
                        break;
                    }
                }while (!done);

                Glk.glk_request_timer_events(0);
                PerformSplit(targetSplit);

                // convert the string from Latin-1 or UTF-32
                int length = (int)ev.val1;
                if (unicode)
                {
                    length *= 4;
                }
                byte[] bytes = new byte[length];
                Marshal.Copy(buf, bytes, 0, length);
                return(encoding.GetString(bytes));
            }
            finally
            {
                Marshal.FreeHGlobal(buf);
            }
        }