source: mainline/uspace/lib/clui/tinput.h@ 959b7ec

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 959b7ec was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[36a75a2]1/*
[9be9c4d]2 * Copyright (c) 2011 Jiri Svoboda
[36a75a2]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libclui
30 * @{
[9f1362d4]31 */
[36a75a2]32/**
33 * @file
34 */
35
36#ifndef LIBCLUI_TINPUT_H_
37#define LIBCLUI_TINPUT_H_
38
[79ae36dd]39#include <inttypes.h>
40#include <io/console.h>
[9be9c4d]41#include <stdio.h>
[79ae36dd]42
[9f1362d4]43#define HISTORY_LEN 10
44#define INPUT_MAX_SIZE 1024
[36a75a2]45
[9be9c4d]46/** Begin enumeration of text completions.
47 *
48 * When user requests text completion, tinput will call this function to start
49 * text completion operation. @a *cstart should be set to the position
50 * (character index) of the first character of the 'word' that is being
51 * completed. The resulting text is obtained by replacing the range of text
52 * starting at @a *cstart and ending at @a pos with the completion text.
53 *
54 * The function can pass information to the get_next and fini functions
55 * via @a state. The init function allocates the state object and stores
56 * a pointer to it to @a *state. The fini function destroys the state object.
57 *
58 * @param text Current contents of edit buffer (null-terminated).
59 * @param pos Current caret position.
60 * @param cstart Output, position in text where completion begins from.
61 * @param state Output, pointer to a client state object.
62 *
[cde999a]63 * @return EOK on success, error code on failure.
[9be9c4d]64 */
[b7fd2a0]65typedef errno_t (*tinput_compl_init_fn)(wchar_t *text, size_t pos, size_t *cstart,
[9be9c4d]66 void **state);
67
68/** Obtain one text completion alternative.
69 *
70 * Upon success the function sets @a *compl to point to a string, the
71 * completion text. The caller (Tinput) should not modify or free the text.
72 * The pointer is only valid until the next invocation of any completion
73 * function.
74 *
75 * @param state Pointer to state object created by the init funtion.
76 * @param compl Output, the completion text, ownership retained.
77 *
[cde999a]78 * @return EOK on success, error code on failure.
[9be9c4d]79 */
[b7fd2a0]80typedef errno_t (*tinput_compl_get_next_fn)(void *state, char **compl);
[9be9c4d]81
82/** Finish enumeration of text completions.
83 *
84 * The function must deallocate any state information allocated by the init
85 * function or temporary data allocated by the get_next function.
86 *
87 * @param state Pointer to state object created by the init funtion.
88 */
89typedef void (*tinput_compl_fini_fn)(void *state);
90
91/** Text completion ops. */
92typedef struct {
93 tinput_compl_init_fn init;
94 tinput_compl_get_next_fn get_next;
95 tinput_compl_fini_fn fini;
96} tinput_compl_ops_t;
97
[36a75a2]98/** Text input field (command line).
99 *
100 * Applications should treat this structure as opaque.
101 */
102typedef struct {
[79ae36dd]103 /** Console */
104 console_ctrl_t *console;
[a35b458]105
[9be9c4d]106 /** Prompt string */
107 char *prompt;
[a35b458]108
[9be9c4d]109 /** Completion ops. */
110 tinput_compl_ops_t *compl_ops;
[a35b458]111
[36a75a2]112 /** Buffer holding text currently being edited */
113 wchar_t buffer[INPUT_MAX_SIZE + 1];
[a35b458]114
[9be9c4d]115 /** Linear position on screen where the prompt starts */
116 unsigned prompt_coord;
117 /** Linear position on screen where the text field starts */
118 unsigned text_coord;
[a35b458]119
[36a75a2]120 /** Screen dimensions */
[96b02eb9]121 sysarg_t con_cols;
122 sysarg_t con_rows;
[a35b458]123
[36a75a2]124 /** Number of characters in @c buffer */
[9f1362d4]125 size_t nc;
[a35b458]126
[36a75a2]127 /** Caret position within buffer */
[9f1362d4]128 size_t pos;
[a35b458]129
[36a75a2]130 /** Selection mark position within buffer */
[9f1362d4]131 size_t sel_start;
[a35b458]132
[36a75a2]133 /** History (dynamically allocated strings) */
[9f1362d4]134 char *history[HISTORY_LEN + 1];
[a35b458]135
[36a75a2]136 /** Number of entries in @c history, not counting [0] */
[9f1362d4]137 size_t hnum;
[a35b458]138
[36a75a2]139 /** Current position in history */
[9f1362d4]140 size_t hpos;
[a35b458]141
[5db9084]142 /** @c true if finished with this line (return to caller) */
[36a75a2]143 bool done;
[a35b458]144
[5db9084]145 /** @c true if user requested to abort interactive loop */
146 bool exit_clui;
[a2bdcf87]147
148 /** @c true if left shift key is currently held */
149 bool lshift_held;
150
151 /** @c true if right shift key is currently held */
152 bool rshift_held;
[36a75a2]153} tinput_t;
154
155extern tinput_t *tinput_new(void);
[b7fd2a0]156extern errno_t tinput_set_prompt(tinput_t *, const char *);
[9be9c4d]157extern void tinput_set_compl_ops(tinput_t *, tinput_compl_ops_t *);
[9f1362d4]158extern void tinput_destroy(tinput_t *);
[b7fd2a0]159extern errno_t tinput_read(tinput_t *, char **);
160extern errno_t tinput_read_i(tinput_t *, const char *, char **);
[36a75a2]161
162#endif
163
164/** @}
165 */
Note: See TracBrowser for help on using the repository browser.