Browse Source

xmldoc and tidying

Thomas 2 years ago
parent
commit
14b34295ea

+ 34 - 9
Terminal.Gui/Core/Autocomplete/AppendAutocomplete.cs

@@ -1,6 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
 using System.IO;
 using System.Linq;
 
@@ -14,20 +12,48 @@ namespace Terminal.Gui {
 
 		private TextField textField;
 
+		/// <inheritdoc/>
 		public override View HostControl { get => textField; set => textField = (TextField)value; }
+
+		/// <summary>
+		/// The color used for rendering the appended text. Note that only
+		/// <see cref="ColorScheme.Normal"/> is used and then only <see cref="Attribute.Foreground"/>
+		/// (Background comes from <see cref="HostControl"/>).
+		/// </summary>
 		public override ColorScheme ColorScheme { get; set; }
 
+		/// <summary>
+		///	Creates a new instance of the <see cref="AppendAutocomplete"/> class.
+		/// </summary>
+		public AppendAutocomplete (TextField textField)
+		{
+			this.textField = textField;
+			SelectionKey = Key.Tab;
+
+
+			ColorScheme = new ColorScheme{
+				Normal = new Attribute(Color.DarkGray,0),
+				Focus = new Attribute(Color.DarkGray,0),
+				HotNormal = new Attribute(Color.DarkGray,0),
+				HotFocus = new Attribute(Color.DarkGray,0),
+				Disabled = new Attribute(Color.DarkGray,0),
+			};
+		}
+
+		/// <inheritdoc/>
 		public override void ClearSuggestions ()
 		{
 			base.ClearSuggestions ();
 			textField.SetNeedsDisplay ();
 		}
 
+		/// <inheritdoc/>
 		public override bool MouseEvent (MouseEvent me, bool fromHost = false)
 		{
 			return false;
 		}
 
+		/// <inheritdoc/>
 		public override bool ProcessKey (KeyEvent kb)
 		{
 			var key = kb.Key;
@@ -55,6 +81,8 @@ namespace Terminal.Gui {
 			return false;
 		}
 		bool _suspendSuggestions = false;
+
+		/// <inheritdoc/>
 		public override void GenerateSuggestions (AutocompleteContext context)
 		{
 			if(_suspendSuggestions)
@@ -64,6 +92,9 @@ namespace Terminal.Gui {
 			base.GenerateSuggestions (context);
 		}
 
+		/// <summary>
+		/// Renders the current suggestion into the <see cref="TextField"/>
+		/// </summary>
 		public override void RenderOverlay (Point renderAt)
 		{
 			if (!this.MakingSuggestion ()) {
@@ -71,7 +102,7 @@ namespace Terminal.Gui {
 			}
 
 			// draw it like its selected even though its not
-			Application.Driver.SetAttribute (new Attribute (Color.DarkGray, textField.ColorScheme.Focus.Background));
+			Application.Driver.SetAttribute (new Attribute (ColorScheme.Normal.Foreground, textField.ColorScheme.Focus.Background));
 			textField.Move (textField.Text.Length, 0);
 
 			var suggestion = this.Suggestions.ElementAt (this.SelectedIdx);
@@ -91,12 +122,6 @@ namespace Terminal.Gui {
 			Application.Driver.AddStr (fragment);
 		}
 
-		public AppendAutocomplete (TextField textField)
-		{
-			this.textField = textField;
-			SelectionKey = Key.Tab;
-		}
-
 		/// <summary>
 		/// Accepts the current autocomplete suggestion displaying in the text box.
 		/// Returns true if a valid suggestion was being rendered and acceptable or

+ 5 - 14
Terminal.Gui/Core/Autocomplete/AutocompleteBase.cs

@@ -1,23 +1,13 @@
 using System;
-using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
-using System.Text;
-using Rune = System.Rune;
 
 namespace Terminal.Gui {
-	public class AutocompleteContext
-	{
-		public List<Rune> CurrentLine { get; set; }
-		public int Idx { get; set; }
-
-		public AutocompleteContext (List<Rune> currentLine, int idx)
-		{
-			CurrentLine = currentLine;
-			Idx = idx;
-		}
-	}
 
+	/// <summary>
+	/// Abstract implementation of <see cref="IAutocomplete"/> allows
+	/// for tailoring how autocomplete is rendered/interacted with.
+	/// </summary>
 	public abstract class AutocompleteBase : IAutocomplete {
 
 		/// <inheritdoc/>
@@ -25,6 +15,7 @@ namespace Terminal.Gui {
 		/// <inheritdoc/>
 		public bool PopupInsideContainer { get; set; }
 
+		/// <inheritdoc/>
 		public ISuggestionGenerator SuggestionGenerator { get; set; } = new SingleWordSuggestionGenerator ();
 
 		/// <inheritdoc/>

+ 31 - 0
Terminal.Gui/Core/Autocomplete/AutocompleteContext.cs

@@ -0,0 +1,31 @@
+using System.Collections.Generic;
+using Rune = System.Rune;
+
+namespace Terminal.Gui {
+	/// <summary>
+	/// Describes the current state of a <see cref="View"/> which
+	/// is proposing autocomplete. Suggestions are based on this state.
+	/// </summary>
+	public class AutocompleteContext
+	{
+		/// <summary>
+		/// The text on the current line.
+		/// </summary>
+		public List<Rune> CurrentLine { get; set; }
+
+		/// <summary>
+		/// The position of the input cursor within the <see cref="CurrentLine"/>.
+		/// </summary>
+		public int CursorPosition { get; set; }
+
+		/// <summary>
+		/// Creates anew instance of the <see cref="AutocompleteContext"/> class
+		/// </summary>
+		public AutocompleteContext (List<Rune> currentLine, int cursorPosition)
+		{
+			CurrentLine = currentLine;
+			CursorPosition = cursorPosition;
+		}
+	}
+}
+

+ 6 - 1
Terminal.Gui/Core/Autocomplete/IAutocomplete.cs

@@ -48,7 +48,7 @@ namespace Terminal.Gui {
 		int SelectedIdx { get; set; }
 
 		/// <summary>
-		/// The colors to use to render the overlay.  Accessing this property before
+		/// The colors to use to render the overlay. Accessing this property before
 		/// the Application has been initialized will cause an error
 		/// </summary>
 		ColorScheme ColorScheme { get; set; }
@@ -100,6 +100,11 @@ namespace Terminal.Gui {
 		/// </summary>
 		void ClearSuggestions ();
 
+
+		/// <summary>
+		/// Gets or Sets the class responsible for generating <see cref="Suggestions"/>
+		/// based on a given <see cref="AutocompleteContext"/> of the <see cref="HostControl"/>.
+		/// </summary>
 		ISuggestionGenerator SuggestionGenerator { get; set; }
 
 

+ 6 - 0
Terminal.Gui/Core/Autocomplete/ISuggestionGenerator.cs

@@ -12,6 +12,12 @@ namespace Terminal.Gui {
 		/// </summary>
 		IEnumerable<Suggestion> GenerateSuggestions (AutocompleteContext context);
 
+
+		/// <summary>
+		/// Returns <see langword="true"/> if <paramref name="rune"/> is a character that
+		/// would continue autocomplete suggesting. Returns <see langword="false"/> if it
+		/// is a 'breaking' character (i.e. terminating current word boundary)
+		/// </summary>
 		bool IsWordChar (Rune rune);
 
 	}

+ 9 - 5
Terminal.Gui/Core/Autocomplete/PopupAutocomplete.cs

@@ -74,6 +74,9 @@ namespace Terminal.Gui {
 			}
 		}
 
+		/// <summary>
+		/// Creates a new instance of the <see cref="PopupAutocomplete"/> class.
+		/// </summary>
 		public PopupAutocomplete ()
 		{
 			PopupInsideContainer = true;
@@ -120,13 +123,13 @@ namespace Terminal.Gui {
 
 		/// <summary>
 		/// When more suggestions are available than can be rendered the user
-		/// can scroll down the dropdown list.  This indicates how far down they
+		/// can scroll down the dropdown list. This indicates how far down they
 		/// have gone
 		/// </summary>
 		public virtual int ScrollOffset { get; set; }
 
 		/// <summary>
-		/// The colors to use to render the overlay.  Accessing this property before
+		/// The colors to use to render the overlay. Accessing this property before
 		/// the Application has been initialized will cause an error
 		/// </summary>
 		public override ColorScheme ColorScheme {
@@ -248,6 +251,7 @@ namespace Terminal.Gui {
 			}
 		}
 
+		/// <inheritdoc/>
 		public override void EnsureSelectedIdxIsValid ()
 		{
 			base.EnsureSelectedIdxIsValid ();
@@ -408,7 +412,7 @@ namespace Terminal.Gui {
 
 
 		/// <summary>
-		/// Completes the autocomplete selection process.  Called when user hits the <see cref="IAutocomplete.SelectionKey"/>.
+		/// Completes the autocomplete selection process. Called when user hits the <see cref="IAutocomplete.SelectionKey"/>.
 		/// </summary>
 		/// <returns></returns>
 		protected bool Select ()
@@ -425,8 +429,8 @@ namespace Terminal.Gui {
 
 		/// <summary>
 		/// Called when the user confirms a selection at the current cursor location in
-		/// the <see cref="HostControl"/>.  The <paramref name="accepted"/> string
-		/// is the full autocomplete word to be inserted.  Typically a host will have to
+		/// the <see cref="HostControl"/>. The <paramref name="accepted"/> string
+		/// is the full autocomplete word to be inserted. Typically a host will have to
 		/// remove some characters such that the <paramref name="accepted"/> string 
 		/// completes the word instead of simply being appended.
 		/// </summary>

+ 13 - 4
Terminal.Gui/Core/Autocomplete/SingleWordSuggestionGenerator.cs

@@ -5,13 +5,22 @@ using System.Text;
 using Rune = System.Rune;
 
 namespace Terminal.Gui {
+	
+	/// <summary>
+	/// <see cref="ISuggestionGenerator"/> which suggests from a collection
+	/// of words those that match the <see cref="AutocompleteContext"/>. You
+	/// can update <see cref="AllSuggestions"/> at any time to change candidates
+	/// considered for autocomplete.
+	/// </summary>
 	public class SingleWordSuggestionGenerator : ISuggestionGenerator {
+
 		/// <summary>
 		/// The full set of all strings that can be suggested.
 		/// </summary>
 		/// <returns></returns>
 		public virtual List<string> AllSuggestions { get; set; } = new List<string> ();
 
+		/// <inheritdoc/>
 		public IEnumerable<Suggestion> GenerateSuggestions (AutocompleteContext context)
 		{
 			// if there is nothing to pick from
@@ -19,7 +28,7 @@ namespace Terminal.Gui {
 				return Enumerable.Empty<Suggestion> ();
 			}
 
-			var currentWord = IdxToWord (context.CurrentLine, context.Idx);
+			var currentWord = IdxToWord (context.CurrentLine, context.CursorPosition);
 
 			if (string.IsNullOrWhiteSpace (currentWord)) {
 				return Enumerable.Empty<Suggestion> ();
@@ -35,7 +44,7 @@ namespace Terminal.Gui {
 
 		/// <summary>
 		/// Return true if the given symbol should be considered part of a word
-		/// and can be contained in matches.  Base behavior is to use <see cref="char.IsLetterOrDigit(char)"/>
+		/// and can be contained in matches. Base behavior is to use <see cref="char.IsLetterOrDigit(char)"/>
 		/// </summary>
 		/// <param name="rune"></param>
 		/// <returns></returns>
@@ -48,7 +57,7 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// <para>
 		/// Given a <paramref name="line"/> of characters, returns the word which ends at <paramref name="idx"/> 
-		/// or null.  Also returns null if the <paramref name="idx"/> is positioned in the middle of a word.
+		/// or null. Also returns null if the <paramref name="idx"/> is positioned in the middle of a word.
 		/// </para>
 		/// 
 		/// <para>
@@ -81,7 +90,7 @@ namespace Terminal.Gui {
 				return null;
 			}
 
-			// we are at the end of a word.  Work out what has been typed so far
+			// we are at the end of a word. Work out what has been typed so far
 			while (endIdx-- > 0) {
 				if (IsWordChar (line [endIdx])) {
 					sb.Insert (0, (char)line [endIdx]);

+ 1 - 1
Terminal.Gui/Core/Autocomplete/Suggestion.cs

@@ -10,7 +10,7 @@
 		public int Remove { get; }
 
 		/// <summary>
-		/// The user visible description for the <see cref="Replacement"/>.  Typically
+		/// The user visible description for the <see cref="Replacement"/>. Typically
 		/// this would be the same as <see cref="Replacement"/> but may vary in advanced
 		/// use cases (e.g. Title= "ctor", Replacement = "MyClass()\n{\n}")
 		/// </summary>