Skip to content

Commit 8b54a17

Browse files
remove everything but the progress bar and menu
1 parent a66482e commit 8b54a17

File tree

2 files changed

+16
-125
lines changed

2 files changed

+16
-125
lines changed

code/logic/fossil/io/input.h

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,6 @@ int fossil_io_validate_is_length(const char *input, size_t max_length);
136136
*/
137137
int fossil_io_validate_sanitize_string(const char *input, char *output, size_t output_size);
138138

139-
/**
140-
* @brief Reads a secure line of input into the provided buffer.
141-
*
142-
* @param buffer The buffer where the input will be stored.
143-
* @param buffer_size The size of the buffer.
144-
* @return A fossil_io_validate_error_t indicating the result of the input reading process.
145-
*/
146-
int fossil_io_validate_read_secure_line(char *buffer, size_t buffer_size);
147-
148139
/**
149140
* Displays a menu of choices and returns the selected choice.
150141
*
@@ -155,31 +146,6 @@ int fossil_io_validate_read_secure_line(char *buffer, size_t buffer_size);
155146
*/
156147
int fossil_io_display_menu(const char *prompt, const char *choices[], int num_choices);
157148

158-
/**
159-
* Reads a password from the user with masked input (e.g., asterisks).
160-
*
161-
* @param buffer The buffer to store the password.
162-
* @param size The maximum size of the buffer.
163-
* @return 1 if password was successfully read, 0 otherwise.
164-
*/
165-
int fossil_io_read_password(char *buffer, size_t size);
166-
167-
/**
168-
* Reads multiline input from the user, allowing the user to press Enter to add new lines.
169-
*
170-
* @param buffer The buffer to store the input.
171-
* @param size The maximum size of the buffer.
172-
* @return 1 if the input was successfully received, 0 otherwise.
173-
*/
174-
int fossil_io_read_multiline_input(char *buffer, size_t size);
175-
176-
/**
177-
* Reads a single character from the user without echoing to the screen.
178-
*
179-
* @return The character entered by the user.
180-
*/
181-
char fossil_io_getch(void);
182-
183149
/**
184150
* Displays a simple progress bar.
185151
*
@@ -352,14 +318,24 @@ namespace fossil {
352318
}
353319

354320
/**
355-
* @brief Reads a secure line of input into the provided buffer.
321+
* @brief Displays a menu of choices and returns the selected choice.
322+
*
323+
* @param prompt The prompt message before displaying the menu.
324+
* @param choices Array of strings representing the choices.
325+
* @param num_choices The number of choices.
326+
* @return The index of the selected choice.
327+
*/
328+
static int display_menu(const char *prompt, const char *choices[], int num_choices) {
329+
return fossil_io_display_menu(prompt, choices, num_choices);
330+
}
331+
332+
/**
333+
* @brief Displays a simple progress bar.
356334
*
357-
* @param buffer The buffer where the input will be stored.
358-
* @param buffer_size The size of the buffer.
359-
* @return A fossil_io_validate_error_t indicating the result of the input reading process.
335+
* @param progress The current progress (0-100).
360336
*/
361-
static int validate_read_secure_line(char *buffer, size_t buffer_size) {
362-
return fossil_io_validate_read_secure_line(buffer, buffer_size);
337+
static void show_progress(int progress) {
338+
fossil_io_show_progress(progress);
363339
}
364340

365341
/**

code/logic/input.c

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -51,49 +51,6 @@ void fossil_io_trim(char *str) {
5151
}
5252
}
5353

54-
char fossil_io_getch(void) {
55-
#ifdef _WIN32
56-
return _getch(); // Windows version
57-
#else
58-
struct termios oldt, newt;
59-
char ch;
60-
tcgetattr(STDIN_FILENO, &oldt); // Save current terminal settings
61-
newt = oldt;
62-
newt.c_lflag &= ~(ICANON | ECHO); // Disable canonical mode and echo
63-
tcsetattr(STDIN_FILENO, TCSANOW, &newt); // Apply the new settings
64-
ch = getchar(); // Read the character
65-
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // Restore the original settings
66-
return ch;
67-
#endif
68-
}
69-
70-
int fossil_io_read_password(char *buffer, size_t size) {
71-
if (buffer == NULL || size == 0) {
72-
return 0;
73-
}
74-
75-
size_t index = 0;
76-
char ch;
77-
while (index < size - 1) {
78-
ch = fossil_io_getch(); // Get a single character without echo
79-
if (ch == '\n' || ch == '\r') {
80-
break;
81-
}
82-
if (ch == 127 || ch == 8) { // Handle backspace
83-
if (index > 0) {
84-
index--;
85-
printf("\b \b");
86-
}
87-
} else {
88-
buffer[index++] = ch;
89-
printf("*"); // Mask the input
90-
}
91-
}
92-
buffer[index] = '\0';
93-
printf("\n"); // Move to the next line
94-
return 1;
95-
}
96-
9754
int fossil_io_display_menu(const char *prompt, const char *choices[], int num_choices) {
9855
if (prompt != NULL) {
9956
printf("%s\n", prompt);
@@ -114,29 +71,6 @@ int fossil_io_display_menu(const char *prompt, const char *choices[], int num_ch
11471
return choice - 1; // Return the index of the chosen option
11572
}
11673

117-
int fossil_io_read_multiline_input(char *buffer, size_t size) {
118-
if (buffer == NULL || size == 0) {
119-
return 0;
120-
}
121-
122-
size_t index = 0;
123-
char ch;
124-
printf("Enter multiple lines of text (Press Enter twice to finish):\n");
125-
126-
while (index < size - 1) {
127-
ch = fossil_io_getch(); // Get a single character
128-
if (ch == '\n') {
129-
if (index > 0 && buffer[index - 1] == '\n') {
130-
break; // Two Enter presses to finish
131-
}
132-
}
133-
buffer[index++] = ch;
134-
printf("%c", ch);
135-
}
136-
buffer[index] = '\0'; // Null-terminate the string
137-
return 1;
138-
}
139-
14074
void fossil_io_show_progress(int progress) {
14175
int width = 50; // Width of the progress bar
14276
int pos = (progress * width) / 100;
@@ -346,22 +280,3 @@ int fossil_io_validate_sanitize_string(const char *input, char *output, size_t o
346280

347281
return 1;
348282
}
349-
350-
int fossil_io_validate_read_secure_line(char *buffer, size_t buffer_size) {
351-
if (buffer == NULL || buffer_size == 0) {
352-
return 0;
353-
}
354-
355-
// Read a line of input from the user
356-
if (fgets(buffer, buffer_size, stdin) == NULL) {
357-
return 0;
358-
}
359-
360-
// Remove the newline character from the input
361-
size_t len = strlen(buffer);
362-
if (len > 0 && buffer[len - 1] == '\n') {
363-
buffer[len - 1] = '\0';
364-
}
365-
366-
return 1;
367-
}

0 commit comments

Comments
 (0)