1 2 3 4 5 6 7 8 9 10 11 12 | #!/usr/bin/ksh93 FPATH="/usr/local/functions/shellcurses" initscr clear move 10 25 addstr "Example 1: Hello World!" move 23 1 refresh endwin exit 0 |
1 2 3 4 5 6 7 8 9 10 11 | #!/usr/bin/ksh93 FPATH="/usr/local/functions/shellcurses" initscr clear mvaddstr 10 25 "Example 2: Hello World!" move 23 1 refresh endwin exit 0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #!/usr/bin/ksh93 FPATH="/usr/local/functions/shellcurses" initscr clear PROMPT="Example 3: Enter some data...:" LEN="${#PROMPT}" (( COL = LEN + 2 + 1 )) mvaddstr 10 2 "${PROMPT}" move 10 ${COL} refresh ANS=$( getstr ) mvaddstr 15 2 "Here is the data you entered.: ${ANS}" move 23 1 refresh endwin exit 0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/ksh93 FPATH="/usr/local/functions/shellcurses" SCRWID="80" initscr clear #### Display a screen header, centered on the screen HEADER="Shell Curses Example 4" HDRWID="${#HEADER}" (( HDRBEGIN = ( SCRWID - HDRWID ) / 2 )) mvaddstr 1 ${HDRBEGIN} "${HEADER}" MENU[0]="First Menu Line" MENU[1]="Second Menu Line" MENU[2]="Third Menu Line" MENU[3]="Fourth Menu Line" MENU[4]="Fifth Menu Line" ITEMCNT="${#MENU[@]}" MENUWID="${#MENU[0]}" #### Determine the maximum length of the longest menu item for MENULINE in "${MENU[@]}" do (( ${#MENULINE} > MENUWID )) && (( MENUWID = ${#MENULINE} + 4 )) done #### Display the numbered menu item, centered on the screen (( COL = ( SCRWID - MENUWID ) / 2 )) NBR="0" for MENULINE in "${MENU[@]}" do mvaddstr $(( ++NBR + 4 )) ${COL} "${NBR} = ${MENULINE}" done #### Prompt the user for a selection mvaddstr 22 2 "Enter the number of your selection: " mvaddstr 23 2 "( 0 = Exit )" #### Read the users selection from the screen ANSWER="99" while [[ "_${ANSWER}" != _[0-9] ]] || (( ANSWER < 1 )) || (( ANSWER > ITEMCNT )) do [[ "_${ANSWER}" == _0 ]] && exit 0 mvclrtoeol 22 40 refresh ANSWER="$( getstr )" done #### Display the item number selected by the user clear mvaddstr 1 ${HDRBEGIN} "${HEADER}" mvaddstr 4 2 "You selected menu item number ${ANSWER}" move 23 1 refresh endwin exit ${ANSWER} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #!/usr/bin/ksh93 FPATH="/usr/local/functions/shellcurses" initscr SCRWID="${MAX_COLS}" SCRLEN="${MAX_LINES}" clear #### Display a two line header, centered on the screen HEADER1="Shell Curses Example 5" HEADER2="Data Entry Screen" mvaddstr 1 $(( ( SCRWID - ${#HEADER1} ) / 2 )) "${HEADER1}" mvaddstr 2 $(( ( SCRWID - ${#HEADER2} ) / 2 )) "${HEADER2}" #### Define the user entry prompts DOTS="........................................" PRMPT[1]="Enter an existing directory name" PRMPT[2]="Enter an existing regular file name" PRMPT[3]="Enter an alpha-numeric value" PRMPT[4]="Enter a numeric value" PRMPT[5]="Enter an executable file name" PCNT="${#PRMPT[@]}" #### Display the numbered data entry prompt with trailing dots for IDX in "${!PRMPT[@]}" do (( DOTWID = ( SCRWID / 2 ) - ( ${#PRMPT[IDX]} + 4 ) )) PRMPT[IDX]="${PRMPT[IDX]}${DOTS:0{DOTWID}}" mvaddstr $(( IDX + 4 )) 2 "${IDX}: ${PRMPT[IDX]}...:" done DATACOL="$(( ${#PRMPT[1]} + 10 ))" #### Prompt the user for a selection mvaddstr $(( SCRLEN - 3 )) 2 "Select a line number to enter data:" #### Read the users data line number selection from the screen while : do #### Read the line number entered by the user mvclrtoeol $(( SCRLEN - 3 )) 40 refresh ANS="$( getstr )" #### clear the status line and re-display the default status message mvclrtoeol $(( SCRLEN - 2 )) 2 mvaddstr $(( SCRLEN - 2 )) 2 "( 0 = Exit )" #### Validate the user entered line number, if invalid go back and ask again [[ "_${ANS}" == "_0" ]] && exit 0 if [[ "_${ANS}" != _+([[:digit:]]) ]] || (( ANS < 1 )) || (( ANS > PCNT )) then continue fi #### Read the line data from the user entry mvclrtoeol $(( ANS + 4 )) ${DATACOL} refresh DATA[${ANS}]="$( getstr )" mvclrtoeol $(( SCRLEN - 2 )) 2 attrset rev #### Check the validity of the line 1 data as entered by the user if (( ANS == 1 )) && [[ ! -d "${DATA[${ANS}]}" ]] then mvclrtoeol $(( ANS + 4 )) ${DATACOL} mvaddstr $(( SCRLEN - 2 )) 2 "ERROR: Invalid Directory Name" fi #### Check the validity of the line 2 data as entered by the user if (( ANS == 2 )) && [[ ! -f "${DATA[${ANS}]}" ]] then mvclrtoeol $(( ANS + 4 )) ${DATACOL} mvaddstr $(( SCRLEN - 2 )) 2 "ERROR: Invalid Regular File Name" fi #### Check the validity of the line 3 data as entered by the user if (( ANS == 3 )) && [[ "_${DATA[${ANS}]}" != _+([[:alnum:]]) ]] then mvclrtoeol $(( ANS + 4 )) ${DATACOL} mvaddstr $(( SCRLEN - 2 )) 2 "ERROR: Invalid Alpha-Numeric Value" fi #### Check the validity of the line 4 data as entered by the user if (( ANS == 4 )) && [[ "_${DATA[${ANS}]}" != _+([[:digit:]]) ]] then mvclrtoeol $(( ANS + 4 )) ${DATACOL} mvaddstr $(( SCRLEN - 2 )) 2 "ERROR: Invalid Numeric Value" fi #### Check the validity of the line 5 data as entered by the user if (( ANS == 5 )) && [[ ! -x "${DATA[${ANS}]}" ]] then mvclrtoeol $(( ANS + 4 )) ${DATACOL} mvaddstr $(( SCRLEN - 2 )) 2 "ERROR: File is not executable or does not exist" fi attroff refresh done endwin exit ${ANS} |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |