termdev

#define termdev: \ I---------------------------------------------------------------------------------\ I---------------------------------------------------------------------------------\ I---------------------------------------------------------------------------------\ I \ I /$$$$$$$$ /$$ \ I |__ $$__/ | $$ \ I | $$ /$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$$ /$$$$$$ /$$ /$$ \ I | $$ /$$__ $$ /$$__ $$| $$_ $$_ $$ /$$__ $$ /$$__ $$| $$ /$$/ \ I | $$| $$$$$$$$| $$ \__/| $$ \ $$ \ $$| $$ | $$| $$$$$$$$ \ $$/$$/ \ I | $$| $$_____/| $$ | $$ | $$ | $$| $$ | $$| $$_____/ \ $$$/ \ I | $$| $$$$$$$| $$ | $$ | $$ | $$| $$$$$$$| $$$$$$$ \ $/ \ I |__/ \_______/|__/ |__/ |__/ |__/ \_______/ \_______/ \_/ \ I---------------------------------------------------------------------------------\ I---------------------------------------------------------------------------------\ I---------------------------------------------------------------------------------I "terminal development" // XXX: ?! where the hell did the bit on stacktraces go? EMULATORS: Common_terminal_emulators: xfce4-terminal qterminal st xterm // NOTE: recommended st: • simples or suckless terminal • ironically, it sucks a shit ton, _avoid at all costs_ st [options] : opens st — a : sets alternative screen mode to false — c : — e : — f : — g : — i : sets resizeableness to false — o : — l : — n : — t : sets title — w : — v : version MULTIPLEXERS: • technically they are considered emulators, however they are very distinct in that they dont necessary have graphical front ends (they need another terminal (emulator) to run inside of), and they can emulate multiple terminals without window magic (ie. tabs and windows are displayed with text) • server-client based • greatly improve workflow especially on systems with a single display screen: • GNUware • has the worst name imaginable; there is little info on it online to begin with (as usual with GNUware), but googling it is borderline impossible; this is the single reason that i decided to go with tmux instead screen [options] : terminal manager; great for making shells independent from terminal emulator windows and thereby sending them to the background pass no arguments(/[options]) to create a screen session [options]: — S <string> : create screen session named <string> — ls : list running screen sessions — r (<string>) : reattach to screen session; if passed in the program will try to match <string> — X [screen] [command] : pass [command] into [screen]; (specify with an -S [...]) short cuts: • <leader> is user defined, but "CTRL + b" by default and often rebound to "CTRL + a" <leader> + [c] : create new window <leader> + <int> : swap to window <int> <leader> + [d] : detach from screen session <leader> + [k] : quit (Kill) screen session [ctrl] + [d] : terminate screen session commands inside screen: quit : closes screen session tmux: tmux [options] [verb] • with no options a new session is created [verb]: attach ([session]) : connect to existing session new-session [options] : creates now session — t [session] : attaches to an existing session as a group session; ie. tabs and processes are synced, but the sessions in the group can work (view tabs/type) independently; great if one wishes to work inside the same session on multiple monitors list-sessions : list running sessions Zellij: pass CLI: • ascii art is king • the output shall page by default if it is one very large dump (${PAGER} exists for a reason) Exit_codes: 0 - success !0 - error Streams: stdout - key output stderr - errors, logs stdin - input Flags: • options with predefined meaning • single letter flags are prefixed with a single (short options), while longer flags are prefixed with double hyphens (long options), by convention — most common conventional flags: -a, --all -d, --debug -f, --force --json -h, --help -o, --output -i, --input -p, --port -q, --quiet -u, --user --version -v --verbose - # when a file is expected, this specifies stdin; has to be last -- # no more flags are being provided so hyphens can be taken literally { fgrep -- - pufka.cdd } the long versions are more reliable • every short option should have a long equivalent, so if a ready-made command is shared with someone not quite at home with the program, he can rougly tell what is going • kebab-case or bust • if the cli is robust enough, it should have a system to hint at typos # This is how git does it $ git clone -dept 1 http://192.168.0.200/anon/software.git error: did you mean `--dept` (with two dashes)? Help: — the following flags should always be hooked to displaying a concise help message — h — help --help • unless there is a good reason not to do so, launching the application with no arguments should display a help message • if the help message is so large that it cannot realistically fit on a single screen, the program should have a second explicit-ly concise help message, which only shows and describes the key information bits Interactivity: • do not use color if not run interactively unless explicit-ly requested • prompt before destructive operations • show progress or a spinner if something takes a long time • abort file operations uppon exit {im looking at you "useradd"} Compatibility: — do not add a default verb; it could break backwards compatibility with scripts { // assume the following $ mycli -h mycli <verb> <string> : echo the result of <verb> operation on <string> verb: len : return the number of characters in the input; default // !!! reverse : return the input with its characters in reverse order // then someone writes a script: mycli moo im a cow // but we decided to add a new verb: moo : print the input with cowsay ascii art // now the users script stops functioning as it used to, // resulting in him deleting the root partition of his // employer's server, ultimately leading to his homelessness // and crack addiction } Configuration: • try to limit yourself to flags • if you cannot limit yourself to flags, attempt to introduce environment variables only • if you seriously need a configuration file, DO NOT VOMIT ALL OVER SOMEONES HOME FOLDER • using the home folder for storing configuration (including ~/.mycli/) is only acceptable if your program is so crucial that it warrants it { interactive system shell; (robust) editor } • please, PLEASE use ~/.config No_color_convention: https://no-color.org/ • color codes can fuck over TTYs or pollute logs • each program defining its own (unconventional) flag for turning colors off is insanity and a pain in the ass • if the environment var ${NO_COLOR} is set, the cli shall not output any ansii color codes • "\ Command-line software which adds ANSI color to its output by default \ should check for a NO_COLOR environment variable that, \ when present and not an empty string (regardless of its value), \ prevents the addition of ANSI color. \ " Margins: ?! • "\ As long as no error occurs, the lines will be prefixed by \"###\". \ Error messages will instead have a "---" prefix. \ This makes it easy to spot errors just by looking in the left margin. \ " — cmdtest User's Guide VT100: Escape_sequences: • named after how an ASCII escape char prefixes them • escape sequence are a bloody mess, they are poorly organized and their terminal support is all over the place \033[<format>m : controls the display of subsequenty outputed characters /**/] format := code | code ';' format ; // NOTE: codes with shitty support are ommited from the table BELOW +==============+================================+ I Result I Code I +==============+================================+ | ############ | foreground | background | +--------------+----------------+---------------+ | black | 30 | 40 | | red | 31 | 41 | | green | 32 | 42 | | yellow | 33 | 43 | | blue | 34 | 44 | | magenta | 35 | 45 | | cyan | 36 | 46 | | white | 37 | 47 | | <8bit-color> | 38;5;<8bc> | 48;5;<8bc> | +--------------+----------------+---------------+ | ############ | on | off | +--------------+----------------+---------------+ | reset | 0 | N/A | // everything back to normal | bold/bright | 1 | 21 | // often a brighter shade of the same colour | underline | 4 | 24 | | inverse | 7 | 27 | // swap foreground and background colours | crossed out | 9 | 29 | ------------------------------------------------+ \033[<int-1>;<int-2>H : moves the cursor to line <int-1> column <int-2> /**/] \033[s : save cursor position /**/] \033[u : restore saved cursor position /**/] \033[<int = 1><char> : controls the cursor /**/] +------+----------------------------+ | Char | Effect | +------+----------------------------+ | A | upward | | B | downward | | C | forward | | D | backward | | E | downward start of the line | | F | upward start of the line | | G | <int>th column | +------+----------------------------+ VT320: https://www.arewesixelyet.com/ • supports images through escape sequences in the formal of sixel ("SIX pixELs") • poor, but improving terminal support { Sixel +--+ | | bit 1 +--+ | | bit 2 +--+ | | bit 3 +--+ | | bit 4 +--+ | | bit 5 +--+ | | bit 6 +--+ } { // sixel grammar sixel := "\033P" <parameters> "q" <data> "\033\\" parameters := %empty | <aspect-ratio> ";" <background> ";" <p3> aspect-ration := %empty | 0 | 1 | 5 | 6 // 2:1 | 2 // 5:1 | 3 | 4 // 3:1 | 7 | 8 | 9 // 1:1 /* per pixel */ back-ground := 0 | 2 // position 0 -> background color | 1 // position 0 -> color data := <token>+ token := <char> | <repeat> | <color-specifier> | "-" // new line; NOTE: this steps 6 pixels downwards, not a character line | "$" // carriage return char := [?-~] /* each character represents 6 vertical pixels, * interpreted as binary(char - '?') */ repeat := "!" <digit>+ <char> color-specifier := "#" 0-255 ";" <mode> ";" <digit> ";" <digit> ";" <digit> mode := 1 // HLS | 2 // RGB } $ echo '\033Pq#0;2;100;0;0#1;2;0;100;0#2;2;100;100;100-#2!30~-#1!30~\033\' Libraries: — ncurses { see AT "C/3th party libraries/ncurses" }: • industry standard • outdated, buggy, incomplete piece of shit • mostly used because of historical reasons and its outstanding compatibility — notcurses: • wanna be ncurses killer • featureful • the ugliest interface i have ever seen — ftxui: • C++/CMAKE • meh on all fronts at best — urwin: ?! • python — whiptail: • shell • displays dialog boxes • capable of creating forms and yielding their result on exit { // $ whiptail --msgbox "Do you agree?" 7 17 ┌───────────────┐ │ │ │ Do you agree? │ │ │ │ <Ok> │ │ │ └───────────────┘ } — figlet: • used for printing bannersbanners are text composed of multiple ascii characters per letter • (sub)chapter names use figlet in this document { // $ figlet -f Small example _ _____ ____ _ _ __ _ __| |___ / -_) \ / _` | ' \| '_ \ / -_) \___/_\_\__,_|_|_|_| .__/_\___| |_| }