Skip to content

Commit

Permalink
karm-io: Handle any string encoding in Fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Apr 10, 2024
1 parent 5134f01 commit 1e64936
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 86 deletions.
5 changes: 3 additions & 2 deletions src/impls/impl-efi/sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ Res<Strong<Sys::Fd>> openFile(Mime::Url const &url) {
}

Efi::FileProtocol *file = nullptr;
auto resolved = try$(resolve(url));
auto resolved = try$(resolve(url)).str();

_StringBuilder<Utf16> b;
b.ensure(resolved.len());

// NOTE: Convert '/' to '\' as EFI uses '\' as path separator
for (auto &u : iterRunes(resolved.str())) {
for (Rune u : iterRunes(resolved)) {
if (u == '/') {
u = '\\';
}
Expand Down
4 changes: 3 additions & 1 deletion src/kernel/hjert-core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ void Object::label(Str label) {
}

String Object::label() const {
return _label ? *_label : "<no label>";
if (not _label)
return "<unlabeled>"s;
return *_label;
}

void Object::_signalUnlock(Flags<Hj::Sigs> set, Flags<Hj::Sigs> unset) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/karm-base/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ struct _StringBuilder {
}

_String<E> take() {
usize len = _buf.size();
usize len = _buf.len();
_buf.insert(len, 0);
return {MOVE, _buf.take(), len};
}
Expand Down
14 changes: 7 additions & 7 deletions src/libs/karm-cli/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct Karm::Io::Formatter<Karm::Cli::Style> {
usize written = 0;

if (style._reset) {
written += try$(writer.writeStr("\x1b[0m"));
written += try$(writer.writeStr("\x1b[0m"s));
}

if (style._fg != Karm::Cli::_COLOR_UNDEF) {
Expand All @@ -153,23 +153,23 @@ struct Karm::Io::Formatter<Karm::Cli::Style> {
}

if (style._bold) {
written += try$(writer.writeStr("\x1b[1m"));
written += try$(writer.writeStr("\x1b[1m"s));
}

if (style._underline) {
written += try$(writer.writeStr("\x1b[4m"));
written += try$(writer.writeStr("\x1b[4m"s));
}

if (style._blink) {
written += try$(writer.writeStr("\x1b[5m"));
written += try$(writer.writeStr("\x1b[5m"s));
}

if (style._reverse) {
written += try$(writer.writeStr("\x1b[7m"));
written += try$(writer.writeStr("\x1b[7m"s));
}

if (style._invisible) {
written += try$(writer.writeStr("\x1b[8m"));
written += try$(writer.writeStr("\x1b[8m"s));
}

return Ok(written);
Expand Down Expand Up @@ -199,7 +199,7 @@ struct Karm::Io::Formatter<Karm::Cli::Styled<T>> {
return Ok(
try$(_styleFmt.format(writer, val._color)) +
try$(_innerFmt.format(writer, val._inner)) +
try$(writer.writeStr("\x1b[0m"))
try$(writer.writeStr("\x1b[0m"s))
);
#else
return _innerFmt.format(writer, val._inner);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/karm-io/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct Emit : public Io::TextWriterBase<> {
usize written = try$(_writer.writeRune('\n'));
_newline = false;
for (usize i = 0; i < _ident; i++)
written += try$(_writer.writeStr(" "));
written += try$(_writer.writeStr(" "s));
return Ok(written);
}

Expand Down
Loading

0 comments on commit 1e64936

Please sign in to comment.