Write a program/function that can help users make simple drawings by moving a cursor contained within a grid of characters, and by selecting which characters should be at a specific position.
Expected Input and Output
The user will be able to work on an area of 80 x 25 characters and will start at position (0, 0). You must then execute commands given as input, each command represented by a specific character. You can assume that the input will only contain a valid set of commands. Your program must be able to execute the following commands:
w,a,s,d : Move the cursor up, left, down or right if the cursor will still be within the boundaries, do nothing otherwise. Your program must work correctly even if the user tries to leave the drawing area.
0,1,2,3,4 : Replace the character at the cursor's position by the corresponding character : ░▒▓█.
? : Read the next input character and save it. You can assume that only printable ASCII characters can be inputted (code 32 to 126 inclusive).
! : Read the character at the cursor's position and save it. ! can therefore save printable ASCII characters and ░▒▓█.
5 : Replace the character at the cursor's position by the last character received with the ? or ! command.
This is code-golf, so the shortest answer in bytes will win.
Test Cases
It will obviously be hard to display the final output, since it requires 25 lines, so these examples will only display the first five lines. Ignore the / and - symbols, they are just here as delimiters for readability.
Input: 1s1s1d2w2w2d3s3s3d4w4w4d3s3s3d2w2w2d1s1s1
Final Output:
░▒▓█▓▒░ /
░▒▓█▓▒░ /
░▒▓█▓▒░ /
/
/
--------------------------------------------------------------------------------/
Input: 2dsaw!s5s5d5d5d5d5d5d5s5s5a5a5a5a5w5w3w5w5a5a3
Final Output:
▓▒▒ /
▒ ▒ /
▒▒▓▒▒▒▒ /
▒ ▒ /
▒▒▒▒▒ /
--------------------------------------------------------------------------------/
Input: aaaaasd?H5d?e5d?l5d5d?a5d?!5a?o5s4d4aa4a4a4a4
Final Output:
/
Hello! /
██████ /
/
/
--------------------------------------------------------------------------------/
033円[1as a variable. \$\endgroup\$$qA, that would get interpreted as variable "qA" so you'd need$q\A. i think it still saves bytes overall though. My biggest gripe is!, I can't even make sure it works properly (or if i even got the syntax right), because it's so undocumented since nobody uses it nor implements it. \$\endgroup\$${q}in order to determine the new byte count. It's probably also possible to remove some newlines from your code, since some of them are optional. As for the escape sequences, I don't think that any terminal supports character reading commands nowadays. Tried everything I was able to think of with XTerm, nothing worked. \$\endgroup\$sanddfail if x or y are equal to 0 (Suffix ++ evaluates to the previous value, not the current one). You can easily fix that by using prefix ++ instead for s and d:s)((y<25&&++y))&&z B;;d)((x<80&&++x))&&z C;;. Please test your code next time before posting it (or add draft somewhere if it is not finished). The last test also fails, because it reads the!given as input for the?commands as it it was the command!. \$\endgroup\$!when you enter the command, notice the single quotes in my screenshot. \$\endgroup\$