Description
In this stage, we will work on the format of the tasklist printout. Let's change it and add some colors! Following is an example of the new tasks list output:
The table format as text:
+----+------------+-------+---+---+--------------------------------------------+
| N | Date | Time | P | D | Task |
+----+------------+-------+---+---+--------------------------------------------+
| 1 | yyyy-MM-dd | hh:mm | | | |
| | | | | | |
| | | | | | |
+----+------------+-------+---+---+--------------------------------------------+
If the task index reaches a double-digit number, then it Should consume a space to the right.
Please, mind the spaces! Each Task line contains 44 characters. If the text is bigger, write the first 44 characters and continue to the next line even if a word is split, as in the following example:
Colors can't be seen in the snippets, so we use images, as in the Examples section.
In the header, P stands for Priority and D for Due tag. They contain 3 spaces each and are denoted by specific colors in the middle space of the first line of each task (see the image above).
Colors can be used in terminals when they support the ANSI escape sequences standard. More on this can be found in the ANSI escape code article on Wikipedia.
Most Linux, Unix, and BSD terminals support it. Windows 10 cmd supports it by default, but you have to enable it manually. Intellij IDEA supports it natively.
The text foreground and background colors can be defined with certain sequences of characters and digits. To distinguish them from normal text, they are preceded by the nonprintable ASCII escape characters (ASCII character code — 27). To include them in the Kotlin println() printout, you should use its Unicode code, that is \u001B.
There are different color schemes, we will use the 4-bit one. To set a foreground or background color, you need to print \u001B[<Color Code>m, where <Color Code> is an integer that denotes the color. To reset the colors, print u001B[0m.
As an example:
println("\u001B[101m \u001B[0m")
Sets the background color to red, prints a space (which is red), and then resets the colors to default (101 is the number for the bright red background color). One space with certain background color denotes each tag.
Priority colors:
Due tag colors:
Objectives
- When users input one of the
print,editordelete, then print the tasklist as described above.
Examples
The greater-than symbol followed by a space (> ) represents the user input. Note that it's not part of the input.
We use images where color cannot be shown.
Example 1: normal execution (current day 2022-1-14)
Input an action (add, print, edit, delete, end):
> add
Input the task priority (C, H, N, L):
> N
Input the date (yyyy-mm-dd):
> 2022-1-14
Input the time (hh:mm):
> 19:00
Input a new task (enter a blank line to end):
> Supermarket
> milk
> cookies
> butter
>
Input an action (add, print, edit, delete, end):
> add
Input the task priority (C, H, N, L):
> C
Input the date (yyyy-mm-dd):
> 2022-1-20
Input the time (hh:mm):
> 20:15
Input a new task (enter a blank line to end):
> Dentist
>
Input an action (add, print, edit, delete, end):
> add
> Input the task priority (C, H, N, L):
L
Input the date (yyyy-mm-dd):
> 2022-1-10
Input the time (hh:mm):
> 12:00
Input a new task (enter a blank line to end):
> Buy book
>
Input an action (add, print, edit, delete, end):
> add
Input the task priority (C, H, N, L):
> H
Input the date (yyyy-mm-dd):
> 2022-1-15
Input the time (hh:mm):
> 00:00
Input a new task (enter a blank line to end):
> Pay bills
>
Input an action (add, print, edit, delete, end):
> print
Input an action (add, print, edit, delete, end):
> end
Tasklist exiting!
Example 2: normal execution, longer tasks (current day 2022-1-14)
Input an action (add, print, edit, delete, end):
> add
Input the task priority (C, H, N, L):
> N
Input the date (yyyy-mm-dd):
> 2022-1-25
Input the time (hh:mm):
> 12:00
Input a new task (enter a blank line to end):
> Remember to review the code for the Tasklist project.
>
Input an action (add, print, edit, delete, end):
> add
Input the task priority (C, H, N, L):
> N
Input the date (yyyy-mm-dd):
> 2022-1-25
Input the time (hh:mm):
> 12:00
Input a new task (enter a blank line to end):
> Find resources about Ansi colors and cursor movement.
> Don't forget to look into the stage 6 links about it.
>
Input an action (add, print, edit, delete, end):
> print
Input an action (add, print, edit, delete, end):
> end
Tasklist exiting!