fix: corner cases when printing large content through term interface
[lunaix-os.git] / lunaix-os / includes / hal / term.h
index 00fe32b04a074ebd40a236a11ee26367b3fcd913..4ddf74d38066b18dd4ea6d55cdf9e201f9a5a107 100644 (file)
@@ -11,8 +11,8 @@ struct term;
 
 struct linebuffer
 {
-    struct rbuffer *next;
-    struct rbuffer *current;
+    struct rbuffernext;
+    struct rbuffercurrent;
     short sflags;
     short sz_hlf;
 };
@@ -27,33 +27,56 @@ typedef struct rbuffer** lbuf_ref_t;
 
 struct term_lcntl
 {
-    struct llist_header lcntls;
     struct term* term;
-    size_t (*process_and_put)(struct term*, struct linebuffer*, char);
+    int (*process_and_put)(struct term*, struct linebuffer*, char);
+};
+
+/**
+ * @brief Communication port capability that a device is supported natively, 
+ *          or able to emulate low level serial transmission behaviour specify 
+ *          by POSIX1-2008, section 11.
+ * 
+ */
+#define TERMPORT_CAP 0x4d524554U
+
+/**
+ * @brief A termios capability that a device provide interfaces which is 
+ *          compliant to POSIX1-2008
+ * 
+ */
+#define TERMIOS_CAP 0x534f4954U
+
+struct termport_capability
+{
+    CAPABILITY_META;
+
+    void (*set_speed)(struct device*, speed_t);
+    void (*set_cntrl_mode)(struct device*, tcflag_t);
 };
 
 struct term
 {
     struct device* dev;
     struct device* chdev;
-    struct llist_header lcntl_stack;
+    struct term_lcntl* lcntl;
     struct linebuffer line_out;
     struct linebuffer line_in;
+    char* scratch_pad;
     pid_t fggrp;
 
-    struct
-    {
-        int (*set_speed)(struct device*, speed_t);
-    } chdev_ops;
+    struct termport_capability* tp_cap;
 
     /* -- POSIX.1-2008 compliant fields -- */
     tcflag_t iflags;
     tcflag_t oflags;
     tcflag_t lflags;
+    tcflag_t cflags;
     cc_t cc[_NCCS];
     speed_t iospeed;
 };
 
+extern struct device* sysconsole;
+
 struct term*
 term_create(struct device* chardev, char* suffix);
 
@@ -70,7 +93,8 @@ struct term_lcntl*
 term_get_lcntl(u32_t lcntl_index);
 
 static inline void
-line_flip(struct linebuffer* lbf) {
+line_flip(struct linebuffer* lbf)
+{
     struct rbuffer* tmp = lbf->current;
     lbf->current = lbf->next;
     lbf->next = tmp;