- updated to-dos

- removed unnecessary debugging code
- moved x86_64-kernel.json to the project root
This commit is contained in:
2025-02-28 03:05:10 +00:00
parent fe18004f7d
commit c8bb85364c
15 changed files with 132 additions and 127 deletions
+76 -15
View File
@@ -44,53 +44,110 @@ impl<'a> Editor {
let (width, height) = writer.font_size().into();
let mut col = Self::PADDING;
let mut line = Self::PADDING;
let mut col = 0;
let mut line = 0;
let mut scale = 1;
for ch in self.buffer.chars() {
if ch == '\n' {
line += scale * height;
col = Self::PADDING;
line += scale;
col = 0;
scale = 1;
continue;
}
if width * scale + col > frame.dimensions().x() {
line += scale * height;
col = Self::PADDING;
if width * (col + 1) > frame.dimensions().x() - 2 * Self::PADDING {
line += scale;
col = 0;
}
writer.render_glyph(&mut frame, Vec2::new(col, line), ch as u8, scale)?;
col += scale * width;
writer.render_glyph(
&mut frame,
Vec2::new(col * width + Self::PADDING, line * height + Self::PADDING),
ch as u8,
scale,
)?;
col += scale;
}
writer.render_glyph(
&mut frame,
Vec2::new(
self.cursor_col * width + Self::PADDING,
self.cursor_line * height + Self::PADDING,
),
b'_',
scale,
);
Ok(frame)
}
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
fn get_lines(&self) -> Vec<&str> {
self.buffer.split('\n').collect::<Vec<&str>>();
todo!()
self.buffer.split('\n').collect::<Vec<&str>>()
}
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
fn move_cursor(&mut self, x: i32, y: i32) {
todo!()
self.cursor_line = self
.cursor_line
.checked_add_signed(y as isize)
.unwrap_or(self.cursor_line);
self.cursor_col = self
.cursor_col
.checked_add_signed(x as isize)
.unwrap_or(self.cursor_col);
}
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
fn delete_char(&mut self) {
todo!()
let i = self.get_char_idx();
self.buffer.remove(i);
}
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
fn insert_char(&mut self, c: char) {
todo!()
let i = self.get_char_idx();
self.buffer.insert(i, c);
}
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
fn splitline(&mut self) {
todo!()
let i = self.get_char_idx();
self.buffer.insert(i, '\n');
}
fn get_char_idx(&self) -> usize {
let frame = Frame::new(&self.window);
let writer = Writer::new(Font::default());
let (width, _height) = writer.font_size().into();
let mut col = 0;
let mut line = 0;
let mut scale = 1;
for (i, ch) in self.buffer.chars().enumerate() {
if ch == '\n' {
line += scale;
col = 0;
scale = 1;
continue;
}
if width * (col + 1) > frame.dimensions().x() - 2 * Self::PADDING {
line += scale;
col = 0;
}
if col == self.cursor_col && line == self.cursor_line {
return i;
}
col += scale;
}
0
}
}
@@ -139,15 +196,19 @@ impl Application for Editor {
}
}
KeyStroke::Left => {
serial_println!("Left\n");
self.move_cursor(-1, 0);
}
KeyStroke::Right => {
serial_println!("Right\n");
self.move_cursor(1, 0);
}
KeyStroke::Up => {
serial_println!("Up\n");
self.move_cursor(0, -1);
}
KeyStroke::Down => {
serial_println!("Down\n");
self.move_cursor(0, 1);
}
KeyStroke::None => {}