コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="args"></param>
        /// <param name="variable"></param>
        /// <param name="suggestions"></param>
        /// <returns></returns>
        Suggestion AutoCompleteVariable(string input, string[] args, ConfigVariable variable)
        {
            var suggestion = new Suggestion(input);

            var type       = variable.TargetProperty.PropertyType;
            var candidates = new string[0];

            //
            //	Gather possible values :
            //
            if (type == typeof(bool))
            {
                candidates = new string[] { "True", "False" };
            }
            else if (type.IsEnum)
            {
                candidates = Enum.GetNames(type);
            }
            else
            {
                candidates = new string[] { variable.Get() };
            }

            //
            //	Only name of the variables is entered.
            //	Just show possible values.
            //
            if (args.Length == 1)
            {
                suggestion.Set(args[0] + " ");
                suggestion.AddRange(candidates.Select(c1 => args[0] + " " + c1));
                return(suggestion);
            }

            //
            //	Select candidates that starts with entered value.
            //
            var longest = LongestCommon(args[1], ref candidates);


            suggestion.AddRange(candidates.Select(c1 => args[0] + " " + c1));

            //	add quotes if longest common contains spaces :
            if (longest != null && longest.Any(c => char.IsWhiteSpace(c)))
            {
                longest = "\"" + longest;                // + "\"";
                if (candidates.Length == 1)
                {
                    //	only on suggestion - close quotes.
                    longest += "\"";
                }
            }
            else
            {
            }

            suggestion.Set(string.Format("{0} {1}", args[0], longest));

            return(suggestion);
        }
コード例 #2
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="input"></param>
		/// <param name="candidates"></param>
		/// <param name="suggestions">Null if no suggestions</param>
		/// <returns></returns>
		public Suggestion AutoComplete ( string input )
		{
			if (string.IsNullOrWhiteSpace(input)) {
				return new Suggestion("");
			}

			var suggestion = new Suggestion(input);

			var args = CommandLineParser.SplitCommandLine( input ).ToArray();

			var cmd  =	args[0];

			var cmdList =	CommandList
							.ToList();

			var varList	=	variables.Select( a => a.Value )
							.OrderBy( b => b.FullName )
							.ToList();


			string longestCommon = null;
			int count = 0;

			//
			//	search commands :
			//	
			foreach ( var name in cmdList ) {
				if (cmd.ToLower()==name.ToLower()) {
					return AutoCompleteCommand(input, args, name);
				}
				if (name.StartsWith(cmd, StringComparison.OrdinalIgnoreCase)) {
					longestCommon = LongestCommon( longestCommon, name );
					suggestion.Set( longestCommon );
					suggestion.Add( name );
					count++;
				}
			}

			//
			//	search variables :
			//	
			foreach ( var variable in varList ) {
				if (cmd.ToLower()==variable.FullName.ToLower()) {
					return AutoCompleteVariable( input, args, variable );
				}		   
				if (variable.FullName.StartsWith(cmd, StringComparison.OrdinalIgnoreCase)) {
					longestCommon = LongestCommon( longestCommon, variable.FullName );
					suggestion.Set( longestCommon );
					suggestion.Add( string.Format("{0,-30} = {1}", variable.FullName, variable.Get() ) );
					count++;
				}
			}

			if (count==1) {
				suggestion.Set( suggestion.CommandLine + " ");
			}

			return suggestion;
		}
コード例 #3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="input"></param>
		/// <param name="args"></param>
		/// <param name="variable"></param>
		/// <param name="suggestions"></param>
		/// <returns></returns>
		Suggestion AutoCompleteVariable ( string input, string[] args, ConfigVariable variable )
		{
			var suggestion = new Suggestion(input);

			var type = variable.Property.PropertyType;
			var candidates = new string[0];

			//
			//	Gather possible values :
			//
			if (type==typeof(bool)) {
				candidates = new string[]{"True", "False"};
			} else if (type.IsEnum) {
				candidates = Enum.GetNames(type);
			} else {
				candidates = new string[]{variable.Get()};
			}

			//
			//	Only name of the variables is entered.
			//	Just show possible values.
			//	
			if (args.Length==1) {	
				suggestion.Set( args[0] + " ");
				suggestion.AddRange( candidates.Select( c1 => args[0] + " " + c1 ) );
				return suggestion;
			}

			//
			//	Select candidates that starts with entered value.
			//
			candidates = candidates
				.Where( c => c.StartsWith( args[1], StringComparison.OrdinalIgnoreCase) )
				.ToArray();

			var longest = LongestCommon( candidates );


			suggestion.AddRange( candidates.Select( c1 => args[0] + " " + c1 ) );

			//	add quotes if longest common contains spaces :
			if (longest!=null && longest.Any( c => char.IsWhiteSpace(c) )) {
				longest = "\"" + longest;// + "\"";
				if (candidates.Length==1) {
					//	only on suggestion - close quotes.
					longest += "\"";
				}
			} else {
			}

			suggestion.Set( string.Format("{0} {1}", args[0], longest) );

			return suggestion;
		}