summaryrefslogtreecommitdiff
path: root/gnu_history.c
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2025-02-05 22:37:27 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2025-02-05 22:37:27 +0100
commita03bda11909b066095f734c01988d2c0d75c261f (patch)
treebe1cdde04e208eb2ffc2255ea6be29935ac40d15 /gnu_history.c
parentdb36212d04156f775e7065c59ed69cd65a54b075 (diff)
switching away from using readline after realizing it was making things a little to easy, wouldnt give me the fullfilling feeling im looking for...
Diffstat (limited to 'gnu_history.c')
-rw-r--r--gnu_history.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/gnu_history.c b/gnu_history.c
new file mode 100644
index 0000000..9a9b794
--- /dev/null
+++ b/gnu_history.c
@@ -0,0 +1,43 @@
+/*
+ * =====================================================================================
+ *
+ * Filename: gnu_history.c
+ *
+ * Description: testing GNU HISTORY AND GNU READLINE
+ *
+ * Version: 1.0
+ * Created: 02/05/2025 19:31:12
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: YOUR NAME (),
+ * Organization:
+ *
+ * =====================================================================================
+ */
+#include <stdio.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <stdlib.h>
+
+int main() {
+ char *input;
+
+ using_history(); // Initialize history
+
+ while (1) {
+ input = readline("shell> "); // Read user input
+
+ if (!input) break; // Handle Ctrl+D (EOF)
+
+ if (*input) { // If input is not empty
+ add_history(input); // Save input to history
+ }
+
+ printf("You typed: %s\n", input);
+
+ free(input); // readline() allocates memory, so free it
+ }
+
+ return 0;
+}