about summary refs log tree commit diff stats
path: root/termbox
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-05-04 23:13:30 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-05-04 23:20:37 -0700
commit769a68cf1df678270f28c55a39f0aeca964aaf25 (patch)
tree4a6c826b6208aa70628c825f070379c1f941cbb2 /termbox
parentb8263692a6f2865482abbc21eae5a4e5163ab725 (diff)
downloadmu-769a68cf1df678270f28c55a39f0aeca964aaf25.tar.gz
3842
Always start with an untouched screen that can scroll on printing "\r\n".
We can still clear the screen as needed.

Also drop support for hiding the cursor.
Diffstat (limited to 'termbox')
-rw-r--r--termbox/termbox.c21
-rw-r--r--termbox/termbox.h3
-rw-r--r--termbox/x.cc4
3 files changed, 7 insertions, 21 deletions
diff --git a/termbox/termbox.c b/termbox/termbox.c
index 7fff7d7c..6a22f109 100644
--- a/termbox/termbox.c
+++ b/termbox/termbox.c
@@ -23,7 +23,6 @@ extern int wcwidth (wchar_t);
 #include "output.inl"
 #include "input.inl"
 
-#define IS_CURSOR_HIDDEN(cx, cy) (cx == -1 || cy == -1)
 #define LAST_COORD_INIT -1
 
 static struct termios orig_tios;
@@ -39,8 +38,8 @@ static int winch_fds[2];
 
 static int lastx = LAST_COORD_INIT;
 static int lasty = LAST_COORD_INIT;
-static int cursor_x = -1;
-static int cursor_y = -1;
+static int cursor_x = 0;
+static int cursor_y = 0;
 
 static uint16_t background = TB_BLACK;
 static uint16_t foreground = TB_WHITE;
@@ -102,11 +101,10 @@ int tb_init(void)
   bytebuffer_init(&input_buffer, 128);
   bytebuffer_init(&output_buffer, 32 * 1024);
 
-  bytebuffer_puts(&output_buffer, funcs[T_ENTER_CA]);
   bytebuffer_puts(&output_buffer, funcs[T_ENTER_KEYPAD]);
-  bytebuffer_puts(&output_buffer, funcs[T_HIDE_CURSOR]);
   bytebuffer_puts(&output_buffer, funcs[T_ENTER_MOUSE]);
   bytebuffer_puts(&output_buffer, funcs[T_ENTER_BRACKETED_PASTE]);
+  bytebuffer_flush(&output_buffer, inout);
 
   update_term_size();
   return 0;
@@ -116,10 +114,7 @@ void tb_shutdown(void)
 {
   if (termw == -1) return;
 
-  bytebuffer_puts(&output_buffer, funcs[T_SHOW_CURSOR]);
   bytebuffer_puts(&output_buffer, funcs[T_SGR0]);
-  bytebuffer_puts(&output_buffer, funcs[T_CLEAR_SCREEN]);
-  bytebuffer_puts(&output_buffer, funcs[T_EXIT_CA]);
   bytebuffer_puts(&output_buffer, funcs[T_EXIT_KEYPAD]);
   bytebuffer_puts(&output_buffer, funcs[T_EXIT_MOUSE]);
   bytebuffer_puts(&output_buffer, funcs[T_EXIT_BRACKETED_PASTE]);
@@ -144,14 +139,9 @@ int tb_is_active(void)
 void tb_set_cursor(int cx, int cy)
 {
   assert(termw != -1);
-  if (IS_CURSOR_HIDDEN(cursor_x, cursor_y) && !IS_CURSOR_HIDDEN(cx, cy))
-    bytebuffer_puts(&output_buffer, funcs[T_SHOW_CURSOR]);
-  if (!IS_CURSOR_HIDDEN(cursor_x, cursor_y) && IS_CURSOR_HIDDEN(cx, cy))
-    bytebuffer_puts(&output_buffer, funcs[T_HIDE_CURSOR]);
   cursor_x = cx;
   cursor_y = cy;
-  if (!IS_CURSOR_HIDDEN(cursor_x, cursor_y))
-    write_cursor(cursor_x, cursor_y);
+  write_cursor(cursor_x, cursor_y);
   bytebuffer_flush(&output_buffer, inout);
 }
 
@@ -316,8 +306,7 @@ static void send_clear(void)
 {
   send_attr(foreground, background);
   bytebuffer_puts(&output_buffer, funcs[T_CLEAR_SCREEN]);
-  if (!IS_CURSOR_HIDDEN(cursor_x, cursor_y))
-    write_cursor(cursor_x, cursor_y);
+  write_cursor(cursor_x, cursor_y);
   bytebuffer_flush(&output_buffer, inout);
 
   /* we need to invalidate cursor position too and these two vars are
diff --git a/termbox/termbox.h b/termbox/termbox.h
index a86bc6ca..97e3f524 100644
--- a/termbox/termbox.h
+++ b/termbox/termbox.h
@@ -44,9 +44,6 @@ void tb_set_clear_attributes(uint16_t fg, uint16_t bg);
 
 /* Move the cursor. Upper-left character is (0, 0). */
 void tb_set_cursor(int cx, int cy);
-/* To hide the cursor, call tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR).
- * Cursor starts out hidden. */
-#define TB_HIDE_CURSOR -1
 
 /* Modify a specific cell of the screen. */
 void tb_change_cell(int x, int y, uint32_t ch, uint16_t fg, uint16_t bg);
diff --git a/termbox/x.cc b/termbox/x.cc
index 5c7fb0a6..f6b04693 100644
--- a/termbox/x.cc
+++ b/termbox/x.cc
@@ -3,10 +3,10 @@
 
 int main() {
   tb_init();
-  tb_clear();
-  tb_change_cell(0, 0, 'a', TB_WHITE, TB_BLACK);
   tb_event x;
   tb_poll_event(&x);
+  std::cout << "a\nb\r\nc\r\n";
+  tb_poll_event(&x);
   tb_shutdown();
   return 0;
 }