Initial commit

This commit is contained in:
Thomas Forgione 2019-07-12 15:23:03 +02:00
commit 2f3751f968
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
7 changed files with 89 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

6
Cargo.lock generated Normal file
View File

@ -0,0 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "tfetch"
version = "0.1.0"

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "tfetch"
version = "0.1.0"
authors = ["Thomas Forgione <thomas@forgione.fr>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

19
src/lib.rs Normal file
View File

@ -0,0 +1,19 @@
pub mod logos;
pub enum Os {
ArchLinux,
}
impl Os {
pub fn ascii_logo(self) -> &'static str {
match self {
Os::ArchLinux => logos::archlinux::ASCII_LOGO,
}
}
pub fn name(self) -> &'static str {
match self {
Os::ArchLinux => "Arch Linux",
}
}
}

20
src/logos/archlinux.rs Normal file
View File

@ -0,0 +1,20 @@
pub const ASCII_LOGO: &'static str = " \x1B[36;1m-`\x1B[0m \
\n \x1B[36;1m.o+`\x1B[0m \
\n \x1B[36;1m`ooo/\x1B[0m \
\n \x1B[36;1m`+oooo:\x1B[0m \
\n \x1B[36;1m`+oooooo:\x1B[0m \
\n \x1B[36;1m-+oooooo+:\x1B[0m \
\n \x1B[36;1m`/:-:++oooo+:\x1B[0m \
\n \x1B[36;1m`/++++/+++++++:\x1B[0m \
\n \x1B[36;1m`/++++++++++++++:\x1B[0m \
\n \x1B[36;1m`/+++o\x1B[0;36moooooooo\x1B[1moooo/`\x1B[0m \
\n \x1B[36;1m./\x1B[0;36mooosssso++osssssso\x1B[1m+`\x1B[0m \
\n \x1B[36m.oossssso-````/ossssss+`\x1B[0m \
\n \x1B[36m-osssssso. :ssssssso.\x1B[0m \
\n \x1B[36m:osssssss/ osssso+++.\x1B[0m \
\n \x1B[36m/ossssssss/ +ssssooo/-\x1B[0m \
\n \x1B[36m`/ossssso+/:- -:/+osssso+-\x1B[0m \
\n \x1B[36m`+sso+:-` `.-/+oso:\x1B[0m \
\n\x1B[36m`++:. `-/+/\x1B[0m\
\n\x1B[36m.` `/\x1B[0m";

1
src/logos/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod archlinux;

32
src/main.rs Normal file
View File

@ -0,0 +1,32 @@
use std::env::var;
use std::fs::File;
use std::io::Read;
use tfetch::Os;
pub fn main() {
let mut hostname = String::new();
let mut hostname_file = File::open("/etc/hostname").unwrap();
hostname_file.read_to_string(&mut hostname).unwrap();
let username = format!("\x1B[36;1m{}\x1B[0m@\x1B[36;1m{}\x1B[0m", var("USER").unwrap(), hostname);
let osname = format!("\x1B[36;1mOS:\x1B[0m {}\n", Os::ArchLinux.name());
let info = [
String::from("\n"),
username,
osname,
];
let mut logo_iterator = Os::ArchLinux.ascii_logo().lines();
let mut info_iterator = info.iter();
loop {
match (logo_iterator.next(), info_iterator.next()) {
(Some(logo), Some(info)) => print!("{} {}", logo, info),
(Some(logo), None) => println!("{}", logo),
_ => break,
}
}
}