Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support streaming inputs ? #528

Open
MarcWeber opened this issue Jul 26, 2024 · 1 comment
Open

Support streaming inputs ? #528

MarcWeber opened this issue Jul 26, 2024 · 1 comment

Comments

@MarcWeber
Copy link

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
Copy link
Author

Eventually the way to go is using web sockets. Use case is this: koekeishiya/yabai#1606.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant