]> khamidou — GitHub mirrors - te.git/commitdiff
implemented backspace support
authorkhamidou <karim@lambda-expr.org>
Wed, 8 Jul 2009 17:56:06 +0000 (19:56 +0200)
committerkhamidou <karim@lambda-expr.org>
Wed, 8 Jul 2009 17:56:06 +0000 (19:56 +0200)
buffer.c
buffer.h
keyb.c
screen.c

index 0d204237c613509d84b7f45ab03ce67ea2fd6f12..a0276afa234f16863c91906fa67c025d839855f3 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -207,8 +207,32 @@ void insert_char(struct te_buffer *buf, char c)
                return;
 
        binsertch(buf->contents, buf->point, 1, c);
+       return;
+}
+
+void delete_char(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
 
+       bdelete(buf->contents, buf->point, 1);
+       move_left(buf);
        return;
 }
 
+void write_buffer(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
+
+       char *c = bstr2cstr(buf->contents, '\0');
+       FILE *fp = fopen(buf->name, "w+");
+
+       if (fp == NULL)
+               notifyprintf("Unable to open %s", buf->name);
+
+       fwrite(c, strlen(c), sizeof(char), fp);
+
+       free(c);
+}
 
index 98f6e175601e98d8b068e297ddd095572eccee24..d5aa5b4b2750e3216cd133c3ce6ab280f57188ee 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -33,5 +33,6 @@ int                           next_char(struct te_buffer *buf);
 int                            move_right(struct te_buffer *buf);
 int                            move_left(struct te_buffer *buf);
 void                           insert_char(struct te_buffer *buf, char c);
+void                           delete_char(struct te_buffer *buf);
 
 #endif
diff --git a/keyb.c b/keyb.c
index d0089b6b09cfa572ae15459a6f6490e158809efa..e14c061abae5c042a162884edc234d6c66b25e09 100644 (file)
--- a/keyb.c
+++ b/keyb.c
@@ -25,6 +25,10 @@ void input_loop(void)
                        screen_move_up(current_buf);
                        break;
 
+               case KEY_BACKSPACE:
+                       screen_delete_char(current_buf);
+                       break;
+
                case 'u':
                        wscrl(buffer_win, -10);
                        touchwin(stdscr);
index 358bed72968cdd260f3d9462202d87631664eabb..acb7f8192b460e8c0f52b0d4bce4c76ddc1329fc 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -251,6 +251,19 @@ void screen_insert_char(struct te_buffer *buf, char c)
        
 }
 
+void screen_delete_char(struct te_buffer *buf)
+{
+       if (buf == NULL)
+               return;
+
+       delete_char(buf);
+       
+       bstring s = current_line_as_bstring(buf->contents, buf->point);
+       draw_line(s, buf->y);
+       screen_move_left(buf);
+       move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */
+}
+
 /*
   display a message in the status bar.
  */
@@ -300,6 +313,21 @@ void miniprintf(char *fmt, ...)
        restoreyx();
 }
 
+/*
+  notifyprintf : display a message in the minibuffer and wait that the user
+                presses a key.
+ */
+void notifyprintf(char *fmt, ...)
+{
+       va_list ap;
+       va_start(ap, fmt);
+       miniprintf(fmt, ap);
+       va_end(ap);
+
+       getch(); /* discard input */
+}
+
+
 void console_signal_handler(int sig)
 {
        switch(sig) {