Changeset e8a9dc3 in mainline for generic/src/console/console.c


Ignore:
Timestamp:
2005-12-10T16:37:20Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e5fcf00
Parents:
f7f6f25
Message:

Added support for backspace

  • printing '\b' should move the cursor one char to the left
  • backspace key should return '\b' to application
File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/console/console.c

    rf7f6f25 re8a9dc3  
    4040chardev_t *stdout = NULL;
    4141
     42/** Get character from character device.
     43 *
     44 * @param chardev Character device.
     45 *
     46 * @return Character read.
     47 */
     48static __u8 _getc(chardev_t *chardev)
     49{
     50        __u8 ch;
     51        ipl_t ipl;
     52
     53        waitq_sleep(&chardev->wq);
     54        ipl = interrupts_disable();
     55        spinlock_lock(&chardev->lock);
     56        ch = chardev->buffer[(chardev->index - chardev->counter) % CHARDEV_BUFLEN];
     57        chardev->counter--;
     58        spinlock_unlock(&chardev->lock);
     59        interrupts_restore(ipl);
     60
     61        chardev->op->resume(chardev);
     62
     63        return ch;
     64}
     65
    4266/** Get string from character device.
    4367 *
     
    5781
    5882        while (index < buflen) {
    59                 ch = getc(chardev);
     83                ch = _getc(chardev);
     84                if (ch == '\b') {
     85                        if (index > 0) {
     86                                index--;
     87                                /* Space backspace, space */
     88                                putchar('\b');
     89                                putchar(' ');
     90                                putchar('\b');
     91                        }
     92                        continue;
     93                }
     94                putchar(ch);
     95
    6096                if (ch == '\n') { /* end of string => write 0, return */
    6197                        buf[index] = '\0';
     
    67103}
    68104
    69 /** Get character from character device.
    70  *
    71  * @param chardev Character device.
    72  *
    73  * @return Character read.
    74  */
     105/** Get character from device & echo it to screen */
    75106__u8 getc(chardev_t *chardev)
    76107{
    77108        __u8 ch;
    78         ipl_t ipl;
    79109
    80         waitq_sleep(&chardev->wq);
    81         ipl = interrupts_disable();
    82         spinlock_lock(&chardev->lock);
    83         ch = chardev->buffer[(chardev->index - chardev->counter) % CHARDEV_BUFLEN];
    84         chardev->counter--;
    85         spinlock_unlock(&chardev->lock);
    86         interrupts_restore(ipl);
    87 
    88         chardev->op->resume(chardev);
    89 
     110        ch = _getc(chardev);
     111        putchar(ch);
    90112        return ch;
    91113}
Note: See TracChangeset for help on using the changeset viewer.