📄 ncurses2-demo_forms.adb
字号:
), ( Key_Home, REQ_FIRST_FIELD ), ( KEY_LEFT, REQ_LEFT_CHAR ), ( KEY_LL, REQ_LAST_FIELD ), ( Key_Next, REQ_NEXT_FIELD ), ( KEY_NPAGE, REQ_NEXT_PAGE ), ( KEY_PPAGE, REQ_PREV_PAGE ), ( Key_Previous, REQ_PREV_FIELD ), ( KEY_RIGHT, REQ_RIGHT_CHAR ), ( KEY_UP, REQ_UP_CHAR ), ( Character'Pos ('Q') mod 16#20#, -- QUIT Form_Request_Code'Last + 1 -- TODO MAX_FORM_COMMAND + 1 ) ); c : Key_Code := Getchar (w); me : Field := Current (f); begin if c = Character'Pos (']') mod 16#20# then if mode = REQ_INS_MODE then mode := REQ_OVL_MODE; else mode := REQ_INS_MODE; end if; c := mode; else for n in lookup'Range loop if lookup (n).code = c then c := lookup (n).result; exit; end if; end loop; end if; -- Force the field that the user is typing into to be in reverse video, -- while the other fields are shown underlined. if c <= Key_Max then c := edit_secure (me, c); Set_Background (me, (Reverse_Video => True, others => False)); elsif c <= Form_Request_Code'Last then c := edit_secure (me, c); Set_Background (me, (Under_Line => True, others => False)); end if; return c; end form_virtualize; function my_form_driver (f : Form; c : Key_Code) return Boolean is flag : Driver_Result := Driver (f, F_Validate_Field); begin if c = Form_Request_Code'Last + 1 and flag = Form_Ok then return True; else Beep; return False; end if; end my_form_driver; function make_label (frow : Line_Position; fcol : Column_Position; label : String) return Field is f : Field := Create (1, label'Length, frow, fcol, 0, 0); o : Field_Option_Set := Get_Options (f); begin if f /= Null_Field then Set_Buffer (f, 0, label); o.Active := False; Set_Options (f, o); end if; return f; end make_label; function make_field (frow : Line_Position; fcol : Column_Position; rows : Line_Count; cols : Column_Count; secure : Boolean) return Field is f : Field; use StringData; len : myptr; begin if secure then f := Create (rows, cols, frow, fcol, 0, 1); else f := Create (rows, cols, frow, fcol, 0, 0); end if; if f /= Null_Field then Set_Background (f, (Under_Line => True, others => False)); len := new Integer; len.all := 0; Set_User_Data (f, len); end if; return f; end make_field; procedure display_form (f : Form) is w : Window; rows : Line_Count; cols : Column_Count; begin Scale (f, rows, cols); w := New_Window (rows + 2, cols + 4, 0, 0); if w /= Null_Window then Set_Window (f, w); Set_Sub_Window (f, Derived_Window (w, rows, cols, 1, 2)); Box (w); -- 0,0 Set_KeyPad_Mode (w, True); end if; -- TODO if Post(f) /= Form_Ok then it's a procedure declare begin Post (f); exception when Eti_System_Error | Eti_Bad_Argument | Eti_Posted | Eti_Connected | Eti_Bad_State | Eti_No_Room | Eti_Not_Posted | Eti_Unknown_Command | Eti_No_Match | Eti_Not_Selectable | Eti_Not_Connected | Eti_Request_Denied | Eti_Invalid_Field | Eti_Current => Refresh (w); end; -- end if; end display_form; procedure erase_form (f : Form) is w : Window := Get_Window (f); s : Window := Get_Sub_Window (f); begin Post (f, False); Erase (w); Refresh (w); Delete (s); Delete (w); end erase_form; finished : Boolean := False; f : Field_Array_Access := new Field_Array (1 .. 12); secure : Field; myform : Form; w : Window; c : Key_Code; result : Driver_Result;begin Move_Cursor (Line => 18, Column => 0); Add (Str => "Defined form-traversal keys: ^Q/ESC- exit form"); Add (Ch => newl); Add (Str => "^N -- go to next field ^P -- go to previous field"); Add (Ch => newl); Add (Str => "Home -- go to first field End -- go to last field"); Add (Ch => newl); Add (Str => "^L -- go to field to left ^R -- go to field to right"); Add (Ch => newl); Add (Str => "^U -- move upward to field ^D -- move downward to field"); Add (Ch => newl); Add (Str => "^W -- go to next word ^B -- go to previous word"); Add (Ch => newl); Add (Str => "^S -- go to start of field ^E -- go to end of field"); Add (Ch => newl); Add (Str => "^H -- delete previous char ^Y -- delete line"); Add (Ch => newl); Add (Str => "^G -- delete current word ^C -- clear to end of line"); Add (Ch => newl); Add (Str => "^K -- clear to end of field ^X -- clear field"); Add (Ch => newl); Add (Str => "Arrow keys move within a field as you would expect."); Add (Line => 4, Column => 57, Str => "Forms Entry Test"); Refresh; -- describe the form f (1) := make_label (0, 15, "Sample Form"); f (2) := make_label (2, 0, "Last Name"); f (3) := make_field (3, 0, 1, 18, False); f (4) := make_label (2, 20, "First Name"); f (5) := make_field (3, 20, 1, 12, False); f (6) := make_label (2, 34, "Middle Name"); f (7) := make_field (3, 34, 1, 12, False); f (8) := make_label (5, 0, "Comments"); f (9) := make_field (6, 0, 4, 46, False); f (10) := make_label (5, 20, "Password:"); f (11) := make_field (5, 30, 1, 9, True); secure := f (11); f (12) := Null_Field; myform := New_Form (f); display_form (myform); w := Get_Window (myform); Set_Raw_Mode (SwitchOn => True); Set_NL_Mode (SwitchOn => True); -- lets us read ^M's while not finished loop c := form_virtualize (myform, w); result := Driver (myform, c); case result is when Form_Ok => Add (Line => 5, Column => 57, Str => Get_Buffer (secure, 1)); Clear_To_End_Of_Line; Refresh; when Unknown_Request => finished := my_form_driver (myform, c); when others => Beep; end case; end loop; erase_form (myform); -- TODO Free_Form(myform); -- for (c = 0; f[c] != 0; c++) free_field(f[c]); Set_Raw_Mode (SwitchOn => False); Set_NL_Mode (SwitchOn => True);end ncurses2.demo_forms;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -