lilalo

diff l3prompt.c @ 157:137cf5a580be

bsd fix
author Igor Chubin <igor@chub.in>
date Mon Nov 28 13:26:46 2011 +0200 (2011-11-28)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/l3prompt.c	Mon Nov 28 13:26:46 2011 +0200
     1.3 @@ -0,0 +1,52 @@
     1.4 +
     1.5 +/*
     1.6 + *  export PS1='\[$($L3_HOME/l3prompt "v3#\!#$?#$UID#$$#$(/bin/date +%s)#$PWD#$RANDOM#")$(l3_save_last_line >& /dev/null)\]'$PS1
     1.7 + *  
     1.8 + *
     1.9 + *  l3prompt perl code:
    1.10 + *
    1.11 + *  my $string=$ARGV[0];
    1.12 + *  my $insert="\e[1K\e[10D";
    1.13 + *  my $max=5;
    1.14 + *
    1.15 + *  while (length($string) > $max) {
    1.16 + *      $res .= substr($string, 0, $max).$insert;
    1.17 + *      $string = substr($string, $max);
    1.18 + *  }
    1.19 + *  $res .= $string.$insert;
    1.20 + *  print "$res";
    1.21 + *
    1.22 + */
    1.23 +#include <stdio.h>
    1.24 +#define N 5
    1.25 +#define BUF_SIZE N+1
    1.26 +char* mixin="\e[1K\e[10D";
    1.27 +char buf[BUF_SIZE];
    1.28 +int main(int argc, char **argv)
    1.29 +{
    1.30 +    char *i,*j;
    1.31 +    int n;
    1.32 +    argc--;
    1.33 +    argv++;
    1.34 +    while (argc > 0) {
    1.35 +        i=argv[0];
    1.36 +        j=&buf[0];
    1.37 +        n=0;
    1.38 +        while(*i) {
    1.39 +            *j=*i;i++;j++;
    1.40 +            n++;
    1.41 +            if (n==N) {
    1.42 +                *j=0;
    1.43 +                fputs(buf, stdout);
    1.44 +                fputs(mixin,stdout);
    1.45 +                j=&buf[0];
    1.46 +                n=0;
    1.47 +            }
    1.48 +        } 
    1.49 +        *j=*i;
    1.50 +        fputs (buf, stdout);
    1.51 +        if (n) fputs(mixin,stdout);
    1.52 +        argc--;
    1.53 +        argv++;
    1.54 +    };
    1.55 +}