How to resolve the algorithm Terminal control/Cursor movement step by step in the UNIX Shell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Terminal control/Cursor movement step by step in the UNIX Shell programming language

Table of Contents

Problem Statement

Demonstrate how to achieve movement of the terminal cursor:

For the purpose of this task, it is not permitted to overwrite any characters or attributes on any part of the screen (so outputting a space is not a suitable solution to achieve a movement to the right).

This task has no specific requirements to trap or correct cursor movement beyond the terminal boundaries, so the implementer should decide what behavior fits best in terms of the chosen language.   Explanatory notes may be added to clarify how an out of bounds action would behave and the generation of error messages relating to an out of bounds cursor position is permitted.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Terminal control/Cursor movement step by step in the UNIX Shell programming language

Source code in the unix programming language

tput cub1                  # one position to the left
tput cuf1                  # one position to the right
tput cuu1                  # up one line
tput cud1                  # down one line
tput cr                    # beginning of line
tput home                  # top left corner

# For line ends and bottom, we need to determine size
# of terminal
WIDTH=`tput cols`
HEIGHT=`tput lines`

tput hpa $WIDTH            # end of line
tput cup $HEIGHT $WIDTH    # bottom right corner


  

You may also check:How to resolve the algorithm Amicable pairs step by step in the Picat programming language
You may also check:How to resolve the algorithm Find common directory path step by step in the Arturo programming language
You may also check:How to resolve the algorithm Cumulative standard deviation step by step in the Scilab programming language
You may also check:How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Animation step by step in the Scala programming language