Milestone 3: Interface
In this third milestone, you'll develop an terminal-based user interface for your spreadsheet using the Curses library. The interface allows users to move around to different cells using the cursor keys, enter formula, and view the results.
Curses
Install a port of the Curses library—or some similar library for user interfaces in the terminal—using a package manager for your language. That might be gem
for Ruby, cabal
for Haskell, cargo
for Rust, pip
for Python, or npm
for JavaScript. You will likely have several libraries from which to choose, and your very finite instructor can offer no opinion on which you should choose. Ruby users should revisit the installation instructions on installing and requiring the curses
gem and the recipes on using it.
We are using a textual user interface (TUI) instead of a graphical user interface (GUI) because most GUIs greedily take over your design and engineering time, subverting the other goals we have for this course. Curses, on the other hand, is not a widget- or event-driven system. It keeps the responsibility for drawing content and handling events in your hands.
Layout
The interface of your program must display these three subwindows to the user:
- A formula editor.
- A read-only display panel that shows a cell's value or error message. This panel is needed because the cell itself is too small to show much data.
- A 2D grid with columns and rows labeled. Each cell in the grid shows just the primitive value of its content, not the code producing the primitive. The value may need to be truncated if it doesn't fit in the cell, but at least some portion of the primitive content must be shown so that the user can see all the data at once.
Arrange the subwindows as you see fit—just make sure all are visible at the same time. Use your Curses library's routine for placing and sizing these subwindows.
You decide how many columns and rows to display. A fully-featured spreadsheet would show hundreds, thousands, or even an arbitrarily large number using a scrolling view. You are not expected to do that. Filling the visible window with a fixed number of rows and columns is acceptable.
User Interactions
Your spreadsheet must support the following user interactions:
- The user selects a cell by moving around with the cursor or other navigational keys. The selection must be highlighted in some manner, perhaps through color, bold text, or reverse video.
- When the user selects a cell, its unevaluated source is displayed in the formula editor, and its primitive value is shown in the display panel. For this milestone, you may assume both chunks of text are single lines that do not overflow or wrap. In the fourth milestone, you will want to add support for multiline text.
- When the user hits a special key of your choosing in view mode, focus is moved to the editor, and the user may type in new text or delete old text.
-
If the text starts with an
=
, treat it as source code that must be lexed and parsed. If the text doesn't start with=
but is an integer, float, or boolean, treat it as a primitive in your expression type hierarchy. Otherwise, treat the input as plain string. - When the user hits a special key of your choosing in edit mode, focus returns to the grid, and the cell and display panel update to show the new value or resulting error message. Any other cells that depend on the modified cell via a cell rvalue or cell lvalue also update. In an industry-grade spreadsheet, you would lazily update only the dependent cells. If you have the time and interest to build and traverse a dependency graph, go for it. If not, feel free to eagerly update all cells. Note that if two cells reference each other, your spreadsheet may enter an infinite loop of evaluation. That's a bug you can fix after the semester's over.
Submission
To submit your milestone, follow the instructions. In particular, do these three things:
- Submit your project to the official GitHub repository that your instructor made for you.
- Record a 3–5 minute screencast of you walking through your code and commenting on it. Do not exceed 5 minutes. Your instructor has many videos to watch. Post it to Canvas Studio according to the instructions.
- Complete the ready date submission form on Canvas.
In your video, demonstrate interacting with the grid, entering new formula, editing formula that trigger updates, and displaying errors on malformed code. In particular, reconstruct this spreadsheet:
-
Enter
5.3
in cell 0, 0. -
Enter
-4.1
in cell 1, 0. -
Enter
10.8
in cell 2, 0. -
Enter
0.0
in cell 0, 1. -
Enter
-2.5
in cell 1, 1. -
Enter
4.4
in cell 2, 1. - Enter formulas in nearby cells to compute the min, max, sum, and mean across this rectangle of six cells.
-
Enter
100
in cell 4, 0. -
Enter
3
in cell 4, 1. -
Enter
=#[4, 0] * #[4, 1]
in cell 4, 2. Use whatever rvalue syntax you chose in milestone 2. -
Edit the
100
and3
and demonstrate that the product automatically updates. -
Enter
9
in cell 5, 0. -
Enter
false
in cell 5, 1. -
Enter
=#[5, 0] << #[5, 1]
in cell 5, 2. It should show the type error but not crash. -
Enter
=~6 - 3
in a cell and confirm that the correct result appears in the grid.
Don't comment on or show every single line of code in your video. Select a few representative snippets. Do comment on programming language ideas that interest you or challenged you.