Changeset 371a012 in mainline for uspace/app/bdsh/input.c


Ignore:
Timestamp:
2009-12-05T16:33:39Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
51ea01e
Parents:
ed372da
Message:

Copy and paste in bdsh input.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/input.c

    red372da r371a012  
    3838#include <io/color.h>
    3939#include <vfs/vfs.h>
     40#include <clipboard.h>
    4041#include <errno.h>
    4142#include <assert.h>
     
    449450}
    450451
     452static void tinput_sel_copy_to_cb(tinput_t *ti)
     453{
     454        int sa, sb;
     455        wchar_t tmp_c;
     456        char *str;
     457
     458        tinput_sel_get_bounds(ti, &sa, &sb);
     459
     460        if (sb < ti->nc) {
     461                tmp_c = ti->buffer[sb];
     462                ti->buffer[sb] = '\0';
     463        }
     464
     465        str = wstr_to_astr(ti->buffer + sa);
     466
     467        if (sb < ti->nc)
     468                ti->buffer[sb] = tmp_c;
     469
     470        if (str == NULL)
     471                goto error;
     472
     473        if (clipboard_put_str(str) != EOK)
     474                goto error;
     475
     476        free(str);
     477        return;
     478error:
     479        return;
     480        /* TODO: Give the user some warning. */
     481}
     482
     483static void tinput_paste_from_cb(tinput_t *ti)
     484{
     485        char *str;
     486        size_t off;
     487        wchar_t c;
     488        int rc;
     489
     490        rc = clipboard_get_str(&str);
     491        if (rc != EOK || str == NULL)
     492                return; /* TODO: Give the user some warning. */
     493
     494        off = 0;
     495
     496        while (true) {
     497                c = str_decode(str, &off, STR_NO_LIMIT);
     498                if (c == '\0')
     499                        break;
     500
     501                tinput_insert_char(ti, c);
     502        }
     503
     504        free(str);
     505}
     506
    451507static void tinput_history_seek(tinput_t *ti, int offs)
    452508{
     
    564620                tinput_seek_vertical(ti, seek_forward, false);
    565621                break;
     622        case KC_C:
     623                tinput_sel_copy_to_cb(ti);
     624                break;
     625        case KC_V:
     626                tinput_paste_from_cb(ti);
     627                break;
    566628        default:
    567629                break;
Note: See TracChangeset for help on using the changeset viewer.