Permalink
Browse files

Add word navigation, expose UsingColor, expose MakeColor

svn path=/trunk/mono-curses/; revision=144334
  • Loading branch information...
migueldeicaza committed Oct 18, 2009
1 parent 79d539a commit c1e31907e63e27e2403e42aa2573b800c01ccbaa
Showing with 159 additions and 6 deletions.
  1. +38 −0 docs/Mono.Terminal/Application.xml
  2. +15 −0 docs/Mono.Terminal/Curses.xml
  3. +17 −0 docs/Mono.Terminal/Entry.xml
  4. +89 −6 gui.cs
@@ -510,6 +510,29 @@
<AssemblyVersion>1.0.0.0</AssemblyVersion>
</AssemblyInfo>
</Member>
+ <Member MemberName="MakeColor">
+ <MemberSignature Language="C#" Value="public static int MakeColor (short f, short b);" />
+ <MemberType>Method</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>1.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Int32</ReturnType>
+ </ReturnValue>
+ <Parameters>
+ <Parameter Name="f" Type="System.Int16" />
+ <Parameter Name="b" Type="System.Int16" />
+ </Parameters>
+ <Docs>
+ <param name="f">To be added.</param>
+ <param name="b">To be added.</param>
+ <summary>
+ Creates a new Curses color to be used by Gui.cs apps
+ </summary>
+ <returns>To be added.</returns>
+ <remarks>To be added.</remarks>
+ </Docs>
+ </Member>
<Member MemberName="MouseEventsAvailable">
<MemberSignature Language="C#" Value="public static Mono.Terminal.Curses.Event MouseEventsAvailable;" />
<MemberType>Field</MemberType>
@@ -624,5 +647,20 @@
<AssemblyVersion>1.0.0.0</AssemblyVersion>
</AssemblyInfo>
</Member>
+ <Member MemberName="UsingColor">
+ <MemberSignature Language="C#" Value="public static bool UsingColor { get; }" />
+ <MemberType>Property</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>1.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Boolean</ReturnType>
+ </ReturnValue>
+ <Docs>
+ <summary>To be added.</summary>
+ <value>To be added.</value>
+ <remarks>To be added.</remarks>
+ </Docs>
+ </Member>
</Members>
</Type>
@@ -1005,6 +1005,21 @@
<AssemblyVersion>1.0.0.0</AssemblyVersion>
</AssemblyInfo>
</Member>
+ <Member MemberName="KeyInsertChar">
+ <MemberSignature Language="C#" Value="public const int KeyInsertChar = 331;" />
+ <MemberType>Field</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>1.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Int32</ReturnType>
+ </ReturnValue>
+ <MemberValue>331</MemberValue>
+ <Docs>
+ <summary>To be added.</summary>
+ <remarks>To be added.</remarks>
+ </Docs>
+ </Member>
<Member MemberName="KeyLeft">
<MemberSignature Language="C#" Value="public const int KeyLeft = 260;" />
<MemberType>Field</MemberType>
@@ -79,6 +79,23 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
+ <Member MemberName="CursorPosition">
+ <MemberSignature Language="C#" Value="public int CursorPosition { get; }" />
+ <MemberType>Property</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>1.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Int32</ReturnType>
+ </ReturnValue>
+ <Docs>
+ <summary>
+ The current cursor position.
+ </summary>
+ <value>To be added.</value>
+ <remarks>To be added.</remarks>
+ </Docs>
+ </Member>
<Member MemberName="PositionCursor">
<MemberSignature Language="C#" Value="public override void PositionCursor ();" />
<MemberType>Method</MemberType>
View
95 gui.cs
@@ -661,6 +661,11 @@ public Entry (int x, int y, int w, string s) : base (x, y, w, 1)
get { return color; }
set { color = value; Container.Redraw (); }
}
+
+ /// <summary>
+ /// The current cursor position.
+ /// </summary>
+ public int CursorPosition { get { return point; }}
/// <summary>
/// Sets the cursor position.
@@ -748,7 +753,7 @@ public override bool ProcessKey (int key)
point++;
Adjust ();
break;
-
+
case 11: // Control-k, kill-to-end
kill = text.Substring (point);
SetText (text.Substring (0, point));
@@ -768,7 +773,21 @@ public override bool ProcessKey (int key)
}
Adjust ();
break;
-
+
+ case (int) 'b' + Curses.KeyAlt:
+ int bw = WordBackward (point);
+ if (bw != -1)
+ point = bw;
+ Adjust ();
+ break;
+
+ case (int) 'f' + Curses.KeyAlt:
+ int fw = WordForward (point);
+ if (fw != -1)
+ point = fw;
+ Adjust ();
+ break;
+
default:
// Ignore other control characters.
if (key < 32 || key > 255)
@@ -786,6 +805,65 @@ public override bool ProcessKey (int key)
return true;
}
+ int WordForward (int p)
+ {
+ if (p >= text.Length)
+ return -1;
+
+ int i = p;
+ if (Char.IsPunctuation (text [p]) || Char.IsWhiteSpace (text[p])){
+ for (; i < text.Length; i++){
+ if (Char.IsLetterOrDigit (text [i]))
+ break;
+ }
+ for (; i < text.Length; i++){
+ if (!Char.IsLetterOrDigit (text [i]))
+ break;
+ }
+ } else {
+ for (; i < text.Length; i++){
+ if (!Char.IsLetterOrDigit (text [i]))
+ break;
+ }
+ }
+ if (i != p)
+ return i;
+ return -1;
+ }
+
+ int WordBackward (int p)
+ {
+ if (p == 0)
+ return -1;
+
+ int i = p-1;
+ if (i == 0)
+ return 0;
+
+ if (Char.IsPunctuation (text [i]) || Char.IsSymbol (text [i]) || Char.IsWhiteSpace (text[i])){
+ for (; i >= 0; i--){
+ if (Char.IsLetterOrDigit (text [i]))
+ break;
+ }
+ for (; i >= 0; i--){
+ if (!Char.IsLetterOrDigit (text[i]))
+ break;
+ }
+ } else {
+ for (; i >= 0; i--){
+ if (!Char.IsLetterOrDigit (text [i]))
+ break;
+ }
+ }
+ i++;
+
+ if (i != p)
+ return i;
+
+ return -1;
+ }
+
+
public override void ProcessMouse (Curses.MouseEvent ev)
{
if ((ev.ButtonState & Curses.Event.Button1Clicked) == 0)
@@ -2271,7 +2349,10 @@ public class Application {
/// </summary>
public static Curses.Event MouseEventsAvailable;
- static int MakeColor (short f, short b)
+ /// <summary>
+ /// Creates a new Curses color to be used by Gui.cs apps
+ /// </summary>
+ public static int MakeColor (short f, short b)
{
Curses.init_pair (++last_color_pair, f, b);
return Curses.ColorPair (last_color_pair);
@@ -2285,6 +2366,8 @@ static int MakeColor (short f, short b)
return empty_container;
}
}
+
+ public static bool UsingColor { get; private set; }
/// <summary>
/// Initializes the runtime. The boolean flag
@@ -2309,13 +2392,13 @@ public static void Init (bool disable_color)
MouseEventsAvailable = Curses.console_sharp_mouse_mask (
Curses.Event.Button1Clicked | Curses.Event.Button1DoubleClicked, out old);
- bool use_color = false;
+ UsingColor = false;
if (!disable_color)
- use_color = Curses.has_colors ();
+ UsingColor = Curses.has_colors ();
Curses.start_color ();
Curses.use_default_colors ();
- if (use_color){
+ if (UsingColor){
ColorNormal = MakeColor (Curses.COLOR_WHITE, Curses.COLOR_BLUE);
ColorFocus = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_CYAN);
ColorHotNormal = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLUE);

0 comments on commit c1e3190

Please sign in to comment.