Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

C# How did they create wait cursor?, In character subsystem

views
     
TSFlierMate
post Mar 17 2022, 04:36 AM, updated 4y ago

On my way
****
Validating
543 posts

Joined: Nov 2020
I will be the last one to know. cool2.gif

We have seen a variety of graphical wait cursor from hourglass to spinning circle.

But what about console mode.... Is this a thing?

user posted image

More pattern is welcome.
jibpek
post Mar 17 2022, 06:51 AM

Enthusiast
*****
Junior Member
708 posts

Joined: Jul 2012
There is no wait cursor in Console mode, you have to draw it yourself, erase it, and then draw again.
flashang
post Mar 17 2022, 08:32 AM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


When display such custom cursor,
you need to do a lot of extra things when you need readline from keyboard.

sad.gif


TSFlierMate
post Mar 17 2022, 05:40 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(flashang @ Mar 17 2022, 08:32 AM)
When display such custom cursor,
you need to do a lot of extra things when you need readline from keyboard.

sad.gif
*
Yes, you've pinpointed the issue.

But it is quite easy, given this, in .NET:
CODE
while (true)
{
   if (Console.KeyAvailable)
       break;

   Console.Write('.');
}

...where it doesn't pause for keypress from user. tongue.gif



flashang
post Mar 17 2022, 07:53 PM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


QUOTE(FlierMate @ Mar 17 2022, 05:40 PM)
Yes, you've pinpointed the issue.

But it is quite easy, given this, in .NET:
CODE
while (true)
{
   if (Console.KeyAvailable)
       break;

   Console.Write('.');
}

...where it doesn't pause for keypress from user.  tongue.gif
*
Nope.
To handle "proper" readline, you need to check for backspace, insert / overwrite, arrow keys, some other keys such as ctrl / alt + keys...


angch
post Mar 17 2022, 08:50 PM

On my way
****
Junior Member
636 posts

Joined: Jul 2006
Back in the DOS days, I hooked on interrupt 8 to change the cursor scan lines 18 times a second, bouncing it up and down. One of my first TSR program.

I suppose in modern times, it's a matter of getting something running in the background to animate it, in your current platform, be it web or console or gui.

This post has been edited by angch: Mar 17 2022, 08:54 PM
silverhawk
post Mar 18 2022, 03:06 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


This is done quite commonly in bash scripts, there are plenty of ways to do progress indicators as well. Here's a simple spinner example

CODE

#!/bin/bash
function shutdown() {
   # reset cursor
   tput cnorm
}
trap shutdown EXIT

function spinner() {
   # cursor invisible
   tput civis

   frames='-\|/'
   input=""
   i=0
   while [[ -z $input ]]; do
       read -rsn1 -t 0.1 input

       i=$(( (i+1) %4 ))
       printf "\r${frames:$i:1}"
       sleep .1
   done

   # restore cursor
   tput cnorm
}

spinner

TSFlierMate
post Mar 19 2022, 05:23 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(silverhawk @ Mar 18 2022, 03:06 PM)
This is done quite commonly in bash scripts, there are plenty of ways to do progress indicators as well. Here's a simple spinner example

» Click to show Spoiler - click again to hide... «

*
Yes, that "frames='-\|/'" is one of the popular way to do it.

When you mean progress indicator, do you mean this?
CODE

.
..
...
.
..
...
(and repeats)

TSFlierMate
post Mar 19 2022, 05:26 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(flashang @ Mar 17 2022, 07:53 PM)
Nope.
To handle "proper" readline, you need to check for backspace, insert / overwrite, arrow keys, some other keys such as ctrl / alt + keys...
*
But I wonder, why do we need to read keystroke when animating a wait cursor??

QUOTE(angch @ Mar 17 2022, 08:50 PM)
Back in the DOS days, I hooked on interrupt 8 to change the cursor scan lines 18 times a second, bouncing it up and down. One of my first TSR program.
*
Interesting, looks like everyone was a DOS master.
silverhawk
post Mar 19 2022, 08:53 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


QUOTE(FlierMate @ Mar 19 2022, 05:23 PM)
Yes, that "frames='-\|/'" is one of the popular way to do it.

When you mean progress indicator, do you mean this?
CODE

.
..
...
.
..
...
(and repeats)

*
Like a normal progress bar you see on windows when you're transferring a file. Its quite common in command line scripts now.

flashang
post Mar 19 2022, 10:33 PM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


QUOTE(FlierMate @ Mar 19 2022, 05:26 PM)
But I wonder, why do we need to read keystroke when animating a wait cursor??
Interesting, looks like everyone was a DOS master.
*
After re-read the 1st post, realized this was talking about waiting cursor in console.
Not for 'waiting command cursor'

biggrin.gif



This post has been edited by flashang: Mar 19 2022, 10:43 PM
flashang
post Mar 19 2022, 10:41 PM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


QUOTE(silverhawk @ Mar 19 2022, 08:53 PM)
Like a normal progress bar you see on windows when you're transferring a file. Its quite common in command line scripts now.
*
If we look at recent common application, including web, desktop gui and console app,
The waiting cursor could be progress bar,
or some text info such as xx mb/sec, xx sec / min reminding, 1 of 999 steps / processes, ...

This may give user some info for them to decide if they are willing to wait until complete or terminate it.

Animation cursor may be is OK for short waiting, but not for long waiting time.

biggrin.gif



 

Change to:
| Lo-Fi Version
0.0227sec    0.79    5 queries    GZIP Disabled
Time is now: 17th December 2025 - 08:50 PM