CSC1002 Console-Based Editor
CSC1002 – Computational Laboratory
Console-Based Editor - Basic - 2025
OVERVIEW
n this assignment, you are going to design and develop a simple, basic console-based editor. Unlike themodern, advanced editor which provides a sophisticated editing environment, utilizing the high
resolution of the graphical screen together with the mouse and the keyboard to position and adjust anytext and figures displayed on the screen, giving us he WYSIWYG (What-You-See-Is-What-You-Get)
experienceIn the early days, lacking access to a rich graphical display and mouse, the functionality of editors waslimited, providing only a much simpler user interface, usually console-based. Editing was carried outbased on simple text commands entered via the eyboard, commands such as inserting (i) and
appending (a) a text string, positioning the editor cursor one character position to the left (h), onecharacter position to the right (l), one-word positionforwards (w), one-word position backwards (b), andso on.CSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational LaboratorySCOPE Complete all the following editor commands:NOTE: Refer to the section “Specific Spec” for more information on particular requirements.
- Case-sensitive commands - all editor commands are case-sensitive, for example, the capital
letter ‘A’ does not equal the lowercase letter ‘a’.
Command types - most commands are single-letter (in lower case) commands (such as ?, $, x, ^,
…etc), while some are two-letter (such as dw). Most commands do not require extra input,while a few do, such as insert (i) and append (a).
- Command prompt (>) - The prompt is a single character string ‘>’. See the screenshots on thefirst page.
- Command Syntax - “Command[Text]”, where “Command” is one of the commands shown instep 1, and “Text” applies only to commands requiring extra input such as insert (i) and append(a). Note: any commands whose description includes asubstring enclosed in “<>” bracketrequire extra input “Text”.Command Parsing - the user types a single command and then presses the return key to
continue. Parse each command string according to “Command Syntax” to ensure that the inputstring matches EXACTLY one of the commands from step 1, including the extra input “Text” ifrequired. When invalid input is entered, simply display another prompt as illustrated in thefollowing screenshot.CSC1002 –2025 WinterBy Kinley LamCSC1002 – Computational Laboratory
Examples of valid command input:
- Command Execution - the editor will repeatedly prompt the user to enter an editor command,
execute the command, and then output the updated content on the display console (except for
commands ‘?’ and ‘q’, see Note follows). After the updated content is displayed, the editor will
display a new prompt on a new line. Refer to the section “Sample Output” for more examples.
Note: when the help command (?) is entered, output only the help menu as shown in step 1;
when the quit command (‘q’) is entered, terminate the program.NOTE:ep your entire source code in ONE SINGLE file.Use only Python modules as specifiedin the “Permitted Modules” sectionIn your design stick ONLY to functions, in other words, no class objects of your ownoFurthermore, the lines of code containing the sub-function(s) defined within another
will be counted as part of the parent function.oNOTE: Failure to adhere to the instructions outlined in the assignment handout willresult in a 50% reductionin the coding style score.CSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational LaboratorySPECIFIC SPEC
Editor content - the editor shows its content, if any, as a single line of text string constructed by
one or multiple Insert/Append commands. If the row cursor is enabled, it shows its position in a
color such as green. When the editor program initially starts, its content is empty. Refer to the
section “Sample Output” for more examples.
Row cursor - it’s used to show where the cursor is on the current row if not empty. In other
words, the cursor will appear on printable characters including space. The cursor is shown bywrapping a character with a pair of escape character strings such as “\033[42m” and “\033[0m”.
For example, given a string “hello world”, to show the green cursor at the position of the letter‘e’, this is the string to print: “h” + “\033[42m” + “e” + “\033[0m” + “llo world”.
Insert - the given string “Text” will be inserted to the left of the cursor and the cursor positionwill be changed to the beginning of the “Text” string.
Append - the given string “Text” will be inserted to the right of the current cursor position andthe cursor position will be changed to the end of the “Text” string.Delete word - delete all characters from the cursor position to the beginning of the next word orto the end of the line.Cursor left and right - when repositioning the cursor to the left or right, one or multiplepositions, and if the cursor is already at the far left or far right position, leave the cursor where itUndo - it’s used to reverse the change(s) made to the editor content including the row cursorpositions based on the most recent commands. If multiple undo commands areexecuted,代写CSC1002 Console-Based Editor each will undo one command at a time in the reverse order that the commands wereexecuted. For example, given the last 2 valid commands are “ahello” followed by “aworld”, the first undo command will reverse the “a world”, and the second consecutive undocommand will reverse “ahello”. Refer to the following figure for an illustration.Repeat - The “Repeat” command is used o re-execute the last valid command and it offers theconvenience of sparing the user from retyping it again. The “Repeat” command is not
applicable to the Undo and Help commands. For example, consider the command sequence:“ahello”, “a world”, “?”, and “u”. If the command “r” is ubsequently entered multiple times,each Repeat command will always re-execute “ahello”. Refer to step “Undo followed by Repeat”for another illustration.CSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational Laboratoryfollowed by Repeat - In this case, the “Undo” is not considered as the lase "Repeat" command is used to target the command immediately preceding the "Undo"
command, not the most recent action performed. Any command entered prior to the "Undo"
ill be re-executed upon triggering the "Repeat" command. Refer to the following figure for anillustration.
- b command - it moves the cursor to the beginning of the word to the left of the cursor. If thecursor is within a word, the cursor will be placed at the word's first letter. Refer to the followingfigure for an illustration.
Word - a word is defined as a sequence of consecutive characters including punctuations but not
white space, in other words, any group of characters without spaces is considered a single word,
ven if it includes punctuation marks. Refer to the following figure for an illustration.
SC1002 – 2025 Winter
By Kinley LamCSC1002 – Computational LaboratoryASSUMPTIONS
- The goal of this assignment is to illustrate the benefits of “Problem Decomposition”, “Clean” and “Refactoring”, all together achieving high creadability to ease logic expansionand keep high maintainability, therefore, it’s not aimed at designing a complex, general-purpose
editor for handling large editing content.
t’s assumed that the length of each line is kept within a reasonable length so that each line canbe stored directly using the standard Python ‘str’ type. The number of lines is also kept within areasonable number so that all lines can be kept in one standard Python list and the lines can beefficiently updated using the standard list and str operations such as append, insert, slicing,cloning, …etc.
It is assumed that the user will not input a command that consumes excessive memory andto a buffer overflow (also called memory overflow or overrun) at runtime, such asinserting a very long string like “ihello …………………………. world.” In other words, all test casesexecuted against your program will be based on the commands from step 1 (Scope) with ashort“Text” string.Each test case is designed to evaluate the functionality and correctness of your program,rather its speed, performance and memory usage. Each test case consists of multiple editin
The text editor is required to handle only regular English characters, thus additional unicodesupport, if any, is unnecessary.
CSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational Laboratory
STARTUP OPTIONS
Not applicableSKILLS
In this assignment, you will be trained on the use of the followings:
Refactoring - logic reuse or simplification based on the existing logic.
Variable scope: global, local and function parameters.Coding Styles (naming convention, meaningful names, comments, doc_string, …etc)
- Problem Decomposition, Clean Code, Top-Down DesignFunctions (with parameters and return) for program structure and logic decompositioStandardobjects (strings, numbers & lists)
ERMITTED MODULES
Only the following Python module(s) is allowed to be used:
re (regular expression)
DELIVERABLES Program source code (A1_School_StudentID.py), where School is SSE, SDS, SME, HSS, FE, LHS, MED andStudentID is your 9-digit student ID.
For instance, a student from SME with student ID “119010001” will name the Python file as follows:
A1_SME_119010001.py:Ensure that your source file is saved in standard, regular UTF-8 encoding format. On the status bar ofVisual Studio Code, you can view the current encoding format as follows:On an occasion, the encoding scheme is set to UTF-8 with BOM as follows:
CSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational LaboratoryThe presence of the Byte Order Mark (BOM) could be due to copying from websites, older version ofeditor, file conversion from other sources, default encoding setting, and so on.
Confirm the encoding scheme is UTF-8 and the file name is correct, then submit the plain program file tothe corresponding assignment folder. A deductionof 5% will be penalized if the file is incorrectly namedor in wrong encoding format.TIPS & HINTS
Apply problem decomposition, Clean Code and Refactoring as illustrated during classes.Beware of variable scope as you might keep a few variables as global such as current editorcontent, cursor position, undo buffer, and so on.Refer to Python website for program styles and naming conventions (PEP 8)
CSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational Laboratory
SAMPLE OUTPUT
CSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational LaboratoryCSC1002 – 2025 WinterBy Kinley LamCSC1002 – Computational Laboratory
MARKING CRITERIA Coding Styles – overall program structure including layout, comments, white spaces, namingconvention, variables, indentation, functions with appropriate parameters and return.
- Program Correctness – whether or the program works 100% as per Scope.User Interaction – how informative and accurate information is exchanged between yourprogram and the player.Readability counts – programs that are well structured and easy to follow using functions tobreak down complex into smaller cleaner generalized functions are preferred over afunction embracing a complex logic with many nested conditions and branches! In other words,a design with a clean architecture and high readability is thpredilection for the courseobjectives over efficiency. The logic in each function should be kept simple and short, and itshould be designed to perform asingle task and be generalized with parameters as needed.
approach – Keep It Simple and Straightforward.
- alance approach – you are not required to come up with a very optimized solution. However,take a balance between readability and efficiency with good use of program constructs.