Ignore:
Timestamp:
Oct 26, 2006, 3:07:58 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Make stdin input line-aware so that we don't have to wait until EOF to display stuff.
  • Reorganise stuff and fix memory leaks.
File:
1 copied

Legend:

Unmodified
Added
Removed
  • toilet/trunk/src/mono9.c

    r1240 r1241  
    2727#include "render.h"
    2828
    29 static int feed_tiny(context_t *, uint32_t);
    30 static int end_tiny(context_t *);
    31 
    3229static int feed_big(context_t *, uint32_t);
     30static int flush_big(context_t *);
    3331static int end_big(context_t *);
    34 
    35 int init_tiny(context_t *cx)
    36 {
    37     cx->ew = 16;
    38     cx->eh = 2;
    39     cx->x = cx->y = 0;
    40     cx->w = cx->h = 0;
    41     cx->cv = cucul_create_canvas(cx->ew, cx->eh);
    42 
    43     cx->feed = feed_tiny;
    44     cx->end = end_tiny;
    45 
    46     return 0;
    47 }
    48 
    49 static int feed_tiny(context_t *cx, uint32_t ch)
    50 {
    51     switch(ch)
    52     {
    53         case (uint32_t)'\r':
    54             return 0;
    55         case (uint32_t)'\n':
    56             cx->x = 0;
    57             cx->y++;
    58             return 0;
    59         case (uint32_t)'\t':
    60             cx->x = (cx->x & ~7) + 8;
    61             return 0;
    62     }
    63 
    64     /* Check whether we reached the end of the screen */
    65     if(cx->x && cx->x + 1 > cx->term_width)
    66     {
    67         cx->x = 0;
    68         cx->y++;
    69     }
    70 
    71     /* Check whether the current canvas is large enough */
    72     if(cx->x + 1 > cx->w)
    73     {
    74         cx->w = cx->x + 1 < cx->term_width ? cx->x + 1 : cx->term_width;
    75         if(cx->w > cx->ew)
    76             cx->ew = cx->ew + cx->ew / 2;
    77     }
    78 
    79     if(cx->y + 1 > cx->h)
    80     {
    81         cx->h = cx->y + 1;
    82         if(cx->h > cx->eh)
    83             cx->eh = cx->eh + cx->eh / 2;
    84     }
    85 
    86     cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);
    87 
    88     cucul_putchar(cx->cv, cx->x, cx->y, ch);
    89     cx->x++;
    90 
    91     return 0;
    92 }
    93 
    94 static int end_tiny(context_t *cx)
    95 {
    96     cucul_set_canvas_size(cx->cv, cx->w, cx->h);
    97 
    98     return 0;
    99 }
    10032
    10133int init_big(context_t *cx)
     
    11547
    11648    cx->feed = feed_big;
     49    cx->flush = flush_big;
    11750    cx->end = end_big;
    11851
     
    180113}
    181114
     115static int flush_big(context_t *cx)
     116{
     117    cx->torender = cx->cv;
     118    cucul_set_canvas_size(cx->torender, cx->w, cx->h);
     119
     120    cx->x = cx->y = 0;
     121    cx->w = cx->h = 0;
     122    cx->cv = cucul_create_canvas(1, 1);
     123
     124    return 0;
     125}
     126
    182127static int end_big(context_t *cx)
    183128{
    184129    cucul_free_canvas(cx->onechar);
     130    cucul_free_canvas(cx->cv);
    185131    free(cx->buf);
    186132    cucul_free_font(cx->f);
Note: See TracChangeset for help on using the changeset viewer.