How to freeze a row in NodeJS when using console.log - node.js

For example, I am doing
console.log('Press A to Stop')
for(var i=0;i<10000;i++) console.log(i);
I want that the message Press a To Stop, will continue to appear all the time.
Do you have any idea how to do that?
The only solution I think about, is to calcuare number rows in the screen, and render frame after frame, (x-1 rows), and add the bottom row each time.
More Info
I want to show logs on the screen. (queries, requests, errors, and more), and I want the user to be able to change the log level, I want to show the instruction on the screen while he seeing the logs.

It's actually pretty easy, but you can't use console.log (which isn't a biggie in your case).
What you will need to do is the following:
instead of console.log use process.stdout.write(x) where x is the output you want (followed by a new line character \n)
use process.stdout.write("Press A to Stop"); (note there is no new line character at the end)
right before you need to write the next line of information use process.stdout.clearLine(); which clears what's currently on the last line of the output
repeat steps 1 to 3

Related

Reprint a table in js terminal without a waterfall print or clearing console

JS has this great feature called console.table. It allows a list of objects to be displayed as a table.
Now I could like to create a simple little program that continously displays the same table just with updated values (individual values change very fast, so a re render only on change isn't an option)
So far I got the best results simply rendering one table after the other, which leaves the most recent table always at the bottom. The problem with this is that it fills the entire terminal extremely fast and as such makes scrolling back up difficult.
Another option would be to clear the terminal and the print the table again. But this leads to excessive "blinking" which makes the table unreadable.
So basically I would need a way to print the console.table, somehow get the terminal cursor back to the start of a table and the overwrite it, similar to how it works in a lot of terminal programms like htop. Is there a way to do this in node js?

How to display the found line at the top of the window in notepad++

When I am editing certain files I open them in Notepad++ and search for patterns. The line with the next match then shows up in the middle of the window, or if it was already inside the window it remains where it was (typically in the lower half, if a forward search was done). Then I typically want to edit the next N lines (N between 10 and maybe 35...) from the found one.
It would be very convenient if the line with the match would be at the top of the window (or a specified number of lines offset from top/middle/bottom) so I wouldn't need to scroll down to where I must edit.
Is this feature available already, or is it something that would require a feature request and implementation?

Sublime text multiple cursors?

Sublime Text is so damn advanced and this seems like such a stupid question, but...
I started writing a for loop in PHP (using SFTP), loved that it gave me a choice to auto-generate the loop. However, it enters this weird multi-cursor mode, which
1)I am not really sure how to use/exit without using the mouse;
2) it seems useless, seeing as all 3 type the same thing, even though I need to change, for example, the $i > x or $i = x.
Although Sublime does indeed support the idea of multiple cursors (which is an incredible time saver and useful as all get out, as we're about to see), what you're actually asking about here is a snippet which in this case happens to also include multiple cursors.
The general idea is that for code that you're likely to type many times (e.g. a for loop), you can create a snippet that will generate the bulk of the text for you in one shot, and then allow you to easily customize it as needed. In this case, the snippet in question is part of the default functionality of Sublime and is provided by the shipped PHP package.
To answer point #2 in your question first, this is far from useless. As seen here, I enter the text for and then press Tab to expand the snippet out. The first thing to notice here is that the status line says Field 1 of 4 to tell me that I'm in a snippet and that it contains four fields.
The first field is the name of the control variable for the loop, and all of them are selected so that as I change the name, all of them change at the same time because when there are multiple cursors, the text you type appears at all of them at the same time.
Once I'm done changing the name of the variable, I press Tab again to go to the next field, which allows me to easily change the point at which the loop starts. Another press of Tab takes me to the third field, where I can specify where the loop ends.
One last press of Tab exits the snippet and selects the text in the loop, so I can start writing my code (caveat: I am not a PHP developer).
At this point you can see Sublime offering another snippet for echo, which would expand out to an echo statement complete with quotes, then allow me to edit the text in the echo and skip to the end.
Circling back around to the first point in your question, you can use Esc at any point to jump out of a snippet and go back to regular editing. You can also use Tab or Shift+Tab to move through the fields in the snippet, and pressing Tab at the last field in the snippet exits it as well.
In this particular case, the first field in the snippet sets up multiple cursors, and so exiting the snippet while this field is active leaves multiple cursors in effect. You can jump back to a single cursor by pressing Esc one more time (this is true regardless of how you ended up with multiple cursors).

QB64 Output issue

How do I scroll up and see previous displayed lines in the output?
I'm using QB64, and had to run a program 1000 times, but I cannot see the starting lines. Actually, I can't see the first 800 lines or so.
Is there a way to expand the window or scroll up to see everything? Because I do not have a scroll bar, and if I use any key to scroll up, it exits the console window.
Thanks in advance.
The new version of QB64 supports a console window, which should be able to do what you want. I'm not too used to console though, but if all else fails you could always save the text in a string array and examine that. There are some examples of creating lists in the community at qb64.net or you could make your own list with scrollbars, etc.
Input a line in the loop for data output:
if x > 24 then
if 24 MOD x then sleep
endif
MOD is the command for modulus where the modulus will return the remainder of 24 and x. in this case if it is zero then it will pause the console output until the user presses any key.
If you don't want to mess with custom buffers, just use the console:
$CONSOLE:ONLY
_DEST _CONSOLE
With that in the begining of your program, QB64 will create only a console window, which by default can be scrolled back so the past lines can be seen.

Printing to a progress bar to the terminal from Java/C++

I want to update the percentage progress of my program on the screen.
I have a progress bar that I print. I add a * when the progress is more than 10%, but I also want to write the actual percentage correct up to every digit. However, I do not want to write a new number every time, since it will have the following effect:
1
2
3
4
Instead, I would like to just maintain one single figure on the screen that keeps getting updated.
How do I do that? (… in Java/C++, but I think it's irrelevant)
In C++ I believe you want to throw \r to bring you back to the beginning of the line (instead of \n) or you'll want to look at the curses library. Not sure, but you can probably do something similar in Java.
Outputting a \b will move the cursor back one column, and outputting a \r will return it to the first column. From there you can print the new value to be displayed.
std::cout << "111\r22\r3" << std::endl;
For C++, I think the curses offers textual GUIs or something... somewhere someone has already written a textual based progress bar, you should use their implementation so you don't have to do their work over again.
Also, if you didn't know it, java has a progress bar that you can use.
http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html

Resources