help
来自「LastWave」· 代码 · 共 881 行 · 第 1/2 页
TXT
881 行
if (!flagC) {fs = [proc slist '!'+cmd+'!']} if (fs.length==0) {fc = [proc clist '!'+cmd+'!']} else {fc = {}} } else { fs = {} fc = {} } ### Let's get all the matching cmd if (fs.length==0 && fc.length==0) { fs = {} if (!flagC) {fs = [proc slist '!'+cmd+'!'+'*']} fc = [proc clist '!'+cmd+'!'+'*'] if (fc.length == 1 && fs.length == 1) { if (fc[0]==fs[0]) {fc = {}} } } flagScript = 0 if (fs.length+fc.length == 0) { return {0 ""} } answer = 1 compl = [_GetCompletion cmd fs+fc] if (fs.length+fc.length > 1) { listv niceprint fs+fc return {2 compl} } ### If a single answer then we should print whether it is a C or script command if (fs.length + fc.length == 1 && fs.length == 1) { file=%${fs[0]}.file if (file != '') {echo \[$file\]} else {echo \[defined in terminal\]} } ### Let's get the corresponding helps help = {} foreach f1 fs+fc { if (flagC) {fff = %\\$f1} else {fff = %$f1} h = fff.help if (h.length==0) { if ([proc slist f1].length!=0) { h = {{"{"+[proc var f1]+"}" ""}} } else { h = {{"Error in the Usage string (it should have been mentionned at startup)" "Error in the Help string (it should have been mentionned at startup)"}} } } help+= {{h f1}} } ### Then we print all the usages and descriptions foreach help2 help { {help2 f1} = help2 ### Keep the right action only if (action != '' && help2.length != 1) { help3 = {} foreach help1 help2 { {u h} = help1 l = [str match u '^[{][* ]|[*^ ]|' 1] a = u[l] if ([str match a '^!'+action+'!*'].length!=0) { help3 += {help1} } } if (help3.length!=0) {help2 = help3} } foreach help1 help2 { ### Get the right help/usage and removes {} {u h} = help1 if (u == '{}') {u = ''} if ([str match u '{+}'].length!=0) {u = u[1:@>-1]} if (h == '{}') {h = ''} if ([str match h '{+}'].length!=0) {h = h[1:@>-1]} # First we print the usage printf "--- %s " f1 blank=' '*(f1.length+5) _PrintSplitStr u blank 2 # Then the help if (flagHelp) {_PrintSplitStr h blank 1} } } return {answer compl}}## The help command # It prints the help on 'name'#setproc help {{&word name ``} {&word name1 ``}} \ "{{{(*commandName* [*action*] | *type* [*fieldName*])} {Displays help on a command or a &type. If *commandName* is not a valid command name then it prints a list \of commands which name begins with *commandName*. if a *type* is specified (i.e., a string starting with '&'), it displays the doc on the corresponding type and \on all the fields. If *field* is specified then only the corresponding field is displayed. If *fieldName* is not a valid field name then it prints a list \of fields which name begins with *fieldName*.}}}" \{ if (name == '') { Help return } if (name[0] == '&') { answer = [_PrintTypeDoc name name1] if (answer == 0) { terminal beep return } return } fs = [proc list '!'+name+'!'] if (fs.length ==0) {blank = 0} else {blank = 1} {answer compl} = [_PrintCmdUsage name name1 1 blank] if (answer == 0) { terminal beep return }}setproc man {} { Help return}## The helpp command # It prints the help on a package#setproc helpp {{&word pack ``}} \ "{{{[*packageName*]} {Displays help on a package and all the commands available. If *packageName is not a valid name, it prints the names of available packages that \start with *packageName*. If no *packageName* is specified it gives a list of all the available packages.}}}" \{ answer = [_PrintPackageHelp pack] if (answer == 0) { terminal beep return }}## The helpv command # It prints the help on value#setproc helpv {{&valobj val} {&word name1 ``}} \ "{{{<val> [*fieldname*]} {Displays help the fields of a value. If *fieldName* is not a valid field name then it prints a list \of fields which name begins with *fieldName*. The value should not be a number (numbers do not have any field!).}}}" \{ type = [val type val] {answer compl} = [_PrintFieldUsage type name1 0 1] if (answer == 0) { terminal beep return }}setproc _TermComp {line cursor insert comp} { printf "%s" [terminal prompt] terminal line line if (comp != '') { terminal cursor insert terminal insert comp } else { terminal cursor cursor }}## Function for command completion#binding delete 'ccompletion'setbinding 'ccompletion' "Terminal command and field completion"setbinding 'ccompletion' terminal keyDown _help {_CommandComp 0}setbinding 'ccompletion' terminal keyDown 'esc h' {_CommandComp 1}setproc _CommandComp {flagHelp} { if ([terminal mode] != 'command') {return} #### get the command line and the cursor position line=[terminal line] cursor=[terminal cursor] #### if the line is empty then return line1 = line line1[[str match line1 "^[+ ]"]] := {""} if (line1.length == 0) { terminal beep return } ### we reverse the line if (cursor != 0) { line1 = line[:!cursor] rline = line1[:-1:] } else { line1 = '' rline = '' } ### find the first '[' or '.' or blank l = [str match rline '[. []' 1] ### ### if nothing or blank --> command completion ! ### blank = 0 if (l.length!=0) { if (rline[l[0]]== ' ') { blank = 1 l={} } } if (l.length==0) { ### We have to get the cmd name l = [str match line '[* ]|[*^ ]|' 1] cmd = line[l] l = l[0] if (type(l)=='&num') {insert=l+1} else {insert = l.last+1} ### And an eventual action line1 = line[*no,insert:@>+1] l = [str match line1 '[* ]|[+^ ]|' 1] if (l.length==0) { action = "" } else { l = l[0] action = line1[l] } ### And call the subroutine printf "\n" {ans comp} = [_PrintCmdUsage cmd action flagHelp blank] if (ans == 0) { terminal beep comp = "" } _TermComp line cursor insert comp return } ### ### Field completion ! ### if (rline[l[0]]== '.') { c = '.' extract = 0 } else { c = '[' extract = 1 } l = [str match line1 '!'+c+'!'] if (l.length==0) {return} l = l[l.length-1] e = l-1 if (!extract) {field = line1[*no,e+2:@>+1]} else {field = ""} insert = cursor b = e r = null while (b>=0) { if (b != 0) { if (line1[b-1] == '.') { b-=1 continue } } line2 = line1[b:e] if (b != 0) { if ([str match line1[b-1] '[0123456789.]'].length!=0) { b -= 1 continue } } r = [val test $line2 '&valobj' -l -1] if (r == null) { b -=1 continue } if (b!=0) { c = line1[b-1] if (c>='A' && c<='Z' || c>='a' && c<='z' || c=='_') { b-=1 continue } } break } if (r == null) { terminal beep return } ### Case of signal.X[ if (extract) { l = [str match line1 '.'] if (l.length!=0) { l = l[l.length-1] if (l > b && l < e) { field1 = line1[*no,l+1:e] line2 = line1[b:l-1] r1 = [val test $line2 '&valobj' -l -1] if (r1 != null) { {type val} = r1 if ([type field type field1 -e] != null) { field = field1 r = r1 } } } } } {type val} = r printf "\n" {ans comp} = [_PrintFieldUsage type field extract flagHelp] if (ans == 0) { terminal beep comp = "" } _TermComp line cursor insert comp return } #let's activate the bindingbinding activate 'ccompletion'setproc _SearchWord {w str} { r = [str substr str w 1] if (r.length != 0) {return r} if (w[0] < 'a' || w[0] > 'z') {return r} w1 = [str 2ascii w] w1[0]-=32 w = [str ascii2 w1] r = [str substr str w 1] return r }setproc apropos {{&word w} {&wordlist .wl}} "{{{*word1* [*word2* ... *wordN*]} {Search for all the commands whose help contain the strings *word<i>* (any order). \For each package, it prints each of the so-obtained command with the corresponding part of the help around the occurence of *word1*}}}" { l = {{'kernel' 1}} + [package list] foreach p l { if (p[1] == 0) {continue} flag = 0 {sl cl} = [proc list '[^_]*' '*' p[0]] lv = sl+cl lv = [listv sort lv] foreach c lv { c1 = [proc get c] foreach h c1.help { if (h.length == 1) {printf "**Warningf : bad help string format for command '%s'\n\n" c ;; continue} h1 = h[1] if (h1 == '{}') {h1 = ''} h1 = h1[1:@>-1] r = [_SearchWord w h1] if (r.length == 0) {continue} flagStop = 0 foreach ww wl { r1 = [_SearchWord ww h1] if (r1.length == 0) { flagStop = 1 break } } if (flagStop == 1) {continue} if (flag == 0) { printf "--> Package '%s'\n" p[0] flag = 1 } printf "%s" c h0 = h[0] a = h0[[str match h0 '^{|[*^ ]|']] a1 = a[0] if (a1>='a' && a1<='z') { printf " %s" a } f = r[0].first-25 l = r[0].last+25 printf " : " if (f > 0) {printf "..."} printf "%s" h1[*no,f:l] if (l < h1.length-1) {printf "..."} printf "\n" } } if (flag == 1) {printf "\n"} }}## Simple command that displays Help#setproc Help {} "{{{} {Displays some basic help about the help system.}}}" { global _help printf "\nThese are what you should know about the help system: \n\n" printf " - While writing a command line, you can always use the completion \n" printf " keys '$_help' to get some help or completion on a command or a field\n\n" printf " - The command 'help *commandName*' (not a quoted name!) prints some help about a command\n" printf " - The command 'help &type' prints some help about a type\n\n" printf " - The command 'helpp *packageName*' prints some help about a package and the list of all the commnads in that package\n\n" printf " - The command 'helpv <value>' prints some help about a value\n\n" printf " - The command 'apropos *word1* [*word2* ... *wordN*]' looks for commands whose help contain the substrings *word<i>*\n\n"}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?