Cursor disappears when running `top -n1 | head`
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
When running
top -n1 | head
the terminal's cursor disappears.
Running top -n1
brings it back.
Tested in gnome-terminal
and tilix
in Ubuntu 16.04 and CentOS 7.5.
Running top -n1 | tail
doesn't have this issue, so I think, something at the end of top
output let the cursor reappear which is not executed when printing the head
only.
What causes this and how can I get back the cursor more elegantly ?
terminal gnome-terminal top cursor
add a comment |Â
up vote
3
down vote
favorite
When running
top -n1 | head
the terminal's cursor disappears.
Running top -n1
brings it back.
Tested in gnome-terminal
and tilix
in Ubuntu 16.04 and CentOS 7.5.
Running top -n1 | tail
doesn't have this issue, so I think, something at the end of top
output let the cursor reappear which is not executed when printing the head
only.
What causes this and how can I get back the cursor more elegantly ?
terminal gnome-terminal top cursor
I can also get it back with runningtput cnorm
. (via)
– RoVo
51 mins ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
When running
top -n1 | head
the terminal's cursor disappears.
Running top -n1
brings it back.
Tested in gnome-terminal
and tilix
in Ubuntu 16.04 and CentOS 7.5.
Running top -n1 | tail
doesn't have this issue, so I think, something at the end of top
output let the cursor reappear which is not executed when printing the head
only.
What causes this and how can I get back the cursor more elegantly ?
terminal gnome-terminal top cursor
When running
top -n1 | head
the terminal's cursor disappears.
Running top -n1
brings it back.
Tested in gnome-terminal
and tilix
in Ubuntu 16.04 and CentOS 7.5.
Running top -n1 | tail
doesn't have this issue, so I think, something at the end of top
output let the cursor reappear which is not executed when printing the head
only.
What causes this and how can I get back the cursor more elegantly ?
terminal gnome-terminal top cursor
terminal gnome-terminal top cursor
edited 1 hour ago
asked 1 hour ago
RoVo
1,416211
1,416211
I can also get it back with runningtput cnorm
. (via)
– RoVo
51 mins ago
add a comment |Â
I can also get it back with runningtput cnorm
. (via)
– RoVo
51 mins ago
I can also get it back with running
tput cnorm
. (via)– RoVo
51 mins ago
I can also get it back with running
tput cnorm
. (via)– RoVo
51 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
Best way IMHO is to make top
use "batch" mode which is intended to be used with non-interactive use cases such as piping to another program or to a file.
So, this
top -n1 -b | head
won't be leaving the shell without a cursor.
As for the why the cursor disappears...
Since top
is an interactive program, it "messes" with the terminal in order to grab input, scroll content, etc, and it hides the cursor.
When terminating it has to restore the cursor display, and it does so by sending a control code to the terminal itself.
By piping the command through head
, this control code won't get through (head
prints just the firs 10 lines by default, and the output of top
+ control codes to restore the terminal state is >10 lines).
As a matter of fact, if you give head
enough lines to print, the cursor appears!
For example,
top -n1 | head -n100
leaves a cursor on my system.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Best way IMHO is to make top
use "batch" mode which is intended to be used with non-interactive use cases such as piping to another program or to a file.
So, this
top -n1 -b | head
won't be leaving the shell without a cursor.
As for the why the cursor disappears...
Since top
is an interactive program, it "messes" with the terminal in order to grab input, scroll content, etc, and it hides the cursor.
When terminating it has to restore the cursor display, and it does so by sending a control code to the terminal itself.
By piping the command through head
, this control code won't get through (head
prints just the firs 10 lines by default, and the output of top
+ control codes to restore the terminal state is >10 lines).
As a matter of fact, if you give head
enough lines to print, the cursor appears!
For example,
top -n1 | head -n100
leaves a cursor on my system.
add a comment |Â
up vote
5
down vote
Best way IMHO is to make top
use "batch" mode which is intended to be used with non-interactive use cases such as piping to another program or to a file.
So, this
top -n1 -b | head
won't be leaving the shell without a cursor.
As for the why the cursor disappears...
Since top
is an interactive program, it "messes" with the terminal in order to grab input, scroll content, etc, and it hides the cursor.
When terminating it has to restore the cursor display, and it does so by sending a control code to the terminal itself.
By piping the command through head
, this control code won't get through (head
prints just the firs 10 lines by default, and the output of top
+ control codes to restore the terminal state is >10 lines).
As a matter of fact, if you give head
enough lines to print, the cursor appears!
For example,
top -n1 | head -n100
leaves a cursor on my system.
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Best way IMHO is to make top
use "batch" mode which is intended to be used with non-interactive use cases such as piping to another program or to a file.
So, this
top -n1 -b | head
won't be leaving the shell without a cursor.
As for the why the cursor disappears...
Since top
is an interactive program, it "messes" with the terminal in order to grab input, scroll content, etc, and it hides the cursor.
When terminating it has to restore the cursor display, and it does so by sending a control code to the terminal itself.
By piping the command through head
, this control code won't get through (head
prints just the firs 10 lines by default, and the output of top
+ control codes to restore the terminal state is >10 lines).
As a matter of fact, if you give head
enough lines to print, the cursor appears!
For example,
top -n1 | head -n100
leaves a cursor on my system.
Best way IMHO is to make top
use "batch" mode which is intended to be used with non-interactive use cases such as piping to another program or to a file.
So, this
top -n1 -b | head
won't be leaving the shell without a cursor.
As for the why the cursor disappears...
Since top
is an interactive program, it "messes" with the terminal in order to grab input, scroll content, etc, and it hides the cursor.
When terminating it has to restore the cursor display, and it does so by sending a control code to the terminal itself.
By piping the command through head
, this control code won't get through (head
prints just the firs 10 lines by default, and the output of top
+ control codes to restore the terminal state is >10 lines).
As a matter of fact, if you give head
enough lines to print, the cursor appears!
For example,
top -n1 | head -n100
leaves a cursor on my system.
edited 1 hour ago
answered 1 hour ago
Mr Shunz
2,23711617
2,23711617
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469770%2fcursor-disappears-when-running-top-n1-head%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I can also get it back with running
tput cnorm
. (via)– RoVo
51 mins ago