about summary refs log tree commit diff stats
path: root/termbox/termbox.h
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-05-18 09:44:37 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-05-18 09:57:57 -0700
commitee1a18f050a5458ade460720091e20ce6b335011 (patch)
treece16273f91254d3d966a1f5427bf9af04b4f136a /termbox/termbox.h
parent7f67383400216732166ff8c845829b93b217ff30 (diff)
downloadmu-ee1a18f050a5458ade460720091e20ce6b335011.tar.gz
3860 - stop buffering the screen in termbox
To achieve this we have to switch to a model of the screen in termbox that
is closer to the underlying terminal.

Before:
  a screen is a grid of characters
  writing out of bounds does nothing

After:
  a screen is a scrolling raster of characters
  writing out of bounds wraps to next line and scrolls if necessary

To move to the new model, it was essential that I migrate my fake screen
at the same time to mimic it. This is why the first attempt (commit 3824)
failed (commit 3858). This is also why this commit can't be split into
smaller pieces.

The fake screen now 'scrolls' by rotating screen lines from top to bottom.
There's still no notion of a scrollback buffer.

The newer model is richer; it permits repl-like apps that upstream termbox
can't do easily. It also permits us to simply use `printf` or `cout` to
write to the screen, and everything mostly works as you would expect. Exceptions:

  a) '\n' won't do what you expect. You need to explicitly print both '\n'
  and '\r'.

  b) backspace won't do what you expect. It only moves the cursor back,
  without erasing the previous character. It does not wrap.

  Both behaviors exactly mimic my existing terminal's emulation of vt100.

The catch: it's easy to accidentally scroll in apps. Out-of-bounds prints
didn't matter before, but they're bugs now. To help track them down, use
the `save-top-idx`, `assert-no-scroll` pair of helpers.

  An important trick is to wrap the cursor before rather after printing
  a character. Otherwise we end up scrolling every time we print to the
  bottom-right character. This means that the cursor position can be invalid
  at the start of a print, and we need to handle that.

In the process we also lose the ability to hide and show the screen. We
have to show the prints happening. Seems apt for a "white-box" platform
like Mu.
Diffstat (limited to 'termbox/termbox.h')
-rw-r--r--termbox/termbox.h27
1 files changed, 4 insertions, 23 deletions
diff --git a/termbox/termbox.h b/termbox/termbox.h
index 64c1c4eb..97306142 100644
--- a/termbox/termbox.h
+++ b/termbox/termbox.h
@@ -8,19 +8,12 @@ extern "C" {
 
 /*** 1. Controlling the screen. */
 
-/* The screen is a 2D array of cells. */
-struct tb_cell {
-  uint32_t ch;  /* unicode character */
-  uint16_t fg;  /* foreground color (0-255) and attributes */
-  uint16_t bg;  /* background color (0-255) and attributes */
-};
-
-/* Names for some colors in tb_cell.fg and tb_cell.bg. */
+/* Names for some foreground/background colors. */
 #define TB_BLACK 232
 #define TB_WHITE 255
 
-/* Colors in tb_cell can be combined using bitwise-OR with multiple
- * of the following attributes. */
+/* Some attributes of screen cells that can be combined with colors using
+ * bitwise-OR. */
 #define TB_BOLD      0x0100
 #define TB_UNDERLINE 0x0200
 #define TB_REVERSE   0x0400
@@ -44,17 +37,6 @@ int tb_is_active(void);
 int tb_width(void);
 int tb_height(void);
 
-/* Update the screen with internal state. Most methods below modify just the
- * internal state of the screen. Changes won't be visible until you call
- * tb_present(). */
-void tb_present(void);
-
-/* Returns a pointer to the internal screen state: a 1D array of cells in
- * raster order. You'll need to call tb_width() and tb_height() for the
- * array's dimensions. The array stays valid until tb_clear() or tb_present()
- * are called. */
-struct tb_cell *tb_cell_buffer();
-
 /* Clear the internal screen state using either TB_DEFAULT or the
  * color/attributes set by tb_set_clear_attributes(). */
 void tb_clear(void);
@@ -63,8 +45,7 @@ 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);
 
-/* Modify a specific cell of the screen. Don't forget to call tb_present() to
- * commit your changes. */
+/* Modify a specific cell of the screen. */
 void tb_change_cell(int x, int y, uint32_t ch, uint16_t fg, uint16_t bg);
 
 /*** 2. Controlling keyboard events. */