3 * Summary: System independent console IO functions
4 * Created by: dshaligram on Wed Jun 20 19:00:52 2007 UTC
22 input_history(size_t size
);
24 void new_input(const std::string
&s
);
27 const std::string
*prev();
28 const std::string
*next();
32 typedef std::list
<std::string
> string_list
;
35 string_list::iterator pos
;
39 void cursorxy(int x
, int y
);
40 inline void cursorxy(const coord_def
& p
) { cursorxy(p
.x
, p
.y
); }
42 // Read one key, flag it as a mouse event if appropriate, but apply no
43 // other conversions. Defined in lib$OS.cc, not in cio.cc.
46 // Converts a key to a direction key, converting keypad and other sequences
47 // to vi key sequences (shifted/control key directions are also handled). Non
48 // direction keys (hopefully) pass through unmangled.
49 int unmangle_direction_keys(int keyin
, KeymapContext keymap
= KMC_DEFAULT
,
50 bool fake_ctrl
= true, bool fake_shift
= true);
52 int nowrapcprintf(int wrapcol
, const char *s
, ...);
53 int nowrap_eol_cprintf(const char *s
, ...);
55 // Returns zero if user entered text and pressed Enter, otherwise returns the
56 // key pressed that caused the exit, usually Escape.
58 // If keyproc is provided, it must return 1 for normal processing, 0 to exit
59 // normally (pretend the user pressed Enter), or -1 to exit as if the user
61 int cancelable_get_line(char *buf
,
63 input_history
*mh
= NULL
,
64 int (*keyproc
)(int &c
) = NULL
);
66 // Do not use this templated function directly. Use the macro below instead.
67 template<int> static int cancelable_get_line_autohist_temp(char *buf
, int len
)
69 static input_history
hist(10);
70 return cancelable_get_line(buf
, len
, &hist
);
73 // This version of cancelable_get_line will automatically retain its own
74 // input history, independent of other calls to cancelable_get_line.
75 #define cancelable_get_line_autohist(buf, len) \
76 cancelable_get_line_autohist_temp<__LINE__>(buf, len)
83 enum button_state_type
93 BUTTON_SCRL_UP
= 0x100,
94 BUTTON_SCRL_DN
= 0x200,
97 c_mouse_event() : pos(-1, -1), bstate(0)
101 c_mouse_event(const coord_def
&c
, int state
= 0) : pos(c
), bstate(state
)
105 // Returns true for valid events.
106 operator bool () const
111 bool left_clicked() const
113 return (bstate
& BUTTON1
);
116 bool right_clicked() const
118 return (bstate
& BUTTON3
);
121 bool scroll_up() const
123 return (bstate
& (BUTTON4
| BUTTON4_DBL
| BUTTON_SCRL_UP
));
126 bool scroll_down() const
128 return (bstate
& (BUTTON2
| BUTTON2_DBL
| BUTTON_SCRL_DN
));
132 coord_def
get_mouse_pos();
133 c_mouse_event
get_mouse_event();
134 void new_mouse_event(const c_mouse_event
&ce
);
135 void c_input_reset(bool enable_mouse
, bool flush
= false);
137 // Keys that getch() must return for keys Crawl is interested in.
144 // 128 is off-limits because it's the code that's used when running
147 // This sequence of enums should not be rearranged.
191 CK_MOUSE_MOVE
= 10001,
204 cursor_control(bool cursor_enabled
)
205 : cstate(is_cursor_enabled()), smartcstate(is_smart_cursor_enabled())
207 enable_smart_cursor(false);
208 set_cursor_enabled(cursor_enabled
);
211 set_cursor_enabled(cstate
);
212 enable_smart_cursor(smartcstate
);
219 // Reads lines of text; used internally by cancelable_get_line.
223 line_reader(char *buffer
, size_t bufsz
,
224 int wrap_col
= get_number_of_cols());
225 virtual ~line_reader();
227 typedef int (*keyproc
)(int &key
);
229 int read_line(bool clear_previous
= true);
231 std::string
get_text() const;
233 void set_input_history(input_history
*ih
);
234 void set_keyproc(keyproc fn
);
237 void cursorto(int newcpos
);
238 virtual int process_key(int ch
);
241 void kill_to_begin();
243 bool is_wordchar(int c
);
248 input_history
*history
;
254 // These are subject to change during editing.
260 typedef int keycode_type
;