Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/clui/tinput.h

    r64d2b10 r9be9c4d  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737#define LIBCLUI_TINPUT_H_
    3838
     39#include <adt/list.h>
     40#include <async.h>
     41#include <inttypes.h>
     42#include <io/console.h>
     43#include <stdio.h>
     44
    3945#define HISTORY_LEN     10
    4046#define INPUT_MAX_SIZE  1024
     47
     48/** Begin enumeration of text completions.
     49 *
     50 * When user requests text completion, tinput will call this function to start
     51 * text completion operation. @a *cstart should be set to the position
     52 * (character index) of the first character of the 'word' that is being
     53 * completed. The resulting text is obtained by replacing the range of text
     54 * starting at @a *cstart and ending at @a pos with the completion text.
     55 *
     56 * The function can pass information to the get_next and fini functions
     57 * via @a state. The init function allocates the state object and stores
     58 * a pointer to it to @a *state. The fini function destroys the state object.
     59 *
     60 * @param text          Current contents of edit buffer (null-terminated).
     61 * @param pos           Current caret position.
     62 * @param cstart        Output, position in text where completion begins from.
     63 * @param state         Output, pointer to a client state object.
     64 *
     65 * @return              EOK on success, negative error code on failure.
     66 */
     67typedef int (*tinput_compl_init_fn)(wchar_t *text, size_t pos, size_t *cstart,
     68    void **state);
     69
     70/** Obtain one text completion alternative.
     71 *
     72 * Upon success the function sets @a *compl to point to a string, the
     73 * completion text. The caller (Tinput) should not modify or free the text.
     74 * The pointer is only valid until the next invocation of any completion
     75 * function.
     76 *
     77 * @param state         Pointer to state object created by the init funtion.
     78 * @param compl         Output, the completion text, ownership retained.
     79 *
     80 * @return              EOK on success, negative error code on failure.
     81 */
     82typedef int (*tinput_compl_get_next_fn)(void *state, char **compl);
     83
     84
     85/** Finish enumeration of text completions.
     86 *
     87 * The function must deallocate any state information allocated by the init
     88 * function or temporary data allocated by the get_next function.
     89 *
     90 * @param state         Pointer to state object created by the init funtion.
     91 */
     92typedef void (*tinput_compl_fini_fn)(void *state);
     93
     94/** Text completion ops. */
     95typedef struct {
     96        tinput_compl_init_fn init;
     97        tinput_compl_get_next_fn get_next;
     98        tinput_compl_fini_fn fini;
     99} tinput_compl_ops_t;
    41100
    42101/** Text input field (command line).
     
    45104 */
    46105typedef struct {
     106        /** Console */
     107        console_ctrl_t *console;
     108       
     109        /** Prompt string */
     110        char *prompt;
     111       
     112        /** Completion ops. */
     113        tinput_compl_ops_t *compl_ops;
     114       
    47115        /** Buffer holding text currently being edited */
    48116        wchar_t buffer[INPUT_MAX_SIZE + 1];
    49117       
    50         /** Screen coordinates of the top-left corner of the text field */
    51         sysarg_t col0;
    52         sysarg_t row0;
     118        /** Linear position on screen where the prompt starts */
     119        unsigned prompt_coord;
     120        /** Linear position on screen where the text field starts */
     121        unsigned text_coord;
    53122       
    54123        /** Screen dimensions */
     
    82151
    83152extern tinput_t *tinput_new(void);
     153extern int tinput_set_prompt(tinput_t *, const char *);
     154extern void tinput_set_compl_ops(tinput_t *, tinput_compl_ops_t *);
    84155extern void tinput_destroy(tinput_t *);
    85156extern int tinput_read(tinput_t *, char **);
Note: See TracChangeset for help on using the changeset viewer.