예제 #1
0
		public override bool Flush()
		{
			Collection.List<char> accumulator = new Collection.List<char>();
			while (!this.queue.Empty)
				foreach (char c in this.queue.Dequeue())
					accumulator.Add(c);
			System.Diagnostics.Debug.Write(new string(accumulator.ToArray()));
			return true;
		}
예제 #2
0
파일: VT100.cs 프로젝트: imintsystems/Kean
		char[] FilterInput(Func<char?> read)
		{
			Collection.IList<char> buffer = new Collection.List<char>();
			char? next;
			while (buffer.Count <= 0 && (next = read()).HasValue)
				switch (next.Value)
				{
					case '\x1b': // ESC
						if ((next = read()).HasValue)
							switch (next.Value)
							{
								case '[': // Arrow keys
									if ((next = read()).HasValue)
										switch (next.Value)
										{
											case 'A': this.OnCommand(EditCommand.UpArrow); break;
											case 'B': this.OnCommand(EditCommand.DownArrow); break;
											case 'C': this.OnCommand(EditCommand.RightArrow); break;
											case 'D': this.OnCommand(EditCommand.LeftArrow); break;
											case '1':
												if ((next = read()).HasValue)
													switch (next.Value)
													{
														case '~': this.OnCommand(EditCommand.Home); break;
													}
												break;
											case '3':
												if ((next = read()).HasValue)
													switch (next.Value)
													{
														case '~': this.OnCommand(EditCommand.Delete); break;
													}
												break;
											case '4':
												if ((next = read()).HasValue)
													switch (next.Value)
													{
														case '~': this.OnCommand(EditCommand.End); break;
													}
												break;
											case '?':
												System.Text.StringBuilder type = new System.Text.StringBuilder();
												while ((next = read()).HasValue && next != 'c')
													type.Append(next.Value);
												string[] parameters = type.ToString().Split(';');
												if (parameters.Length > 0)
													switch (parameters[0])
													{
														default:
														case "1":
															this.Level = OperatingLevel.VT100;
															break;
														case "6":
														case "62":
														case "63":
														case "64":
															this.Level = OperatingLevel.VT400;
															break;
													}
												break;
										}
									break;
							}
						break;
					case '\x7f': //Delete
						switch(this.Level)
						{
							case OperatingLevel.VT100:
								this.OnCommand(EditCommand.Delete);
								break;
							case OperatingLevel.VT400:
								this.OnCommand(EditCommand.Backspace); 
								break;
						}
						break;
					default:
						buffer.Add(next.Value);
						break;
				}
			return buffer.ToArray();
		}
예제 #3
0
		char[] FilterInput(Func<char?> read)
		{
			Collection.IList<char> buffer = new Collection.List<char>();
			char? next;
			while (buffer.Count <= 0 && (next = read()).HasValue)
				switch (next.Value)
				{
					case '\0':
						break;
					case '\x04':
						this.OnCommand(EditCommand.Exit);
						break;
					case '\b':
						this.OnCommand(EditCommand.Backspace);
						break;
					case '\t':
						this.OnCommand(EditCommand.Tab);
						break;
					case '\n':
						this.OnCommand(EditCommand.Enter);
						break;
					case '\r':
						this.OnCommand(EditCommand.Enter);
						if ((next = read()).HasValue && (next.Value != '\n' && next.Value != '\0'))
							buffer.Add(next.Value);
						break;
					default:
						buffer.Add(next.Value);
						break;
				}
			return buffer.ToArray();
		}
예제 #4
0
파일: Parser.cs 프로젝트: imintsystems/Kean
		/// <summary>
		/// Parses the argument list and activates the respective callbacks.
		/// </summary>
		/// <param name="arguments">Argument list to parse.</param>
		/// <returns></returns>
		public bool Parse(string[] arguments)
		{
			bool result = true;
			Collection.Queue<Token> tokens = new Collection.Queue<Token>();
			foreach(string argument in arguments)
			{
				if (argument.StartsWith("--"))
					tokens.Enqueue(new Token(TokenType.Long, argument.Substring(2)));
				else if (argument.StartsWith("-") && argument.Length > 1 && char.IsLetter(argument[1]))
				{
					foreach (char c in argument.Substring(1))
						tokens.Enqueue(new Token(TokenType.Short, c.ToString()));
				}
				else
					tokens.Enqueue(new Token(TokenType.Parameter, argument));
			}
			while (tokens.Count > 0 && result)
			{
				Argument argument = null;
				switch (tokens.Peek().Type)
				{
					case TokenType.Long:
						argument = this[tokens.Dequeue().Value];
						break;
					case TokenType.Short:
						argument = this[tokens.Dequeue().Value[0]];
						break;
					case TokenType.Parameter:
						this.UnassociatedParameterHandler.Call(tokens.Dequeue().Value);
						break;
				}
				if (argument.NotNull() && result)
				{
					Collection.List<string> parameters = new Collection.List<string>();
					for (int i = 0; i < argument.Parameters && result; i++)
					{
						if (!tokens.Empty && tokens.Peek().Type == TokenType.Parameter)
							parameters.Add(tokens.Dequeue().Value);
						else
							result = false;
					}
					if (result)
						argument.Handler(parameters.ToArray());
				}
			}
			return result;
		}
예제 #5
0
파일: Parser.cs 프로젝트: imintsystems/Kean
        Tuple<string, Member, string[]> Parse(string line)
        {
            string prefix = "";
            Member member;
            if (line.StartsWith(".."))
            {
                member = this.Current.Parent;
                if (member.IsNull())
                    member = this.Current;
                else
                    prefix = "..";
                line = line.Substring(2);
            }
            else if (line.StartsWith("."))
            {
                member = this.Root;
                if (this.current != member)
                    prefix = ".";
                line = line.Substring(1);
            }
            else
                member = this.current;

            string[] splitted = line.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
            Collection.List<string> parameters = new Collection.List<string>();
            if (splitted.Length > 0)
            {
                foreach (string name in splitted[0].Split(new char[] { '.' }))
                    if (member is Object)
                    {
                        Member next = (member as Object).Find(m => m.Name == name);
                        if (next.IsNull())
                        {
                            parameters.Add(name);
                            break;
                        }
                        else
                            member = next;
                    }
                if (splitted.Length > 1)
                    parameters.Add(splitted[1].SplitAt());
            }
            return Tuple.Create(prefix, member, parameters.ToArray());
        }