Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non-printable characters in vga buffer module #425

Merged
merged 1 commit into from
Apr 7, 2018

Conversation

phil-opp
Copy link
Owner

@phil-opp phil-opp commented Apr 2, 2018

Suggested by @fpsiorz in #405 (comment).

I decided to modify write_string instead of write_byte, because it allows us to still print the additional bytes of codepage 437 via write_byte (e.g. a for non-ASCII characters).

A better solution would be to translate UTF-8 to codepage 437 where possible, but I think that would be too much code for the blog. Maybe we could do it via an external crate.

@phil-opp phil-opp merged commit 6d0f103 into master Apr 7, 2018
@bors bors bot deleted the vga-byte-printing branch April 7, 2018 17:45
@@ -203,12 +203,23 @@ To print whole strings, we can convert them to bytes and print them one-by-one:
impl Writer {
pub fn write_string(&mut self, s: &str) {
for byte in s.bytes() {
self.write_byte(byte)
match byte {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a match we could use an if condition:

if byte.is_ascii() {
    self.write_byte(byte);
} else {
    self.write_byte(0xfe);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also includes non-printable ASCII bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants