slitaz-base-files view doc/libtaz.txt @ rev 325

Tiny edit
author Paul Issott <paul@slitaz.org>
date Thu Feb 16 22:32:53 2017 +0000 (2017-02-16)
parents 5829aa52b9ee
children
line source
2 SYNOPSIS
3 . /lib/libtaz.sh
4 function
7 DESCRIPTION
8 LibTaz is the base SliTaz SHell library used by almost all tools and
9 utilities. It provides common SHell script functions, parses the cmdline
10 options and store values in a variable. The output messages can be
11 formatted for raw/text, gtk, html and by default they are formatted for
12 a standard terminal supporting colors. LibTaz is in the directory
13 /lib/libtaz.sh since it is used when /usr may not be mounted.
16 FUNCTIONS
17 _ <string> Short name for "eval_gettext string; echo"
18 _n <string> Short name for "eval_gettext string"
19 status Return command status [Done|Failed]
20 separator [<char>] Display a line separator
21 newline Echo a new line if gettext or echo -n is used
22 boldify <string> Use a bold font for term, html or GTK output
23 colorize NB <string> Colorize a string in term mode
24 indent NB [string] Indent text in term mode
25 emsg <string> Output mark up messages
26 check_root Check if user is logged as root
27 debug <string> Display a DEBUG message when --debug is used
28 die <string> Report error and finish work
29 im Returns true if you're in interactive mode
30 confirm Read answer to confirm an action
31 log <string> Log activity, $activity must be set
32 optlist <lines> Prints two-column list (of options, or functions, etc.)
33 longline <string> Wrap words in long terminal message
34 title <string> Print localized title
35 footer [<string>] Print footer
36 action <string> Print action
37 itemize <string> Print long line as list item (check for :-* markers)
40 OPTIONS
41 --output=[raw|gtk|html]
42 --activity=/path/files/activity
43 --quiet Display nothing but errors (usually: action ... status)
44 --cols=<number> Output width in columns
47 EXAMPLES
48 _ 'Hello, $USER!'
49 _ 'Hello, %s!' $USER
51 echo -n 'Removing...'; rm $file; status
53 separator
54 separator '*'
56 newline
58 boldify 'Bold text'
60 colorize 32 "Message"
61 myprogram --color=32
63 indent 32 "Message"
65 emsg "<b>bold</b> <c 31>red</c> separator<-> newline<n> <i 26>indent"
67 check_root
69 debug "A='$A'"
71 die 'Config %s absent. Exit' $config
74 Using confirm()
75 Use global options for auto-answering: '--yes' or '--noconfirm'.
76 Use global option '--timeout' to define the wait time (default is 30 s).
77 The letters "y", "Y", "n" and "N", used in the response, are localized.
78 1. Outdated syntax. No options. Displays translated " [y/N] ? " and waits
79 for your input.
80 Answer formula is "[y/N]": to answer "yes" you need to enter "y" (or "Y"),
81 while to answer "no" you may enter "n" or "N" or any other letter, or
82 even just press Enter.
84 echo -n "The question"; confirm && echo "Confirmed"
86 2. New syntax. Option is the string displayed. Answer formula the same.
88 confirm "The question [y/N]?" && echo "Confirmed"
90 3. Modern syntax. Two options: the question and the preferred answer.
91 Displays the question and then translated answer formula as "[Y/n]" or
92 "[y/N]" depending on the preferred answer.
94 confirm "The question?" y && echo "Confirmed"
96 In all cases, it returns "true" if you answer "yes", while returns "false"
97 otherwise.
100 activity='/var/log/my.log'
101 log "Message"
103 optlist "\
104 option1 Description1 (after one or any number of tab symbols)
105 -a option2 $(_ 'Description2')"
107 longline $(busybox --help)
108 longline "$(cat /usr/share/licenses/lgpl.txt)"
110 title "Summary"
111 footer "$(_ 'No errors found')"
112 action 'Checking settings...'; checking_settings; status
114 itemize " - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed d\
115 o eiusmod tempor incididunt ut labore et dolore magna aliqua."
116 itemize " * Ut enim ad minim veniam, quis nostrud exercitation ullamco lab\
117 oris nisi ut aliquip ex ea commodo consequat."
120 USAGE NOTES
121 SliTaz Base functions used from boot scripts to end user tools.
122 Use gettext and not echo for messages. Keep output suitable for GTK boxes
123 and Ncurses dialog. LibTaz should not depend on any configuration file.
124 No bloated code here, functions must be used by at least 3-4 tools.
127 AUTHORS
128 Christophe Lincoln
129 Aleksej Bobylev