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
  1. Start it
  2. What you can do
  3. With the terminal and your editor
  4. Changes on disk and conflicts
  5. Preferences
  6. Stop it

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.

terminal
$ cstudy serve --open
cstudy serve 0.9.1 · workspace ~/cstudy-workspace
open       http://127.0.0.1:<port>/?token=<token>
stop       Ctrl-C
cstudy serve options
OptionEffect
--openOpen the page in your default browser. Without it no browser opens: open the URL the server prints, token included
--port NListen 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.

The views of the page
ViewOpens withWhat you do there
ProblemsAlt+1Browse and filter the catalog, and take the cstudy next pick
ProblemA row of the listRead the statement, start or resume, open the solution, and see the history of the problem
AttemptStart or ResumeEdit and save your files, test and submit, take hints, and finish with a rating
MockAlt+2Start a mock interview and follow its countdown and problems
ProgressAlt+3Check your stats and the reviews due, and export or import your progress
HealthAlt+4See the cstudy doctor checks; Fix runs cstudy doctor --fix
SettingsAlt+5Change 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 in an attempt
KeysDo
Cmd+SSave the active tab
Cmd+EnterRun the tests
Cmd+Shift+EnterSubmit a project level
EscapeIn the results: cancel the run, after a question
F8Go 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+S saves the active tab, or :w with 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.

Preferences of the page
PreferenceDefaultEffect
Vim keybindingsoffVim keys in every editor; :w saves
Run on saveoffEach save, from the page or from your editor, runs the tests again, as cstudy test --watch does
Type-check TypeScriptonTypeScript runs type-check, so type errors show in the editor
ThemesystemLight 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.