freeall / single-line-log

Output one line and move to beginning of line. Useful for progress bars and counters with no breaks in the terminal
MIT License
210 stars 26 forks source link

First line stay in console #13

Open dimdimbe opened 7 years ago

dimdimbe commented 7 years ago

Hi,

The first line stay in the console when i do log(logStr.join('\n')) //logStr is a array of string

capture d ecran 2017-02-15 a 22 31 49

Am i doing something wrong? Is there someone experiencing the same "bug" ?

Thank you in advance

freeall commented 7 years ago

I'm not sure I understand the screenshot. Can you make a simpler case and see if it works?

dimdimbe commented 7 years ago

I will try to make a simpler case.

In the mean time i made a video screenshot maybe it's clearer

dimdimbe commented 7 years ago

I think it's because i play with "stdin" I have the same issue with the following code

const log = require('single-line-log').stdout

process.stdin.on('data',(chunk) => {
  log.clear()
  log('i just type: '+chunk.toString())
})
freeall commented 7 years ago

Ahh, yeah, that is probably not a good idea to mix with single-line-log :)

dimdimbe commented 7 years ago

i just try changing line 28 in the index.js file of the module

str += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount-1 ? MOVE_UP : '');

by removing the "-1"

str += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount ? MOVE_UP : '');

It fix my problem, and when i run the test.js file, everything look fine as well

Can i propose this as a PR ? or the "-1" has a purpose

freeall commented 7 years ago

I'm almost in my bed, but it'd be nice if you do a PR, then I'll take a look tomorrow

dimdimbe commented 7 years ago

Same for me ;) I'll do a PR (at least try , i'm quite new to open source stuff)

Thank's for your time and for the module :D