Skip to content

Commit 7aa8605

Browse files
committed
fix: Restored full main.rs and escaped the raw NUL in the ArrowUp handler. By mistake i cutted it off to half due to a editor error.
1 parent 5b99397 commit 7aa8605

1 file changed

Lines changed: 104 additions & 1 deletion

File tree

src/main.rs

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,107 @@ async fn keyboard_task() {
9999
if let Some(ref mut editor) = *ea {
100100
let quit = match key {
101101
DecodedKey::Unicode(c) => editor.handle_char(c),
102-
DecodedKey::RawKey(pc_keyboard::KeyCode::ArrowUp) => { editor.handle_char('
102+
DecodedKey::RawKey(pc_keyboard::KeyCode::ArrowUp) => { editor.handle_char('\0'); false }
103+
_ => false,
104+
};
105+
if quit {
106+
*ea = None;
107+
axiom_os::vga_buffer::clear_screen();
108+
axiom_os::println!("AXIOM OS v0.3.0-alpha");
109+
axiom_os::print!("> ");
110+
}
111+
continue;
112+
}
113+
}
114+
match key {
115+
DecodedKey::Unicode('\n') | DecodedKey::Unicode('\r') => {
116+
axiom_os::println!();
117+
axiom_os::shell::interpret_command(&input_buf);
118+
input_buf.clear();
119+
hist_cursor = 0;
120+
axiom_os::print!("> ");
121+
}
122+
DecodedKey::Unicode('\x08') => {
123+
if !input_buf.is_empty() {
124+
input_buf.pop();
125+
axiom_os::vga_buffer::WRITER.lock().backspace();
126+
}
127+
}
128+
DecodedKey::Unicode('\t') => {
129+
let commands = [
130+
"trust", "verify", "tamper", "cat", "ls", "write", "echo",
131+
"diskwrite", "diskread", "diskls", "diskverify", "disktamper",
132+
"ps", "kill", "spawn", "hash", "bench", "mitra", "run",
133+
"sysinfo", "history", "help", "clear", "info", "axiom",
134+
];
135+
let matches: alloc::vec::Vec<&str> = commands.iter()
136+
.filter(|c| c.starts_with(input_buf.as_str()))
137+
.copied()
138+
.collect();
139+
if matches.len() == 1 {
140+
let completed = matches[0];
141+
for _ in 0..input_buf.len() {
142+
axiom_os::vga_buffer::WRITER.lock().backspace();
143+
}
144+
input_buf = alloc::string::String::from(completed);
145+
axiom_os::print!("{}", completed);
146+
} else if matches.len() > 1 {
147+
axiom_os::println!();
148+
for m in &matches { axiom_os::print!(" {}", m); }
149+
axiom_os::println!();
150+
axiom_os::print!("> {}", input_buf);
151+
}
152+
}
153+
DecodedKey::Unicode(c) => {
154+
input_buf.push(c);
155+
axiom_os::print!("{}", c);
156+
}
157+
DecodedKey::RawKey(pc_keyboard::KeyCode::ArrowUp) => {
158+
let hist = axiom_os::shell::HISTORY.lock();
159+
let len = *axiom_os::shell::HIST_LEN.lock();
160+
let pos = *axiom_os::shell::HIST_POS.lock();
161+
if len == 0 { continue; }
162+
if hist_cursor < len { hist_cursor += 1; }
163+
let idx = (pos + 10 - hist_cursor) % 10;
164+
let entry = hist[idx].clone();
165+
drop(hist);
166+
// Clear current line
167+
for _ in 0..input_buf.len() {
168+
axiom_os::vga_buffer::WRITER.lock().backspace();
169+
}
170+
input_buf = entry.clone();
171+
axiom_os::print!("{}", entry);
172+
}
173+
DecodedKey::RawKey(pc_keyboard::KeyCode::ArrowDown) => {
174+
let hist = axiom_os::shell::HISTORY.lock();
175+
let pos = *axiom_os::shell::HIST_POS.lock();
176+
// Clear current line
177+
for _ in 0..input_buf.len() {
178+
axiom_os::vga_buffer::WRITER.lock().backspace();
179+
}
180+
if hist_cursor > 1 {
181+
hist_cursor -= 1;
182+
let idx = (pos + 10 - hist_cursor) % 10;
183+
let entry = hist[idx].clone();
184+
drop(hist);
185+
input_buf = entry.clone();
186+
axiom_os::print!("{}", entry);
187+
} else {
188+
hist_cursor = 0;
189+
drop(hist);
190+
input_buf.clear();
191+
}
192+
}
193+
194+
DecodedKey::RawKey(_) => {}
195+
}
196+
}
197+
}
198+
}
199+
}
200+
201+
#[panic_handler]
202+
fn panic(info: &PanicInfo) -> ! {
203+
println!("{}", info);
204+
loop {}
205+
}

0 commit comments

Comments
 (0)