-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lecture 109 - Implementing the ability to read lines
- Loading branch information
1 parent
b10cefb
commit bea44ff
Showing
5 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "peachos.h" | ||
|
||
int peachos_getkeyblock() | ||
{ | ||
int val = 0; | ||
do | ||
{ | ||
val = peachos_getkey(); | ||
} | ||
while(val == 0); | ||
return val; | ||
} | ||
|
||
void peachos_terminal_readline(char* out, int max, bool output_while_typing) | ||
{ | ||
int i = 0; | ||
for (i = 0; i < max -1; i++) | ||
{ | ||
char key = peachos_getkeyblock(); | ||
|
||
// Carriage return means we have read the line | ||
if (key == 13) | ||
{ | ||
break; | ||
} | ||
|
||
if (output_while_typing) | ||
{ | ||
peachos_putchar(key); | ||
} | ||
|
||
// Backspace | ||
if (key == 0x08 && i >= 1) | ||
{ | ||
out[i-1] = 0x00; | ||
// -2 because we will +1 when we go to the continue | ||
i -= 2; | ||
continue; | ||
} | ||
|
||
out[i] = key; | ||
} | ||
|
||
// Add the null terminator | ||
out[i] = 0x00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
#ifndef PEACHOS_H | ||
#define PEACHOS_H | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
|
||
void print(const char* filename); | ||
int getkey(); | ||
int peachos_getkey(); | ||
|
||
void* peachos_malloc(size_t size); | ||
void peachos_free(void* ptr); | ||
void peachos_putchar(char c); | ||
int peachos_getkeyblock(); | ||
void peachos_terminal_readline(char* out, int max, bool output_while_typing); | ||
|
||
|
||
#endif |