MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / main

Function main

edit/src/main.rs:331–682  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

329
330#[no_mangle]
331fn main() {
332 let args: Vec<String> = env::args().collect();
333
334 if args.len() != 2 {
335 print!("Usage: {} <file>", args[0]);
336 return;
337 }
338 let file_path = &args[1];
339
340 let mut file = File::open(file_path);
341
342 display(&file);
343 loop {
344 match syscalls::receive(&syscalls::STDIN) {
345 Ok(syscalls::Message::Short(
346 message::CHAR, ch, _)) => {
347 // Received a character
348
349 if ch == 8 {
350 // Backspace
351 if file.cursor.pos == 0 {
352 // Shorten the piece before this
353 if file.cursor.piece == 0 {
354 continue; // no-op
355 }
356 let piece = file.pieces[file.cursor.piece - 1];
357 match piece {
358 Piece::Original{start: start,
359 len: len} => {
360 if len == 1 {
361 // Remove the piece
362 file.pieces.remove(file.cursor.piece - 1);
363 file.cursor.piece -= 1;
364 } else {
365 file.pieces[file.cursor.piece - 1] = Piece::Original{
366 start: start,
367 len: len - 1};
368 }
369 },
370 Piece::Add{start: start,
371 len: len} => {
372 if len == 1 {
373 // Remove the piece
374 file.pieces.remove(file.cursor.piece - 1);
375 file.cursor.piece -= 1;
376 } else {
377 file.pieces[file.cursor.piece - 1] = Piece::Add{
378 start: start,
379 len: len - 1};
380 }
381 },
382 }
383 } else if file.cursor.pos == 1 {
384 // Shorten this piece
385 let piece = file.pieces[file.cursor.piece];
386 match piece {
387 Piece::Original{start: start,
388 len: len} => {

Callers

nothing calls this directly

Calls 13

argsFunction · 0.85
displayFunction · 0.85
receiveFunction · 0.85
removeMethod · 0.80
insertMethod · 0.80
saveMethod · 0.80
rfindMethod · 0.80
atMethod · 0.80
previousMethod · 0.80
openFunction · 0.50
lenMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected