felixhageloh / uebersicht

ˈyːbɐˌzɪçt
GNU General Public License v3.0
4.59k stars 165 forks source link

Support streaming inputs ? #528

Open MarcWeber opened 3 months ago

MarcWeber commented 3 months ago

Example Yabai --verbose outputs many events such as switching spaces I am interested in.

Now it would be cool if such was allowed:

const read_using_readline = (path, cb_on_line) => {
    cb_on_line(Object.keys(fs))
    cb_on_line("bc")
    cb_on_line("bc")
    return;
    // cb_on_line({output: Object.keys(fs)})
    const stream = fs.createReadStream(path, { encoding: 'utf8', flags: 'r' });
    // Use readline to process the file line by line
    const rl = readline.createInterface({
        input: stream,
        output: process.stdout,
        terminal: false
    });
    rl.on('line', (line) => {
        cb_on_line(line)
    });

}

// export const read_using_tail = (path, cb_on_line) => {
//   const tail = spawn('tail', ['-f', '--retry', path]);
//   let partial = ''
//   tail.stdout.on('data', (data) => {
//     const lines = data.split("\n")
//     lines[0] = partial + lines[0]
//     partial = lines.pop()
//     for (let v of lines) {
//         callback(v)
//     }
//   });

//   tail.stdout.on('err', (data) => console.err(`${widget_name}: ${err}`))
//   tail.stdout.on('close', (data) => console.log('tail quit? - should not happen'))
// }

// export const command = "whoami";
export const command  = (callback) => {
    // callback("onth")
    read_using_readline(yabay_log, callback)
}

Then you could just stream in all events and build whatever state makes sense to render or update the view.

MarcWeber commented 3 months ago

Eventually the way to go is using web sockets. Use case is this: https://github.com/koekeishiya/yabai/issues/1606.