Add buffer listing function.

This commit is contained in:
2026-09-03 14:40:11 +01:00
parent 46bdb8cd0f
commit 3bfebe30ce
4 changed files with 133 additions and 6 deletions
+1
View File
@@ -9,6 +9,7 @@ struct Token {
uint32_t end;
enum Kind : uint8_t {
TempCurrent,
BufferName,
AddressSeperator,
Address,
Offset,
+33
View File
@@ -118,6 +118,39 @@ void Function::register_extented(BEd &ctx) {
},
}
);
ctx.functions.insert(
"b",
Function{
.address_kind = Function::AddressKind::None,
.argument_kind = Function::ArgumentKind::None,
.input_mode = Function::InputMode::None,
.desc = "List active buffers",
.default_address = "",
.accept_zero = false,
.pre_text_mode = nullptr,
.handle = [](
BEd &ctx,
const buffer::Address &addr_,
vase::Shard *,
const Argument &,
std::vector<buffer::Line> *
) {
auto &current = std::get<std::string>(addr_);
bool current_real = false;
for (auto &[name, _] : ctx.buffers) {
if (current == name) {
ctx.io.write("* ");
current_real = true;
} else {
ctx.io.write(" ");
}
ctx.io.write_line(name);
}
if (!current_real)
ctx.io.write_line("* " + current);
},
}
);
ctx.functions.insert(
"#",
Function{
+13 -4
View File
@@ -745,10 +745,19 @@ void Function::register_posix(BEd &ctx) {
std::vector<buffer::Line> *
) {
auto &addr = std::get<buffer::Range>(addr_);
if (addr.start == addr.end)
ctx.io.write_line(std::format(":{}:{}", addr.buffername, addr.start));
else
ctx.io.write_line(std::format(":{}:{},{}", addr.buffername, addr.start, addr.end));
ctx.io.apply(io::Token::BufferName);
ctx.io.write(":" + addr.buffername + ":");
ctx.io.apply(io::Token::Number);
if (addr.start == addr.end) {
ctx.io.write_line(std::format(" {}", addr.start));
} else {
ctx.io.write(std::format(" {}", addr.start));
ctx.io.apply(io::Token::AddressSeperator);
ctx.io.write(",");
ctx.io.apply(io::Token::Number);
ctx.io.write_line(std::format("{}", addr.end));
}
ctx.io.reset();
ctx.prev().buffername = addr.buffername;
ctx.prev().start = addr.start;
ctx.prev().end = addr.end;
+86 -2
View File
@@ -15,6 +15,91 @@ io::Highlight Theme::get(const io::Token::Kind &token) const {
Theme Theme::default_theme() {
Theme theme;
theme.hl[io::Token::TempCurrent] = {
.fg = 0x7DCFFF,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::BufferName] = {
.fg = 0xAAD94C,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::AddressSeperator] = {
.fg = 0xFF8F40,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Address] = {
.fg = 0xD2A6FF,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Offset] = {
.fg = 0xEF5168,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::AddressRegex] = {
.fg = 0x7DCFFF,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::AddressSymbol] = {
.fg = 0xAAD94C,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Mark] = {
.fg = 0xFF8F40,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::RubyFunction] = {
.fg = 0xD2A6FF,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::RubyArg] = {
.fg = 0xEF5168,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Any] = {
.fg = 0x7DCFFF,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Shell] = {
.fg = 0xAAD94C,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Ruby] = {
.fg = 0xFF8F40,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::File] = {
.fg = 0xD2A6FF,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Regex] = {
.fg = 0xEF5168,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Replacement] = {
.fg = 0x7DCFFF,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Suffix] = {
.fg = 0xAAD94C,
.bg = 0x000000,
.flags = io::Highlight::None,
};
theme.hl[io::Token::Color1] = {
.fg = 0x7DCFFF,
.bg = 0x000000,
@@ -187,7 +272,6 @@ Theme Theme::default_theme() {
Theme Theme::from_name(std::string_view name) {
if (name == "default")
return default_theme();
throw std::runtime_error("Unknown theme: " + std::string(name));
throw ed_error("Unknown theme: " + std::string(name));
}
} // namespace bed::internal::theme