Added patch by Johan Bevemyr (jb@bevemyr.com)
[apps/madtty.git] / inject_csi.h
index a372bcd..b350a12 100644 (file)
@@ -30,5 +30,15 @@ Copyright (c) 2004 Bruno T. C. de Oliveira
  * related fields in it */
 void rote_es_interpret_csi(RoteTerm *rt);
 
+static inline void clamp_cursor_to_bounds(RoteTerm *rt) {
+   if (rt->crow < 0) rt->curpos_dirty = true, rt->crow = 0;
+   if (rt->ccol < 0) rt->curpos_dirty = true, rt->ccol = 0;
+
+   if (rt->crow >= rt->rows) 
+      rt->curpos_dirty = true, rt->crow = rt->rows - 1;
+
+   if (rt->ccol >= rt->cols)
+      rt->curpos_dirty = true, rt->ccol = rt->cols - 1;
+}
 #endif