start of TP2 part 2
This commit is contained in:
parent
b077d79c39
commit
0575135143
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
**/Cargo.lock
|
||||
**/target/*
|
||||
**/target/*
|
||||
**/.vscode/*
|
||||
6
Session1/TP2/Text/Cargo.toml
Normal file
6
Session1/TP2/Text/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "Text"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
77
Session1/TP2/Text/src/main.rs
Normal file
77
Session1/TP2/Text/src/main.rs
Normal file
@ -0,0 +1,77 @@
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let mut run: bool = true;
|
||||
let mut file_name: String = String::new();
|
||||
let mut col_amount: i8 = 50;
|
||||
|
||||
while run {
|
||||
print!("\x1b[2J\x1b[H");
|
||||
println!("========== Justify some text ==========");
|
||||
println!(" A) Set file name (Name: {})", file_name);
|
||||
println!(" B) Set column amount between 50 and 120 (Amount: {})", col_amount);
|
||||
println!(" C) Justify and print text");
|
||||
println!(" D) Justify and save text");
|
||||
println!(" Quit (any other key)");
|
||||
|
||||
let mut choice: String = String::new();
|
||||
print!("Your choice: ");
|
||||
let _ = io::stdout().flush();
|
||||
io::stdin()
|
||||
.read_line(&mut choice)
|
||||
.expect("Failed to read from stdin");
|
||||
choice = choice.trim().to_ascii_lowercase().to_string();
|
||||
|
||||
match choice.as_str() {
|
||||
"a" => {
|
||||
file_name = set_file_name();
|
||||
}
|
||||
"b" => {
|
||||
col_amount = set_col_amount();
|
||||
}
|
||||
"c" => {
|
||||
print_justified_text();
|
||||
}
|
||||
"d" => {
|
||||
save_justified_text();
|
||||
}
|
||||
_ => {
|
||||
run = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_file_name() -> String {
|
||||
let mut path_iscorrect: bool = false;
|
||||
let mut path: String = String::new();
|
||||
|
||||
while !path_iscorrect {
|
||||
path = String::new();
|
||||
print!("Enter the desired file's path: ");
|
||||
let _ = io::stdout().flush();
|
||||
io::stdin()
|
||||
.read_line(&mut path)
|
||||
.expect("Failed to read from stdin");
|
||||
path = path.trim().to_string();
|
||||
|
||||
if Path::new(&path).exists() {
|
||||
path_iscorrect = true;
|
||||
} else {
|
||||
println!("The specified file does not exist. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
fn set_col_amount() -> i8 {
|
||||
8
|
||||
}
|
||||
|
||||
fn print_justified_text() {}
|
||||
|
||||
fn save_justified_text() {}
|
||||
|
||||
fn load_justify_text() {}
|
||||
Loading…
x
Reference in New Issue
Block a user