Setup routing.

This commit is contained in:
2026-08-07 14:21:44 +01:00
parent fdb67b449d
commit 717c048d6f
7 changed files with 74 additions and 22 deletions
+13
View File
@@ -3,7 +3,20 @@
#include "pch.h"
namespace crib::cli {
struct Command {
void (*run)(std::vector<std::string>);
std::string (*summary)();
void (*help)();
};
struct cli_error : std::runtime_error {
int exit_code;
cli_error(std::string msg, int code)
: std::runtime_error(std::move(msg)), exit_code(code) {}
};
extern bool use_colors;
void help();
int execute(const std::string &name, const Command &cmd, int argc, char *argv[]);
int run(int argc, char *argv[]);
} // namespace crib::cli
+1 -1
View File
@@ -6,5 +6,5 @@
namespace crib::commands::ed {
std::string summary();
void help();
void run(int argc, char *argv[]);
void run(std::vector<std::string>);
} // namespace crib::commands::ed
+52
View File
@@ -19,4 +19,56 @@ struct LineIterator {
bool next(std::string *line);
uint64_t byte_offset();
};
struct Iterator {
Shard *root;
std::string line;
Iterator(Shard *root, uint64_t line_num)
: root(root), it(root, line_num, Direction::Forward) {
Shard::retain(root);
}
~Iterator() {
Shard::release(root);
}
Iterator(const Iterator &other)
: root(other.root), it(other.it) {
Shard::retain(root);
}
Iterator &operator=(const Iterator &other) {
if (this != &other) {
Shard::retain(other.root);
Shard::release(root);
root = other.root;
it = other.it;
}
return *this;
}
Iterator(Iterator &&other) noexcept
: root(other.root), it(std::move(other.it)) {
other.root = nullptr;
}
Iterator &operator=(Iterator &&other) noexcept {
if (this != &other) {
Shard::release(root);
root = other.root;
it = std::move(other.it);
other.root = nullptr;
}
return *this;
}
std::string &next() {
it.next(&line);
return line;
}
private:
LineIterator it;
};
} // namespace crib::internal::vase
+1 -3
View File
@@ -53,9 +53,7 @@ struct Vase {
std::string to_string();
std::string to_string(Range range);
Point resolve_column(uint64_t line, uint64_t column);
LineIterator iterate(uint64_t line);
Iterator iterate(uint64_t line);
void insert(Point *point, char key);
void insert(Point *point, const char *data, uint64_t len);