This project implements a terminal screen renderer using OCaml. It parses a stream of binary-encoded commands and renders graphical instructions in a terminal. This is achieved by interpreting the commands to setup a virtual screen, draw characters, lines, and text, manipulate the cursor, and clear the screen.
Below is the project's proposal in PDF format.
Below is the use case diagram in PDF format:
Below is the sequence diagram in PDF format:
Below is a flowchart diagram in PDF format:
This section outlines the progress of the project as of 9/12/2024. Below is the document in PDF format:
- Screen Setup: Initialise a virtual terminal screen with customisable dimensions and colour modes.
- Draw Characters: Place individual characters at specific coordinates.
- Draw Lines: Render straight lines between two points with specified characters and colours.
- Render Text: Display strings of text starting at a given position.
- Cursor Movement: Move the cursor without rendering.
- Screen Clearing: Reset the screen content.
- EOF Handling: Terminate rendering upon receiving an end-of-file command.
The program processes a binary input with the following structure:
Command Byte | Length Byte | Data Bytes |
---|---|---|
1 byte | 1 byte | Depends on the command |
Command | Code | Description | Data Format |
---|---|---|---|
Setup Screen | 0x1 |
Initialise screen dimensions and colour mode. | Byte 0 : Width, Byte 1 : Height, Byte 2 : Colour Mode |
Draw Character | 0x2 |
Draw a character at specific coordinates. | Byte 0 : x, Byte 1 : y, Byte 2 : Colour, Byte 3 : ASCII |
Draw Line | 0x3 |
Draw a line between two coordinates. | Byte 0-4 : Coordinates, Byte 5 : Color, Byte 6 : ASCII |
Render Text | 0x4 |
Display text starting at a given position. | Byte 0-2 : Position & Colour, Byte 3-n : ASCII text |
Cursor Move | 0x5 |
Move cursor to a specific position. | Byte 0 : x, Byte 1 : y |
Draw at Cursor | 0x6 |
Draw at the current cursor position. | Byte 0 : ASCII, Byte 1 : Colour |
Clear Screen | 0x7 |
Reset the screen. | No data |
End of File | 0xFF |
End of the binary stream. | No data |
terminal-screen/
├── README.md
├── bin/
| ├── main.ml
├── lib/
│ ├── *.ml
│ ├── *.mli
├── test/
│ ├── test_module.ml
├── .gitignore
├── .ocamlformat
├── dune-project
├── library.opam
├── AUTHORS
└── Makefile
- Clone the repository:
git clone https://github.com/yourusername/terminal_screen.git
cd terminal_screen
- Install dependencies:
sudo apt get opam
opam install . --deps-only -y
- Activate the environment:
eval $(opam env)
- To build the program in an executable:
opam exec -- dune build
- To execute the program:
dune exec terminal_screen_app
Execute all unit tests:
opam exec -- dune runtest