forked from GrassLab/osc2021
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from ianchen-tw/refactor-shell
Refactor shell
- Loading branch information
Showing
10 changed files
with
290 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
#pragma once | ||
|
||
#include "cfg.h" | ||
|
||
struct InputBuffer { | ||
char *data; | ||
int mx_size; | ||
int write_head; | ||
int cur_input_size; | ||
|
||
void (*pop)(struct InputBuffer *self); | ||
void (*push)(struct InputBuffer *self, char c); | ||
void (*cursor_mov_left)(struct InputBuffer *self); | ||
void (*cursor_mov_right)(struct InputBuffer *self); | ||
void (*clear)(struct InputBuffer *self); | ||
}; | ||
void bfr_init(struct InputBuffer *bfr, char *data, int mx_size); | ||
void bfr_pop(struct InputBuffer *bfr); | ||
void bfr_push(struct InputBuffer *bfr, char c); | ||
void bfr_cursor_mov_left(struct InputBuffer *bfr); | ||
void bfr_cursor_mov_right(struct InputBuffer *bfr); | ||
void bfr_clear(struct InputBuffer *bfr); | ||
|
||
void InputBuffer_init(struct InputBuffer *bfr, char *data, int mx_size); | ||
|
||
// Only used for running tests | ||
void test_shell_buffer(); |
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,12 @@ | ||
#pragma once | ||
|
||
typedef struct { | ||
char *name; | ||
char *help; | ||
void (*func)(void); | ||
} Cmd; | ||
|
||
Cmd *getCmd(char *name); | ||
|
||
// Only used for running tests | ||
void test_shell_cmd(); |
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,26 +1,15 @@ | ||
#pragma once | ||
|
||
#define MX_CMD_BFRSIZE 64 | ||
#include "buffer.h" | ||
#include <stdint.h> | ||
|
||
typedef enum AnsiEscType { | ||
Unknown, | ||
CursorForward, | ||
CursorBackward, | ||
} AnsiEscType; | ||
|
||
enum KeyboardInput { | ||
KI_BackSpace = '\b', // 8 | ||
KI_LineFeed = '\n', // 10 | ||
KI_CarrageReturn = '\r', // 13 | ||
KI_Esc = '\e', // 27 | ||
KI_ANSI_ESCAPE_SEQ_START = '\e', // 27 | ||
|
||
KI_PRINTABLE_START = 32, | ||
KI_PRINTABLE_END = 126, | ||
KI_Delete = 127, | ||
struct Shell { | ||
char *data; | ||
uint32_t bfr_size; | ||
struct InputBuffer bfr; | ||
}; | ||
|
||
void shellPrintPrompt(); | ||
void shellInputLine(); | ||
void shellProcessCommand(); | ||
void shellInit(); | ||
void shell_show_prompt(struct Shell *sh); | ||
void shell_input_line(struct Shell *sh); | ||
void shell_process_command(struct Shell *sh); | ||
void shell_init(struct Shell *sh, char *data, uint32_t size); |
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
Oops, something went wrong.