Changeset bd5f3b7 in mainline for uspace/lib/clui/tinput.h


Ignore:
Timestamp:
2011-08-21T13:07:35Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00aece0, f1a9e87
Parents:
86a34d3e (diff), a6480d5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r86a34d3e rbd5f3b7  
    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 <stdio.h>
     39#include <adt/list.h>
    4040#include <async.h>
    4141#include <inttypes.h>
    4242#include <io/console.h>
     43#include <stdio.h>
    4344
    4445#define HISTORY_LEN     10
    4546#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;
    46100
    47101/** Text input field (command line).
     
    53107        console_ctrl_t *console;
    54108       
     109        /** Prompt string */
     110        char *prompt;
     111       
     112        /** Completion ops. */
     113        tinput_compl_ops_t *compl_ops;
     114       
    55115        /** Buffer holding text currently being edited */
    56116        wchar_t buffer[INPUT_MAX_SIZE + 1];
    57117       
    58         /** Screen coordinates of the top-left corner of the text field */
    59         sysarg_t col0;
    60         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;
    61122       
    62123        /** Screen dimensions */
     
    90151
    91152extern 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 *);
    92155extern void tinput_destroy(tinput_t *);
    93156extern int tinput_read(tinput_t *, char **);
Note: See TracChangeset for help on using the changeset viewer.