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

Add 'less' Text Pagination Functionality to Dynamically View Parts of Large Text #1115

Open
wants to merge 56 commits into
base: theseus_main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
aef3885
Initial attempt to read file into string
Sep 20, 2024
9f597e2
remove errors to read file into initial string
nnh12 Nov 5, 2024
b1bcaa4
write content file when 'less' is called
nnh12 Nov 6, 2024
c22a389
add print string contents to verify existing functionality
nnh12 Nov 8, 2024
abe76e2
Add terminal size to determine line splice
nnh12 Nov 8, 2024
98a43a3
Save recent progress to use correct terminal size
nnh12 Nov 9, 2024
727c1fa
Add correct instance of Terminal for dimension
nnh12 Nov 10, 2024
583d574
Remove window and text display import
nnh12 Nov 10, 2024
da8fdf8
Delete extra 'Terminal' instance
nnh12 Nov 10, 2024
6b871ab
Initial implementation of display content function
nnh12 Nov 10, 2024
c2354b2
Event handler implementation
nnh12 Nov 10, 2024
621a857
Add 'shared_map' to grab the terminal instance
nnh12 Nov 11, 2024
993d6c3
use new instance of 'Terminal' to write to display
nnh12 Nov 12, 2024
0b2e906
attempt to add libterm dependency
nnh12 Nov 17, 2024
527ca79
Attempt to display string to terminal
nnh12 Nov 17, 2024
2dbf85d
Get text pagination to project file onto terminal
nnh12 Nov 19, 2024
443e782
Remove prompt instruction after entering 'less' editing mode
nnh12 Nov 20, 2024
48724c9
Add missing text pagination to Missing filename ("less --help" for help)
nnh12 Nov 22, 2024
f10c4d1
Test 'Tab' command working
nnh12 Nov 22, 2024
8b7049d
Prelimary key word short cut to Quit
nnh12 Nov 23, 2024
1fd2b54
Fix clippy error messages with string format error
nnh12 Nov 25, 2024
286ace5
Convert 'str' to String
nnh12 Nov 25, 2024
26bf332
Handle none case with warning
nnh12 Nov 25, 2024
7661174
Keycode 'Q' to leave out of text
nnh12 Nov 25, 2024
bebf802
Remove LineSlice struct for now
nnh12 Nov 25, 2024
1230e77
Remove 'Terminal' instantiation
nnh12 Nov 25, 2024
b69d78e
Restart fresh terminal instance upon quiting
nnh12 Nov 26, 2024
b19dc2d
Migrate less functionality to 'shell'
nnh12 Nov 28, 2024
0c00a64
Displayable text added
nnh12 Nov 28, 2024
eeae44d
test file for large file
nnh12 Nov 28, 2024
d309149
Grab the line slices within a text file
nnh12 Nov 28, 2024
e9c64be
Grab the sliced string against dimension and display
nnh12 Nov 28, 2024
05fd274
Handle keyboard hits for navigation
nnh12 Nov 29, 2024
6d70adf
Quit 'less' upon 'Q' keyboard
nnh12 Nov 29, 2024
351cbf8
remove 's1' clone for testing
nnh12 Dec 3, 2024
4c3b55c
Move away from Terminal reference
nnh12 Dec 3, 2024
b137731
access map instance for line access
nnh12 Dec 4, 2024
87a2e1c
Remove previous less command and replace with shell implementation
nnh12 Dec 4, 2024
3149653
Fix 'Q' option to allow user to enter 'q' letter
nnh12 Dec 5, 2024
3910469
Use shell instance of content string to display
nnh12 Dec 5, 2024
71bd2a7
Add 'Up' and 'Down' functionality
nnh12 Dec 5, 2024
345b668
Restore less functionality back to original
nnh12 Dec 5, 2024
ad24748
Revert less application to original again
nnh12 Dec 5, 2024
190c3a4
again
nnh12 Dec 5, 2024
06a2788
revert Cargo changes
nnh12 Dec 5, 2024
2c34fff
fix line issue
nnh12 Dec 5, 2024
075ab3e
Fix unnnecessary changes
nnh12 Dec 5, 2024
52d62c8
fix again
nnh12 Dec 5, 2024
179e743
fix clippy errors
nnh12 Dec 6, 2024
cd6f199
Revert changes to applications/less/src/lib.rs
nnh12 Dec 6, 2024
29e33e2
Update sytling
nnh12 Dec 6, 2024
b11c169
Fix clippy errors again
nnh12 Dec 6, 2024
b8c6b0c
fix clippy errors again
nnh12 Dec 6, 2024
ad9724e
restore get get content string to return result
nnh12 Dec 6, 2024
e7d127f
Fix issue with map initialization
nnh12 Dec 6, 2024
f21345c
Clean up code
nnh12 Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
again
nnh12 committed Dec 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 190c3a44f766bda3ac5649dbb665b1941ebac02e
262 changes: 0 additions & 262 deletions applications/less/src/lib.rs
Original file line number Diff line number Diff line change
@@ -200,268 +200,6 @@ use alloc::{
// }


pub fn main(_args: Vec<String>) -> isize {

// // Get stdout.
// let stdout = match app_io::stdout() {
// Ok(stdout) => stdout,
// Err(e) => {
// error!("{}", e);
// return 1;
// }
// };

// // Set and parse options.
// let mut opts = Options::new();
// opts.optflag("h", "help", "print this help menu");
// let matches = match opts.parse(args) {
// Ok(m) => m,
// Err(e) => {
// error!("{}", e);
// print_usage(opts, stdout);
// return -1;
// }
// };
// if matches.opt_present("h") {
// print_usage(opts, stdout);
// return 0;
// }
// if matches.free.is_empty() {
// print_usage(opts, stdout);
// return 0;
// }
// let filename = matches.free[0].clone();

// if let Err(e) = run(filename) {
// error!("{}", e);
// return 1;
// }
0
}

// fn run(filename: String) -> Result<(), String> {

// // Acquire key event queue.
// let key_event_queue = app_io::take_key_event_queue()?;
// let key_event_queue = (*key_event_queue).as_ref()
// .ok_or("failed to take key event reader")?;

// // Read the whole file to a String.
// let content = get_content_string(filename)?;

// // Get it run.
// let map = parse_content(&content)?;

// Ok(event_handler_loop(&content, &map, key_event_queue)?)
// }

// fn print_usage(opts: Options, stdout: StdioWriter) {
// let _ = stdout.lock().write_all(format!("{}\n", opts.usage(USAGE)).as_bytes());
// }

// const USAGE: &'static str = "Usage: less file
// read files";//! A text file reader which allows the user using `Up` and `Down` to scroll the screen.
#![no_std]

// FIXME

extern crate alloc;
// extern crate task;
// extern crate getopts;
// extern crate path;
// extern crate fs_node;
// extern crate keycodes_ascii;
// extern crate libterm;
// extern crate spin;
// extern crate app_io;
// extern crate stdio;
// extern crate core2;
// #[macro_use] extern crate log;

// use keycodes_ascii::{Keycode, KeyAction};
// use core::str;
use alloc::{
vec::Vec,
string::String,
};
// use getopts::Options;
// use path::Path;
// use fs_node::FileOrDir;
// use alloc::collections::BTreeMap;
// use libterm::Terminal;
// use spin::Mutex;
// use stdio::{StdioWriter, KeyEventQueueReader};
// use core2::io::Write;

// /// The metadata for each line in the file.
// struct LineSlice {
// /// The starting index in the String for a line. (inclusive)
// start: usize,
// /// The ending index in the String for a line. (exclusive)
// end: usize
// }

// /// Read the whole file to a String.
// fn get_content_string(file_path: String) -> Result<String, String> {
// let Ok(curr_wd) = task::with_current_task(|t| t.get_env().lock().working_dir.clone()) else {
// return Err("failed to get current task".to_string());
// };
// let path = Path::new(file_path);

// // navigate to the filepath specified by first argument
// match path.get(&curr_wd) {
// Some(file_dir_enum) => {
// match file_dir_enum {
// FileOrDir::Dir(directory) => {
// Err(format!("{:?} is a directory, cannot 'less' non-files.", directory.lock().get_name()))
// }
// FileOrDir::File(file) => {
// let mut file_locked = file.lock();
// let file_size = file_locked.len();
// let mut string_slice_as_bytes = vec![0; file_size];
// let _num_bytes_read = match file_locked.read_at(&mut string_slice_as_bytes, 0) {
// Ok(num) => num,
// Err(e) => {
// return Err(format!("Failed to read {:?}, error {:?}",
// file_locked.get_name(), e))
// }
// };
// let read_string = match str::from_utf8(&string_slice_as_bytes) {
// Ok(string_slice) => string_slice,
// Err(utf8_err) => {
// return Err(format!("File {:?} was not a printable UTF-8 text file: {}",
// file_locked.get_name(), utf8_err))
// }
// };
// Ok(read_string.to_string())
// }
// }
// },
// _ => {
// Err(format!("Couldn't find file at path {}", path))
// }
// }
// }

// /// This function parses the text file. It scans through the whole file and records the string slice
// /// for each line. This function has full UTF-8 support, which means that the case where a single character
// /// occupies multiple bytes are well considered. The slice index returned by this function is guaranteed
// /// not to cause panic.
// fn parse_content(content: &String) -> Result<BTreeMap<usize, LineSlice>, &'static str> {
// // Get the width and height of the terminal screen.
// let (width, _height) = app_io::get_my_terminal().ok_or("couldn't get terminal for `less` app")?
// .lock()
// .get_text_dimensions();

// // Record the slice index of each line.
// let mut map: BTreeMap<usize, LineSlice> = BTreeMap::new();
// // Number of the current line.
// let mut cur_line_num: usize = 0;
// // Number of characters in the current line.
// let mut char_num_in_line: usize = 0;
// // Starting index in the String of the current line.
// let mut line_start_idx: usize = 0;
// // The previous character during the iteration. Set '\0' as the initial value since we don't expect
// // to encounter this character in the beginning of the file.
// let mut previous_char: char = '\0';

// // Iterate through the whole file.
// // `c` is the current character. `str_idx` is the index of the first byte of the current character.
// for (str_idx, c) in content.char_indices() {
// // When we need to begin a new line, record the previous line in the map.
// if char_num_in_line == width || previous_char == '\n' {
// map.insert(cur_line_num, LineSlice{ start: line_start_idx, end: str_idx });
// char_num_in_line = 0;
// line_start_idx = str_idx;
// cur_line_num += 1;
// }
// char_num_in_line += 1;
// previous_char = c;
// }
// map.insert(cur_line_num, LineSlice{ start: line_start_idx, end: content.len() });

// Ok(map)
// }

// /// Display part of the file (may be whole file if the file is short) to the terminal, starting
// /// at line number `line_start`.
// fn display_content(content: &String, map: &BTreeMap<usize, LineSlice>,
// line_start: usize, terminal: &Arc<Mutex<Terminal>>)
// -> Result<(), &'static str> {
// // Get exclusive control of the terminal. It is locked through the whole function to
// // avoid the overhead of locking it multiple times.
// let mut locked_terminal = terminal.lock();

// // Calculate the last line to display. Make sure we don't extend over the end of the file.
// let (_width, height) = locked_terminal.get_text_dimensions();
// let mut line_end: usize = line_start + height;
// if line_end > map.len() {
// line_end = map.len();
// }

// // Refresh the terminal with the lines we've selected.
// let start_indices = match map.get(&line_start) {
// Some(indices) => indices,
// None => return Err("failed to get the byte indices of the first line")
// };
// let end_indices = match map.get(&(line_end - 1)) {
// Some(indices) => indices,
// None => return Err("failed to get the byte indices of the last line")
// };
// locked_terminal.clear();
// locked_terminal.print_to_terminal(
// content[start_indices.start..end_indices.end].to_string()
// );
// locked_terminal.refresh_display()
// }

// /// Handle user keyboard strikes and perform corresponding operations.
// fn event_handler_loop(content: &String, map: &BTreeMap<usize, LineSlice>,
// key_event_queue: &KeyEventQueueReader)
// -> Result<(), &'static str> {

// // Get a reference to this task's terminal. The terminal is *not* locked here.
// let terminal = app_io::get_my_terminal().ok_or("couldn't get terminal for `less` app")?;

// // Display the beginning of the file.
// let mut line_start: usize = 0;
// display_content(content, map, 0, &terminal)?;

// // Handle user keyboard strikes.
// loop {
// match key_event_queue.read_one() {
// Some(keyevent) => {
// if keyevent.action != KeyAction::Pressed { continue; }
// match keyevent.keycode {
// // Quit the program on "Q".
// Keycode::Q => {
// let mut locked_terminal = terminal.lock();
// locked_terminal.clear();
// return locked_terminal.refresh_display()
// },
// // Scroll down a line on "Down".
// Keycode::Down => {
// if line_start + 1 < map.len() {
// line_start += 1;
// }
// display_content(content, map, line_start, &terminal)?;
// },
// // Scroll up a line on "Up".
// Keycode::Up => {
// if line_start > 0 {
// line_start -= 1;
// }
// display_content(content, map, line_start, &terminal)?;
// }
// _ => {}
// }
// },
// _ => {}
// }
// }
// }


pub fn main(_args: Vec<String>) -> isize {

// // Get stdout.