Ken Van Hoeylandt 79d3dd4fdb
Improvements for apps, filesystems, terminal and shell (#659)
app-module

- Apps now have support for:
  - environment variables (inherit from parent app)
  - current workdir
  - window size (when running in terminal)
- Add type aliases like `AppId` and `PackageId`
- Remove data duplication between ledger and app instance records: create `AppManifestSet`
- `AppManifest` usage safety improved: pass by value where needed, or use `AppId` instead of a manifest.

Terminal and shell

- Moved shell commands into coreutils-module as proper apps.
- Refine stack size for terminal and shell because apps now run with their own task and stack (including in-memory apps)

Platform

- Fix for listing root dir on ESP32: wrap posix directory functions and wire in file systems.
- Moved all platform-specific file system init code to platform subprojects

Other

- Fix for screenshot capture (issue with paths)
- Fixes for coreutils app correctness
- Memory optimizations (use more PSRAM where possible) in various locations such as app-module, shell and terminal.
- `ls` and `help` commands now use terminal width and show columns of data by default
- Created fs helpers at `TactilityKernel/include/tactility/filesystem/fs.h` (partially ported from `ShellFs`)
2026-09-25 08:29:27 +02:00

74 lines
1.8 KiB
C++

#include <coreutils/command_support.h>
#include <app/manifest.h>
#include <cstdio>
namespace {
struct HeadState {
int remaining;
bool atLineStart;
};
bool emitHeadChunk(const char* data, size_t length, void* context) {
auto* state = static_cast<HeadState*>(context);
for (size_t i = 0; i < length; i++) {
if (state->remaining <= 0) {
return false;
}
const char c = data[i];
if (c == '\n') {
printf("\n");
state->remaining--;
state->atLineStart = true;
} else {
const char text[2] = { (c == '\t' || (static_cast<unsigned char>(c) >= 0x20 && static_cast<unsigned char>(c) < 0x7F)) ? c : '.', '\0' };
printf("%s", text);
state->atLineStart = false;
}
}
return state->remaining > 0;
}
} // namespace
namespace coreutils::head {
static int32_t main(int argc, char* argv[]) {
int count = 10;
const int first = parseLineCount(argc, argv, &count);
if (first >= argc) {
printf("usage: head [-n N] <file>\n");
return 1;
}
char path[FILE_MAX_PATH_STRING_LENGTH];
if (!resolvePathArg("head", argv[first], path, sizeof(path))) {
return 1;
}
HeadState state { count, true };
if (!streamFile(path, &state, emitHeadChunk)) {
printf("head: %s: cannot read\n", argv[first]);
return 1;
}
if (!state.atLineStart) {
printf("\n");
}
return 0;
}
extern const ::AppManifest manifest = {
.id = "head",
.name = "head",
.category = APP_CATEGORY_SYSTEM,
.location = { .type = APP_LOCATION_MEMORY, .location = reinterpret_cast<void*>(main) },
.flags = APP_MANIFEST_FLAG_HIDDEN | APP_MANIFEST_FLAG_HEADLESS,
.stack = { .depth = 4096, .desired_memory_capability = 0 },
};
} // namespace coreutils::head