DocumentationPractising in the browser
Guides
Practising in the browser
cstudy is a command line, and the terminal stays the main way to use it. When you would rather have a page, cstudy serve runs one on your own computer, with the same practice loop on the same workspace and progress.
On this page
Start it
Run cstudy serve in your workspace, or from anywhere with cstudy --workspace PATH serve. It needs a workspace, so run cstudy init first.
$ cstudy serve --open
cstudy serve 0.9.1 · workspace ~/cstudy-workspace
open http://127.0.0.1:<port>/?token=<token>
stop Ctrl-C| Option | Effect |
|---|---|
--open | Open the page in your default browser. Without it no browser opens: open the URL the server prints, token included |
--port N | Listen on port N. Without it the system picks a free port, so the port changes at each start |
While it runs, the terminal prints one line per finished run or job, and nothing else. The page comes with the install, the editor included, and works offline.
The URL is a password
The server listens on 127.0.0.1 only, which other machines cannot connect to. The token in the URL is new each time the server starts, and anyone with the URL can use the page while it runs, so do not share it.
What you can do
The page covers the practice loop for every kind of problem, in all 6 languages. Each view shows the cstudy command it mirrors, and every run is the same cstudy test or cstudy submit, so the page needs the same toolchains as the terminal.
| View | Opens with | What you do there |
|---|---|---|
| Problems | Alt+1 | Browse and filter the catalog, and take the cstudy next pick |
| Problem | A row of the list | Read the statement, start or resume, open the solution, and see the history of the problem |
| Attempt | Start or Resume | Edit and save your files, test and submit, take hints, and finish with a rating |
| Mock | Alt+2 | Start a mock interview and follow its countdown and problems |
| Progress | Alt+3 | Check your stats and the reviews due, and export or import your progress |
| Health | Alt+4 | See the cstudy doctor checks; Fix runs cstudy doctor --fix |
| Settings | Alt+5 | Change your preferences, and see where the workspace is |
In an attempt, results arrive as the run goes, and compiler errors show in the editor, on the lines they name. On Linux, read Ctrl for Cmd:
| Keys | Do |
|---|---|
Cmd+S | Save the active tab |
Cmd+Enter | Run the tests |
Cmd+Shift+Enter | Submit a project level |
Escape | In the results: cancel the run, after a question |
F8 | Go to the next error in the editor |
Hint, Solution… and Done… count as their commands do: any hint caps the grade at ok, and revealing a solution before the attempt passes grades it again, so the page asks first. See Finishing an attempt.
With the terminal and your editor
The page is another way to use cstudy, not a separate tool. It works on the same workspace files and the same progress.db as the terminal and your editor, so you can switch between them at any time. Start an attempt in the terminal and it appears in the page’s in-progress menu; submit in the terminal and the page opens the new level; edit in your editor and the open tab follows.
A few things stay in the terminal: cstudy init, cstudy ide, cstudy new, cstudy verify on catalog problems, and cstudy test --debug, which needs your editor’s debugger.
Changes on disk and conflicts
- Saving is explicit.
Cmd+Ssaves the active tab, or:wwith Vim on. The page never saves on its own, and a tab with unsaved edits shows a dot in place of its close button. - Files changed on disk reload. When your editor or the terminal changes a file, a tab without unsaved edits takes the new version in place and keeps your cursor.
- A conflict shows a banner. A tab with unsaved edits does not reload: Reload theirs drops your edits, and Overwrite saves yours over the file.
- Leaving asks first. Closing a tab, leaving the view or closing the page with unsaved edits asks before anything is lost.
Preferences
Preferences apply at once. They are stored in .cs/serve/preferences.json in the workspace, so they follow the workspace, not the browser.
| Preference | Default | Effect |
|---|---|---|
| Vim keybindings | off | Vim keys in every editor; :w saves |
| Run on save | off | Each save, from the page or from your editor, runs the tests again, as cstudy test --watch does |
| Type-check TypeScript | on | TypeScript runs type-check, so type errors show in the editor |
| Theme | system | Light or dark, or follow your system |
Stop it
Press Ctrl-C in the terminal where the server runs. Runs in progress stop as Ctrl-C stops them in the terminal, and record nothing. Your files and progress stay in the workspace.
The next start prints a new URL with a new token, so open that one.
The full guide in the cstudy repository covers project files, every key, troubleshooting and what keeps the page private to you.
Written for cstudy 0.9.1. The specs in the cstudy repository are the source of truth for every detail.