diff --git a/.gitignore b/.gitignore index 6c24c44..4d59550 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ zed +*.dSYM/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc1af64 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This is me coding along with Mr. [Tsoding](https://www.twitch.tv/tsoding)'s stream about creating a text editor from scratch using C. diff --git a/build.sh b/build.sh index cd87d44..52876d5 100755 --- a/build.sh +++ b/build.sh @@ -2,4 +2,4 @@ set -xe -clang -Wall -Wextra -o zed main.c +clang -Wall -Wextra -ggdb -o zed main.c diff --git a/main.c b/main.c index 78984b7..a5c8f3d 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,10 @@ #include #include +#include + +#include + #define ZED_CAPACITY 1024 typedef struct { @@ -13,12 +17,24 @@ static Editor editor = {0}; int main(int argc, char **argv) { + if (!isatty(0)) { + fprintf(stderr, "Please run in the terminal!\n"); + return 1; + } + if (argc < 2) { fprintf(stderr, "Usage: zed \n"); fprintf(stderr, "ERROR: no input file was provided\n"); return 1; } + // stores the state of the terminal + struct termios term; + if (tcgetattr(0, &term)) { + fprintf(stderr, "ERROR: could not save the state of the terminal\n"); + return 1; + } + const char *file_path = argv[1]; FILE *f = fopen(file_path, "rb"); if (f == NULL) {