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

feat(streams): refactor streams and buffer usage #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lirantal
Copy link
Owner

@lirantal lirantal commented Feb 8, 2019

Refactoring the original picture-tube code to minimize the use of external modules (event-stream, buffers) and use built-in Streams and Buffers support in Node.js

Would be happy if someone more experienced with terminal emulation and streams could review this. Perhaps you could help @waldyrious, @J-Cat, @reconbot, @larsonjj ?

Context: this is in follow-up of a blessed-contrib change to use a thinner picture-tube package with no vulnerabilities: yaronn/blessed-contrib#162

@lirantal lirantal self-assigned this Feb 8, 2019
Copy link

@reconbot reconbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is alright, there’s probably another way to make charm the read part of the duplex but I don’t see any issues doing it this way.

One note is that _final is only node 8 and above.

@lirantal
Copy link
Owner Author

lirantal commented Feb 9, 2019

I could perhaps have the 1.x version of this new replacement use older streams syntax to be compatible with <=8 and then we could release 2.x with the new class and _final syntax.

I linked a local development version of this branch to blessed-contrib and when I run it with the default cols: 95 I get this:

var blessed = require('blessed')
  , contrib = require('../')
  , screen = blessed.screen()
    
var pic = contrib.picture(
   { file: './media/flower.png'
   , cols: 95
   , onReady: ready})
function ready() { screen.render() }

screen.append(pic)

image

Only when I change the cols value to something smaller like 60 I get the full picture:

image

Any ideas why this happens?

@lirantal
Copy link
Owner Author

@cancerberoSgx tagged you here due to recent activity in blessed-contrib in hope that you might be able to help with the outstanding issue here?

@cancerberoSgx
Copy link

@lirantal thanks for including me. I'm not familiar with the library or PNG library but it sounds like the stream is not flushed entirely? will try to research when I have more time, thanks again. Cool lib!

var charm = require("charm");
var x256 = require("x256");

var { Duplex } = require("stream");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should really use readable-stream.

return es.duplex(ws, c);

this.c.on("end", () => {
this.emit("end");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be this.push(null) to correctly end the stream.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for jumping in Matteo!

I saw that in the docs as well for a readable stream implementation and had tried this.push(null); when c streams ends but that just doesn't draw anything at all.

To add context:
Both variations of this.push(null) and this.emit('end') work well with this picture-tuber branch if you test it out with the CLI util: node bin/tube.js /Users/lirantal/projects/forks/blessed-contrib/examples/media/flower.png:

image

The issue is when I use this branch of picture-tuber in blessed-contrib (its used in the picture widget). To re-construct that setup:

  • cd picture-tuber
  • git checkout feat/refactor-streams-use
  • npm link
  • cd blessed-contrib
  • npm link picture-tuber
  • cd examples
  • node picture.js

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

Successfully merging this pull request may close these issues.

4 participants