Update output to unix in realtime - perl

Im sure this is common but I was having trouble finding anything on google...
I am using Perl and I am running my program in UNIX. At one point in my program I am printing numbers which represent the number of regex matches found. Anyway the output is something like this..
1
2
3
4
5
etc..
It ends up being quite a long list, so if you want to get to the top or bottom of the output you have to do a ton of scrolling...
My question is how can I get the list output to update in realtime, so the list output would stay on one line. so that 1 changes to 2 changes to 3 etc..
Thanks for help!

It depends on a lot of things, but \r in a string should return the cursor to the beginning of the line.

Firstly, don't forget to unbuffer output in your Perl with:
$|=1;
Then try:
$(tput clear);
to put cursor to top of terminal window.
Try typing:
tput clear
into your terminal to see if that clears the screen and puts the cursor at top left. If not, try typing:
clear
to clear the screen and get cursor to "Home" position.

Related

Move to specific line and column in one command

Let's say we have a text file that is very long and has many lines. I want to move to 30th line and 15th column in this file.
Are there any VIM commands that could be used to move to mentioned line number and column in one command? Thanks.
Please, do not suggest to use smt like :30 command and after 15| this is NOT an option.
May VIM has an option to input smt like: :30,15, just in another syntax?
The only option I found is to use :call cursor(30,15) but it looks little bit too long, as I need to type it each time I want to jump to the another position.
You can define your own command-line command. Define it in ~/.vimrc and it will be available everywhere. Define:
:command -nargs=* Go call cursor(<f-args>)
Run:
:Go 30 15
Well, you want to move across two dimensions but Vim commands are limited to one dimension, therefore you can't move to line 30 and column 15 with a single built-in command.
Here are the shortest key sequences to move to column 15 of line 30:
" in normal mode
30G15|
" in command-line mode and normal mode
:30<CR>15|<CR>
" in command-line mode
:30norm15|<CR>
" from the shell
$ vim foo.txt +norm30G15\|<CR>
Note that the first suggestion above is already the shortest theoretically possible sequence because you would need:
at least one key for the command itself,
at least one key to separate the two coordinates,
the vertical coordinate (can't be shortened),
and the horizontal coordinate (can't be shortened).
The only improvement I can think of to 30G15| would be to use keys that don't require a modifier but, frankly, I am not sure that it is worth the hassle.

Scrolling "too long" command doesn't work properly

Assume I want to invoke a tool with a lot of options, like:
$ somescript --option1 --option2 --option3 --option4 --option5 whatever even more stuff
But the width of the terminal doesn't allow to have that thing on a "single line".
That alone isn't a problem, but with fish, there is a problem with scrolling.
When I enter that extra-wide command, at some point, there will be a line break:
$ somescript --option1 --option2 --option3 --option4 --option5
whatever even more stuff
All fine so far. While typing such a lengthy command, I can scroll forth and back at any point. Works as expected. So, assume I entered the command, made a mistake, and now want to remove --option4.
The normal thing: use "arrow up" to get to that command in the history, to then use "arrow left" to scroll within the command. And now something weird happens.
Everything is fine while the cursor is within the second line. But when the cursor moves to the first line ... after 3 to 5 more "arrow left" strokes, the cursor moves UP another line. Then it sits above the first line of the command. There is also a vertical jump of a few characters.
In other words: as soon as a command is longer than the width of the terminal, I am unable to scroll into the first line reliably. The cursor shows up somewhere, and it is really hard to guess where it really sits at any moment. Which makes it almost impossible to edit anything in that first line.
This is on MacOs, using iterm 3.2.9 and fish version 3.0.2 installed via brew.
Wrote up defect 6014 on github. Outcome is rather frustrating.
The problem is: the Mac terminal(s) all handle certain unicode characters the wrong way. "Normally" that isn't a problem, but when you use one of those fish prompts that give you the git status (like AcidHub which is my favorite) ... fish can't compute/determine the exact line width, and there you go.
So, basically, when using fish on MacOs, option space is limited to:
use the defaults, which (when using special prompts, like AcidHub will lead to scrolling issues)
adapt the fish prompt accordingly (in my case, I replaced all special unicode chars with something simpler). It doesn't look that great, but scrolling simply works again.
And a completely different and unexpected solution to the problem: I am using iterm2 on my Mac, and iterm2 just added a "status bar" section. That can be easily configured, and of course, it already has a status bar component that tells you about git status.
Thus my solution: I changed the fish prompt to just give the PWD, and all the other things that the AcidHub prompt has to offer, are now "iterm2 status bar" components!

Powershell commands?

Ok I'm having trouble and google isn't helping, so I thought I'd come to you geniuses. I'm using Powershell and posh-git, and it keeps doing something that I'm sure I can exit out of with a magic command, I just don't know it yet.
Basically, when I run git diff (or something else with a long result), it will only give me a screen's worth of information, and end the screen with a colon
:
And if I keep pressing Enter it will add more to the screen til it is done showing everything for that command, and shows
<END>
But now what? How do I get out of this and back to calling commands? Enter, Esc and the other things I thought to try are not helping. I'm sure this must be a simple thing, but I don't know how to explain to Google what I want.
Anyone know?
if you do a git config -l you may see some relevant entries like:
core.pager='less'
pager.diff=false
pager.log=true
You can enable or disable the pager for different commands, or set a different pager. https://www.kernel.org/pub/software/scm/git/docs/git-config.html has the details, check out the core.pager section and pager.<cmd> sections for specifics.
If you're using 'less' as your pager, hit 'h' at that : prompt to get lots of details about what you can do there, and as pointed out by others, q, Q, or ZZ will get you back to the command line.
You can terminate the current command using CTRL+C. Is that what you're asking?

What is the usual way in MATLAB to read help page by page?

I'm looking for an equivalent of for example DOS's dir |more which lists the data, until one page is complete, then waits for a key to be pressed until showing another. Is there an equivalent for MATLAB's help system.
I know I could simply scroll back, but this would be so much more convenient, expecially if one uses help system often.
Type more on at the command line. This will print command outputs page by page.
For the next line: 'return'; next page; 'spacebar'; return to command line: 'q'.
Likewise, more off resumes the normal display mode.

Printing in emacs

I'm trying to print a page with very long lines in emacs. Someone out there has never heard of the 80 columns rule, and now I'd like to print that file. I'm using the ps-print-buffer-with-faces command
When I launch this command, I get lines wrapped in the middle of words. Extremely uncomfortable. But if I use the longlines-mode for examples, I get nice wrapping, but wrong line numbers (lines which wrap get wrong numbers). This problem doesn't occur when I let ps-print do the wrapping in the middle of words.
So how can I tell ps-print to wrap at word boundaries and preserve line numbers?
Thanks!
CFP.
Before there's a better answer, here is what I'd do: use fill-region to hard-wrap and print the buffer, then undo to revert if necessary.
The key sequence: C-x hM-x fill-regionM-x ps-print-buffer-with-faceC-/.
I searched further, but there seems to be no way to do this.