mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Improve kernel terminal line editing.
This commit is contained in:
parent
3c6ecd6512
commit
951b6edccd
3 changed files with 76 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -99,6 +99,13 @@ namespace Sortix
|
|||
return buffer[index];
|
||||
}
|
||||
|
||||
uint32_t LineBuffer::WouldBackspace() const
|
||||
{
|
||||
if ( !CanBackspace() ) { return 0; }
|
||||
size_t index = OffsetIndex(bufferoffset, bufferused-1, bufferlength);
|
||||
return buffer[index];
|
||||
}
|
||||
|
||||
void LineBuffer::Commit()
|
||||
{
|
||||
buffercommitted = bufferfrozen = bufferused;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -38,6 +38,7 @@ namespace Sortix
|
|||
uint32_t Pop();
|
||||
uint32_t Peek() const;
|
||||
uint32_t Backspace();
|
||||
uint32_t WouldBackspace() const;
|
||||
void Commit();
|
||||
void Freeze();
|
||||
bool CanPop() const;
|
||||
|
|
|
@ -22,27 +22,31 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sortix/kernel/platform.h>
|
||||
#include <sortix/kernel/refcount.h>
|
||||
#include <sortix/kernel/kthread.h>
|
||||
#include <sortix/kernel/interlock.h>
|
||||
#include <sortix/kernel/ioctx.h>
|
||||
#include <sortix/kernel/inode.h>
|
||||
#include <sortix/kernel/keyboard.h>
|
||||
#include <sortix/kernel/poll.h>
|
||||
#include <sortix/kernel/scheduler.h>
|
||||
#include <sortix/kernel/process.h>
|
||||
|
||||
#include <sortix/fcntl.h>
|
||||
#include <sortix/termmode.h>
|
||||
#include <sortix/termios.h>
|
||||
#include <sortix/keycodes.h>
|
||||
#include <sortix/signal.h>
|
||||
#include <sortix/stat.h>
|
||||
#include <sortix/poll.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sortix/fcntl.h>
|
||||
#include <sortix/keycodes.h>
|
||||
#include <sortix/poll.h>
|
||||
#include <sortix/signal.h>
|
||||
#include <sortix/stat.h>
|
||||
#include <sortix/termios.h>
|
||||
#include <sortix/termmode.h>
|
||||
|
||||
#include <sortix/kernel/platform.h>
|
||||
#include <sortix/kernel/inode.h>
|
||||
#include <sortix/kernel/interlock.h>
|
||||
#include <sortix/kernel/ioctx.h>
|
||||
#include <sortix/kernel/keyboard.h>
|
||||
#include <sortix/kernel/kthread.h>
|
||||
#include <sortix/kernel/poll.h>
|
||||
#include <sortix/kernel/process.h>
|
||||
#include <sortix/kernel/refcount.h>
|
||||
#include <sortix/kernel/scheduler.h>
|
||||
|
||||
#include "utf8.h"
|
||||
#include "logterminal.h"
|
||||
|
@ -166,6 +170,50 @@ void LogTerminal::ProcessKeystroke(int kbkey)
|
|||
return;
|
||||
}
|
||||
|
||||
if ( termmode & TERMMODE_LINEBUFFER && control && kbkey == KBKEY_W )
|
||||
{
|
||||
bool had_non_whitespace = false;
|
||||
c_w_delete_more:
|
||||
if ( !linebuffer.CanBackspace() ) { return; }
|
||||
uint32_t delchar = linebuffer.WouldBackspace();
|
||||
bool waskbkey = KBKEY_DECODE(delchar);
|
||||
bool wasuni = !waskbkey;
|
||||
bool whitespace =
|
||||
(wasuni && (delchar == ' ' ||
|
||||
delchar == '\t' ||
|
||||
delchar == '\n')) ||
|
||||
(waskbkey && (abs(KBKEY_DECODE(delchar)) == -KBKEY_SPACE ||
|
||||
abs(KBKEY_DECODE(delchar)) == -KBKEY_TAB ||
|
||||
abs(KBKEY_DECODE(delchar)) == -KBKEY_ENTER));
|
||||
if ( wasuni && whitespace && had_non_whitespace )
|
||||
return;
|
||||
if ( wasuni && !whitespace )
|
||||
had_non_whitespace = true;
|
||||
linebuffer.Backspace();
|
||||
if ( (!waskbkey || termmode & TERMMODE_KBKEY) &&
|
||||
(!wasuni || termmode & TERMMODE_UNICODE) &&
|
||||
termmode & TERMMODE_ECHO &&
|
||||
wasuni )
|
||||
Log::Print("\b");
|
||||
goto c_w_delete_more;
|
||||
}
|
||||
|
||||
if ( termmode & TERMMODE_LINEBUFFER && control && kbkey == KBKEY_U )
|
||||
{
|
||||
while ( linebuffer.CanBackspace() )
|
||||
{
|
||||
uint32_t delchar = linebuffer.Backspace();
|
||||
bool waskbkey = KBKEY_DECODE(delchar);
|
||||
bool wasuni = !waskbkey;
|
||||
if ( (!waskbkey || termmode & TERMMODE_KBKEY) &&
|
||||
(!wasuni || termmode & TERMMODE_UNICODE) &&
|
||||
termmode & TERMMODE_ECHO &&
|
||||
wasuni )
|
||||
Log::Print("\b");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t unikbkey = KBKEY_ENCODE(kbkey);
|
||||
QueueUnicode(unikbkey);
|
||||
uint32_t unicode = kblayout->Translate(kbkey);
|
||||
|
|
Loading…
Reference in a new issue