Skip to content

Commit

Permalink
feat: console.c added
Browse files Browse the repository at this point in the history
  • Loading branch information
cylobi committed Mar 10, 2024
1 parent bd016b2 commit 76ed32d
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions console.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Console input and output.
// Input is from the keyboard or serial port.
// Output is written to the screen and serial port.

#include "types.h"
#include "defs.h"
#include "param.h"
Expand Down Expand Up @@ -187,6 +186,9 @@ struct {
} input;

#define C(x) ((x)-'@') // Control-x
#define K 4
char saved_buf[INPUT_BUF]; // saved buffer of copy-paste
int saved_buffer_size = 0;

void
consoleintr(int (*getc)(void))
Expand All @@ -200,6 +202,51 @@ consoleintr(int (*getc)(void))
// procdump() locks cons.lock indirectly; invoke later
doprocdump = 1;
break;
case 67: case 88: //copy and cut
for (int i = (input.e - input.r) - K; i < input.e - input.r ; i++)
{
saved_buf[i - (input.e - input.r - K)] = input.buf[(input.r + i ) % INPUT_BUF];
saved_buffer_size += 1;
}

if (c == 88)
{
while(input.e != input.w && input.buf[(input.e-1) % INPUT_BUF] != '\n'){
input.e--;
consputc(BACKSPACE);
}
}
break;
case 86: //paste
for (int i = 0; i < saved_buffer_size; i++)
{
c = saved_buf[i];
consputc(c);
}
break;

case C('E'):
for (int i = 0; i < input.e - input.r ; i++)
{
int temp = input.buf[(input.r + i ) % INPUT_BUF];
if(temp >= 48 && temp <= 53)
{
temp += 4;
}
else if(temp >= 54 && temp <= 57)
{

}
else if(temp >= 97 && temp <= 122)
{

}
else if(temp >= 65 && temp <= 90)
{

}
// saved_buf[i] =
}
case C('U'): // Kill line.
while(input.e != input.w &&
input.buf[(input.e-1) % INPUT_BUF] != '\n'){
Expand Down Expand Up @@ -293,7 +340,5 @@ consoleinit(void)
devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread;
cons.locking = 1;

ioapicenable(IRQ_KBD, 0);
}

0 comments on commit 76ed32d

Please sign in to comment.