modus
Menu
On this page

The entry terminal

The source src/modules/system/terminal built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.

The terminal: it shows the text that a process gives as records, and it gives the keys that the input types to that process (src/library/modus/terminal).

The terminal starts no process. The root service starts a process and its terminal, and gives the same terminal ring and text region to the two. The terminal holds a surface, these two memory objects, and a handle that reads the state of the process: it has nothing of the start grant set of the process. The name of the process, the size of the text and what the window shows are values of its context.

Keys: Page Up and Page Down move the view. Each other key goes to the process, and the view returns to the last lines.

The pointer: the scroll bar at the right of the lines moves the view. A press on an arrow button moves it by one line, and again while the button is held; a press on the track by one page; the thumb follows the pointer while it is held (src/library/modus/interface/scroll_bar.odin).

Two threads:

the reader   It reads the records of the terminal ring and keeps the
             lines. It owns the lines: no lock exists.
the drawer   The first thread. At the rate of the screen it asks the
             reader for a view: the cells of the rows that the window
             shows. Then it draws the view. The reader makes the view
             between two groups of records: some microseconds.
             The surface has two pictures: the compositor never reads
             a picture that the drawer changes. Before each wait it
             tells the compositor whether a change waits for its
             next picture.

The reader does not wait for a picture, so the process that writes does not wait for a picture. A line that the window does not show costs one copy of its bytes, and no pixel.

The lines that the terminal keeps are in three areas of fixed size: the lines, the runs, the bytes. Each area starts again at its first place when it is full: the oldest lines go.

What it is for. A process with the grant Terminal (the console, flood) writes typed records, not pixels and not escape sequences: a run of text has its style as a field. The process never draws, never waits for a picture, and never parses a key sequence. See the terms terminal and terminal ring.

Start: nothing starts it by name. The root service starts one terminal with each process that has the grant Terminal, and refuses start("terminal"). Its row of start_grant_sets has the grant System_Part only: it receives only the handles above.

What a reader sees: a window with the name of the process, its lines, a status bar that the process fills, the action bar of Page Up and Page Down at the right of its last line, and on the log:

  • "terminal: ok, console writes in a ring of N records";
  • "terminal: the first key goes to console";
  • "terminal: a press on the arrow up of the scroll bar of console: the view starts at line L of N", or "... the view follows the last lines";
  • "terminal: a drag of the thumb of the scroll bar of console: ...";
  • "terminal: console stopped: itself, done, after L lines and R records", with the stop outcome in place of "done", or the text of another stop cause in place of "itself, done";
  • "terminal: console draws its interface text in the interface font", or "... in the font of the cells", at its first frame and at each change of the setting font;
  • "terminal: console shows the character N in its cells, drawn by this process from the font F of its fallback chain", once for each font F, for the first or the last character of the view past the 192 characters of Spleen that a font of the chain of the cells has ; and "terminal: console shows the character N in its cells as the replacement glyph: no font of its fallback chain has it", once, for the first or the last such character that no font has.

The terminal of flood measures: it shows the rates of the process, and writes one line with the lines, the records and the kernel entries of one second.

What it proves: a text output with no kernel entry for each line, and a writer that never waits for the screen. It does not prove fairness between two writers: one terminal serves one process.

See: The due picture of a terminal: a change that waits is said before the wait in the repository, Glyphs past the glyph cache in the repository

terminal module with an entry

Hash
999c225b39ee853d0e51a2cd6e1aad54e625abc0701f48196c178b7f431ae10f
Size
267584 bytes
Exports
0
Imports
1
Imported by
0
License
MIT

The terminal: it shows the text that a process gives as records, and it gives the keys that the input types to that process (src/library/modus/terminal)

FactValue
KindModules with an entry
Sourcesrc/modules/system/terminal
Boot imageyes: in the boot image, 267584 bytes in this build
Build settings
  • DRAWING_THROUGH_MODULE=true
Imports
Imported bynone

Neighbours

What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.

terminal drawing

Exports

ExportWhat it does
entry()The entry of the terminal: it opens the window of one process, starts the reader thread, then draws the lines and sends the keys until the machine stops

entry

entry()

The entry of the terminal: it opens the window of one process, starts the reader thread, then draws the lines and sends the keys until the machine stops.

When the root service starts it, the entry:

  1. 1. reads its values: the name of the process, the columns (40 at least), the rows (4 at least), and the flag that it measures;
  2. 2. opens a window of two pictures with the name of the process; with no window, it writes "terminal: no surface" and stops with Failed;
  3. 3. creates the three areas of the lines;
  4. 4. opens the terminal ring and maps the text region, read-only; a wrong ring or region stops it with Failed;
  5. 5. starts the reader thread, and writes "terminal: ok, ...".

The first thread is then the drawer. It sleeps while nothing changes, and wakes for a record, a key, the stop of the process, or every 250 ms to look at the state of the process. Page Up and Page Down move the view; each other key goes to the process, and a key is lost when the queue is full. When the process stops, the terminal shows its code and keeps its lines: it does not stop with it.

Form
The entry of the module: one parameter, an address, fixed by the contract.
Source
src/modules/system/terminal/main.odin:1441

Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).

What the root service gives it

WhatValueAs the root service says
GrantsThe text of the process that writes in it (terminal_start).
Other terms of its start grant setnone
Budget that it asks for
  • working memory pages 12648
  • pages of its threads 91
  • pages of the pictures of its window 0
  • pages of the module and its imports from the files of the build
  • processes 1
  • threads 2
The lines that it keeps, and the surfaces of its window: their size follows the columns and the rows that its starter gives, each resize and the scale, so the tool cannot count them, and the working memory holds them at their largest. The lines take 3840 pages. A surface holds two pictures; one of the reference screen takes 4050 pages. That is the surface of a window as large as the logical screen at each scale, the largest scale 2 included: 960 x 540 logical pixels at 2 are the 1920 x 1080 pixels of the screen. During a resize the window holds two surfaces, the one that the compositor shows and the new one, until the compositor answers: so two surfaces of the reference screen, 8100 pages, and a maximize from a window as large as the screen fits. A rescale holds one surface at a time. 3840 + 8100 = 11940 (checked under the type Line). A window larger than the logical screen of a scale (a drag past the left edge of the screen, or a window that the principal sized at a smaller scale) does not fit: display.surface_resize declines the resize with a line, and a rescale declines the scale, so the window keeps its frame until a scale that it fits. The cells of the largest grid are in the module: the tool counts them. And the glyph memory of its two copies of the text rendering, the one of the drawing module, which draws its cells, and its own, which draws a cell again to tell where its glyph comes from (display.cell_fallback_of): each reserves its memory at its first glyph, 2 x 354 pages (display.TEXT_MEMORY_PAGES) = 708 pages. 11940 + 708 = 12648.

The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).

start_grant_sets global variable of the package root

start_grant_sets := [?]Start_Grant_Set_Row {...}

The start grant set of each module of the boot image, with the reason of each.

src/modules/system/root/start_grant_sets.odin:73