summaryrefslogtreecommitdiff
path: root/userspace/xterm/xterm.c
blob: a4325c7908fe8de00682e7dc80f1daf084dec272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdlib.h>
#include <stdio.h>
#include "../put_pixel.h"

extern char**environ;

//default
char *argv1[]={"xterm","/bin/fsh",0};   

int main(int argc, char **argv)
{
    // we need a window
    _gui_win();

    // basically loads font and sets a few constants
    vesa_init(NULL);

    // init tty and set vesa output funcs
    void *tty=terminal_init_vesa();

    //int xterm_in[2];
    int xterm_out[2];

    //_pipe(xterm_in);
    pipe(xterm_out);

    int tty_fd=_open("/dev/tty");

    int pid=fork();   

    if(!pid) // child
    {
        // we need a window
        _gui_win();
        //srand(time(NULL));   // Initialization, should only be called once.
        while(1)
        {
            int x = rand()%600;
            int y = rand()%300;
            int width=10;
            int height=10;
            int col = rand()% 0x00ffff;
            put_rect( x, y, width,height,col);
            _gui_inval((x<<16)|(y),(width<<16)|height);
        }
            //_close(xterm_in[1]);
            close(xterm_out[0]);

            dup2(tty_fd,0);// stdin
            dup2(xterm_out[1],1);// stdout
            dup2(xterm_out[1],2);// stderr

             // replace process with our foolshell or whatever
            if(argc==1)_execve(argv1[1],argv1,environ); 
            execve(argv[1],argv,environ);
            
            printf("unable to execve %s",argv[1]); // never reached
    }
    else{

        //_close(xterm_in[0]);
        close(xterm_out[1]);

        //_dup2(xterm_in[1],0); // compositor writes here.
        //_close(xterm_in[1]);
        
        // TODO quit if execve fails or child exits...
            terminal_put(tty,'X');
            terminal_put(tty,'X');
            terminal_put(tty,'X');
        while(1)
        {
            char buf[1];
            //read(xterm_out[0],buf,1); // show what foolshell writes to its stdout/stderr
            read(tty_fd,buf,1); // show what foolshell writes to its stdout/stderr
            terminal_put(tty,buf[0]);
        }
    }

}