aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-03-06 20:48:28 +0000
committersotech117 <michael_foiani@brown.edu>2024-03-06 20:48:28 +0000
commit43c2a4fc158992d03355e54ae3550796ddaa8d36 (patch)
tree4b9c9338625af23dd9f3e8387048d1a0c899845a
parent059e9490743400baa53743b6dd7f2a0a14da9339 (diff)
refactor code
-rw-r--r--kernel/drivers/tty/ldisc.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/kernel/drivers/tty/ldisc.c b/kernel/drivers/tty/ldisc.c
index 1b79bae..67a6615 100644
--- a/kernel/drivers/tty/ldisc.c
+++ b/kernel/drivers/tty/ldisc.c
@@ -47,12 +47,6 @@ long ldisc_wait_read(ldisc_t *ldisc)
{
// NOT_YET_IMPLEMENTED("DRIVERS: ldisc_wait_read");
- // if it's full, return 0
- if (ldisc->ldisc_full)
- {
- return 0;
- }
-
// while there are no need chars to be read, sleep
// TODO: check if this is the right condition
while (
@@ -187,12 +181,6 @@ void ldisc_key_pressed(ldisc_t *ldisc, char c)
{
// NOT_YET_IMPLEMENTED("DRIVERS: ldisc_key_pressed");
- // if the buffer is full, ignore the incoming char
- if (ldisc->ldisc_full)
- {
- return;
- }
-
switch (c)
{
case '\b':
@@ -201,6 +189,12 @@ void ldisc_key_pressed(ldisc_t *ldisc, char c)
{
// remove the last char
ldisc->ldisc_head = (ldisc->ldisc_head - 1 + LDISC_BUFFER_SIZE) % LDISC_BUFFER_SIZE;
+
+ // if (ldisc->ldisc_full)
+ // {
+ // ldisc->ldisc_full = 0;
+ // }
+
// emit a `\b` to the vterminal
vterminal_write(&ldisc_to_tty(ldisc)->tty_vterminal, "\b", 1);
}
@@ -250,22 +244,23 @@ void ldisc_key_pressed(ldisc_t *ldisc, char c)
break;
default:
+ // if the buffer is full, ignore the incoming char
+ // if (ldisc->ldisc_full)
+ // {
+ // return;
+ // }
+
// if none applies, fallback to vterminal_key_pressed
// vterminal_write(ldisc_to_tty(ldisc), &c, 1);
ldisc->ldisc_buffer[ldisc->ldisc_head] = c;
- // update the buffer if it's full
- if ((ldisc->ldisc_head + 1) % LDISC_BUFFER_SIZE == ldisc->ldisc_tail)
- {
- ldisc->ldisc_full = 1;
- }
- else
+ // update the buffer if it's not full
+ if ((ldisc->ldisc_head + 1) % LDISC_BUFFER_SIZE != ldisc->ldisc_tail)
{
ldisc->ldisc_head = (ldisc->ldisc_head + 1) % LDISC_BUFFER_SIZE;
+ vterminal_key_pressed(&ldisc_to_tty(ldisc)->tty_vterminal);
}
- vterminal_key_pressed(&ldisc_to_tty(ldisc)->tty_vterminal);
-
break;
}
}