Ignore:
Timestamp:
Oct 8, 2006, 2:14:13 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Break everything. Temporarily. Only the term output works.
  • Allow to read from stdin.
  • Wrap at terminal width (currently letter-wrap, not word-wrap).
File:
1 edited

Legend:

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

    r1112 r1193  
    2424#include <cucul.h>
    2525
     26#include "toilet.h"
    2627#include "render.h"
    2728
     29static int feed_tiny(context_t *, uint32_t);
     30static int end_tiny(context_t *);
     31
     32int init_tiny(context_t *cx)
     33{
     34    cx->ew = 16;
     35    cx->eh = 2;
     36    cx->x = cx->y = 0;
     37    cx->w = cx->h = 0;
     38    cx->cv = cucul_create_canvas(cx->ew, cx->eh);
     39
     40    cx->feed = feed_tiny;
     41    cx->end = end_tiny;
     42
     43    return 0;
     44}
     45
     46static int feed_tiny(context_t *cx, uint32_t ch)
     47{
     48    if(cx->x >= cx->w)
     49        cx->w = cx->x + 1;
     50
     51    if(cx->y >= cx->h)
     52        cx->h = cx->y + 1;
     53
     54    switch(ch)
     55    {
     56        case (uint32_t)'\r':
     57            return 0;
     58        case (uint32_t)'\n':
     59            cx->x = 0;
     60            cx->y++;
     61            break;
     62        case (uint32_t)'\t':
     63            cx->x = (cx->x & ~7) + 8;
     64            break;
     65        default:
     66            cucul_putchar(cx->cv, cx->x, cx->y, ch);
     67            cx->x++;
     68            break;
     69    }
     70
     71    if(cx->x >= cx->term_width)
     72    {
     73        cx->x = 0;
     74        cx->y++;
     75    }
     76
     77    if(cx->x >= cx->ew)
     78        cx->ew = cx->ew + cx->ew / 2;
     79
     80    if(cx->y >= cx->eh)
     81        cx->eh = cx->eh + cx->eh / 2;
     82
     83    cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);
     84
     85    return 0;
     86}
     87
     88static int end_tiny(context_t *cx)
     89{
     90    cucul_set_canvas_size(cx->cv, cx->w, cx->h);
     91
     92    return 0;
     93}
     94
     95#if 0
    2896cucul_canvas_t *render_big(uint32_t const *string, unsigned int length)
    2997{
     
    80148    return cv;
    81149}
     150#endif
    82151
    83 cucul_canvas_t *render_tiny(uint32_t const *string, unsigned int length)
    84 {
    85     unsigned int x;
    86     cucul_canvas_t *cv = cucul_create_canvas(length, 1);
    87 
    88     for(x = 0; x < length; x++)
    89         cucul_putchar(cv, x, 0, string[x]);
    90 
    91     return cv;
    92 }
    93 
Note: See TracChangeset for help on using the changeset viewer.