Template:ConsoleLines

From Coder Merlin
Revision as of 17:44, 14 December 2021 by imported>Anton-krom
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Purpose[edit]

Mimics console input / output.

Implementation approach[edit]

The template is targeted to merge functionality of Template:ConsoleLine and Template:ConsoleLines. The template allows the injection of bootstrap classes, primarily to add rounded corners and some padding to the single template instance or to the first and last instances of the template call series.

Editors are encouraged to replace / edit all instances of both templates eventually using the proposed syntax / parameters.

Usage[edit]

The first unnamed parameter contains the console input/output and it is the only mandatory parameter.

There are the optional named parameters:

prompt   # The console prompt.
classes  # Names of CSS classes which apply to the block.
Example
{{ConsoleLines
|classes=rounded py-2
|prompt=john-williams@codermerlin:~$
|sudo systemctl status apache2
[sudo] password for john-williams:           
Unit apache2.service could not be found.
}}
Result

john-williams@codermerlin:~$ sudo systemctl status apache2
[sudo] password for john-williams:
Unit apache2.service could not be found.

Hint.pngHelpful Hint
  1. Use one template for a single command prompt.
  2. Use rounded py-2 classes to add border radius and some vertical padding.
  3. Do not use <br/> to insert a line break, just start typing on the new line.
  4. Use a number of subsequent instances of the template to build a block of console lines with multiple command prompts. In this case you might want:
    • to add rounded corners only to the top of the first instance and to the bottom of the last instance
    • not to use padding between console lines blocks.
  5. Play with rounded-top, rounded-bottom, pt-2, pb-2 to achieve the desired layout.
  6. In complex cases when the console output fails to appear correctly (for example, when it contains the reserved characrters like =), wrap it into <nowiki> tag.
Example
{{ConsoleLines
|classes=rounded-top pt-2 <!-- first prompt (top block) -->
|prompt=john-williams@codermerlin:~$
|sudo systemctl status apache2
[sudo] password for john-williams:           
Unit apache2.service could not be found.
}}
{{ConsoleLines
|classes= <!-- second prompt (middle block) -->
|prompt=john-williams@codermerlin:~$
|<nowiki>ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=19.5 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=19.7 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=116 time=19.7 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=116 time=19.5 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 19.453/19.573/19.671/0.091 ms</nowiki>
}}
{{ConsoleLines
|classes=rounded-bottom pb-2 <!-- third prompt (bottom block) -->
|prompt=john-williams@codermerlin:~$
|sudo systemctl status apache2
[sudo] password for john-williams:           
Unit apache2.service could not be found.
}}
Result

john-williams@codermerlin:~$ sudo systemctl status apache2
[sudo] password for john-williams:
Unit apache2.service could not be found.

john-williams@codermerlin:~$ ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=19.5 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=19.7 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=116 time=19.7 ms 64 bytes from 8.8.8.8: icmp_seq=4 ttl=116 time=19.5 ms ^C --- 8.8.8.8 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3004ms rtt min/avg/max/mdev = 19.453/19.573/19.671/0.091 ms

john-williams@codermerlin:~$ sudo systemctl status apache2
[sudo] password for john-williams:
Unit apache2.service could not be found.

Variations[edit]

There are two additional colour flavours of this template:

Light

Template:ConsoleLinesLight

Dark

Template:ConsoleLinesDark