wasm Error : JavaScript execution returned a result of an unsupported type
- Dominant language
- Perl
- Stars
- 3.9k
- Forks
- 213
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
I have tried to compile various TUI file managers into WebAssembly, but all my attempts have failed. Subsequently, I decided to develop a new file manager myself, with assistance from ChatGPT, as I am not actually a programmer.
My development is still in its very early stages. I am frustrated to learn that the termios library is not compatible with WebAssembly. Additionally, I am wondering why my compiled file manager is occasionally terminated with the following error:
wasm Error: JavaScript execution returned a result of an unsupported type
Please find below the source code of my development so far:
#include
#include
#include
#include
#include
#include
#define MAX_PATH 1024
#define MAX_ENTRIES 1024
struct entry {
char name[MAX_PATH];
int is_dir;
int selected;
};
struct entry entries[MAX_ENTRIES];
int num_entries = 0;
int current_pos = 0;
int selected_count = 0;
void get_entries(char *path) {
DIR *dir = opendir(path);
struct dirent *entry;
num_entries = 0;
if (dir == NULL) {
perror("opendir");
return;
}
while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] != '.') {
strcpy(entries[num_entries].name, entry->d_name);
entries[num_entries].is_dir = entry->d_type == DT_DIR;
entries[num_entries].selected = 0;
num_entries++;
}
}
closedir(dir);
}
void draw() {
printf("\033[H\033[J"); // Clear screen
printf("Current directory: %s\n\n", getcwd(NULL, 0));
for (int i = 0; i < num_entries; i++) {
if (i == current_pos) {
printf("\033[7m"); // Inverse video
}
if (entries[i].selected) {
printf("* "); // Represent selected files/directories with *
} else {
printf(" ");
}
printf("%c %s\n", entries[i].is_dir ? '/' : ' ', entries[i].name);
if (i == current_pos) {
printf("\033[0m"); // Reset attributes
}
}
}
void select_all() {
for (int i = 0; i < num_entries; i++) {
entries[i].selected = 1;
}
selected_count = num_entries;
}
void invert_selection() {
for (int i = 0; i < num_entries; i++) {
entries[i].selected = !entries[i].selected;
}
selected_count = num_entries - selected_count;
}
void clear_selections() {
for (int i = 0; i < num_entries; i++) {
entries[i].selected = 0;
}
selected_count = 0;
}
int main() {
char cwd[MAX_PATH];
getcwd(cwd, sizeof(cwd));
get_entries(cwd);
draw();
while (1) {
char c = getchar();
switch (c) {
case 'k':
current_pos = (current_pos - 1 + num_entries) % num_entries;
break;
case 'j':
current_pos = (current_pos + 1) % num_entries;
break;
case 'h':
chdir("..");
getcwd(cwd, sizeof(cwd));
get_entries(cwd);
break;
case 'l':
if (entries[current_pos].is_dir) {
chdir(entries[current_pos].name);
getcwd(cwd, sizeof(cwd));
get_entries(cwd);
current_pos = 0;
}
break;
case 'g':
current_pos = 0;
break;
case 'G':
current_pos = num_entries - 1;
break;
case 'q':
exit(0);
case ' ':
entries[current_pos].selected = !entries[current_pos].selected;
selected_count += entries[current_pos].selected ? 1 : -1;
// Set the item one below the current hovering item as the new hovering item
current_pos = (current_pos + 1) % num_entries;
break;
case 'a':
select_all();
break;
case 'A':
invert_selection();
break;
case 'x':
if (selected_count == 0) {
char path[MAX_PATH];
snprintf(path, sizeof(path), "%s/%s", cwd, entries[current_pos].name);
if (entries[current_pos].is_dir) {
rmdir(path);
} else {
remove(path);
}
} else {
for (int i = 0; i < num_entries; i++) {
if (entries[i].selected) {
char path[MAX_PATH];
snprintf(path, sizeof(path), "%s/%s", cwd, entries[i].name);
if (entries[i].is_dir) {
rmdir(path);
} else {
remove(path);
}
}
}
}
getcwd(cwd, sizeof(cwd));
get_entries(cwd);
current_pos = 0;
selected_count = 0;
break;
case 'v':
for (int i = 0; i < num_entries; i++) {
if (entries[i].selected) {
char src_path[MAX_PATH];
char dst_path[MAX_PATH];
snprintf(src_path, sizeof(src_path), "%s/%s", cwd, entries[i].name);
snprintf(dst_path, sizeof(dst_path), "%s/%s", cwd, entries[i].name);
rename(src_path, dst_path);
}
}
getcwd(cwd, sizeof(cwd));
get_entries(cwd);
current_pos = 0;
selected_count = 0;
break;
case 'm':
clear_selections();
break;
}
draw();
}
return 0;
}
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.