Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit Add a function to move the cursor.



details:   https://anonhg.NetBSD.org/src/rev/f61a61adcfe2
branches:  trunk
changeset: 787910:f61a61adcfe2
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jul 12 17:48:29 2013 +0000

description:
Add a function to move the cursor.

diffstat:

 lib/libedit/chared.c   |  23 +++++++++++++++++++++--
 lib/libedit/editline.3 |  14 ++++++++++++--
 lib/libedit/histedit.h |   3 ++-
 3 files changed, 35 insertions(+), 5 deletions(-)

diffs (112 lines):

diff -r 1bd29fe790cb -r f61a61adcfe2 lib/libedit/chared.c
--- a/lib/libedit/chared.c      Fri Jul 12 17:32:47 2013 +0000
+++ b/lib/libedit/chared.c      Fri Jul 12 17:48:29 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.c,v 1.37 2012/07/18 17:12:39 christos Exp $     */
+/*     $NetBSD: chared.c,v 1.38 2013/07/12 17:48:29 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)chared.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: chared.c,v 1.37 2012/07/18 17:12:39 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.38 2013/07/12 17:48:29 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -644,6 +644,25 @@
                el->el_line.cursor = el->el_line.buffer;
 }
 
+/* el_cursor():
+ *     Move the cursor to the left or the right of the current position
+ */
+public int
+el_cursor(EditLine *el, int n)
+{
+       if (n == 0)
+               goto out;
+
+       el->el_line.cursor += n;
+
+       if (el->el_line.cursor < el->el_line.buffer)
+               el->el_line.cursor = el->el_line.buffer;
+       if (el->el_line.cursor > el->el_line.lastchar)
+               el->el_line.cursor = el->el_line.lastchar;
+out:
+       return el->el_line.cursor - el->el_line.buffer;
+}
+
 /* c_gets():
  *     Get a string
  */
diff -r 1bd29fe790cb -r f61a61adcfe2 lib/libedit/editline.3
--- a/lib/libedit/editline.3    Fri Jul 12 17:32:47 2013 +0000
+++ b/lib/libedit/editline.3    Fri Jul 12 17:48:29 2013 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: editline.3,v 1.79 2013/01/22 20:23:21 christos Exp $
+.\"    $NetBSD: editline.3,v 1.80 2013/07/12 17:48:29 christos Exp $
 .\"
 .\" Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 22, 2013
+.Dd July 12, 2013
 .Dt EDITLINE 3
 .Os
 .Sh NAME
@@ -49,6 +49,7 @@
 .Nm el_wget ,
 .Nm el_source ,
 .Nm el_resize ,
+.Nm el_cursor ,
 .Nm el_line ,
 .Nm el_wline ,
 .Nm el_insertstr ,
@@ -112,8 +113,12 @@
 .Fn el_source "EditLine *e" "const char *file"
 .Ft void
 .Fn el_resize "EditLine *e"
+.Fn int
+.Fn el_cursor "EditLine *e" "int count"
 .Ft const LineInfo *
 .Fn el_line "EditLine *e"
+.Ft const LineInfoW *
+.Fn el_wline "EditLine *e"
 .Ft int
 .Fn el_insertstr "EditLine *e" "const char *str"
 .Ft int
@@ -610,6 +615,11 @@
 Otherwise, it's the responsibility of the application to call
 .Fn el_resize
 on the appropriate occasions.
+.It Fn el_cursor
+Move the cursor to the right (if positive) or to the left (if negative)
+.Fa count
+characters.
+Returns the resulting offset of the cursor from the beginning of the line.
 .It Fn el_line
 Return the editing information for the current line in a
 .Fa LineInfo
diff -r 1bd29fe790cb -r f61a61adcfe2 lib/libedit/histedit.h
--- a/lib/libedit/histedit.h    Fri Jul 12 17:32:47 2013 +0000
+++ b/lib/libedit/histedit.h    Fri Jul 12 17:48:29 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.h,v 1.50 2013/01/22 20:23:21 christos Exp $   */
+/*     $NetBSD: histedit.h,v 1.51 2013/07/12 17:48:29 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -279,6 +279,7 @@
 int             el_wset(EditLine *, int, ...);
 int             el_wget(EditLine *, int, ...);
 
+int             el_cursor(EditLine *, int);
 const LineInfoW        *el_wline(EditLine *);
 int             el_winsertstr(EditLine *, const wchar_t *);
 #define          el_wdeletestr  el_deletestr



Home | Main Index | Thread Index | Old Index