Browse Source

Improved README; all code in one file

main
Unbewohnte 3 years ago
parent
commit
5b1f170672
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 38
      README.md
  4. 14
      src/fumo.rs
  5. 27
      src/main.rs

2
Cargo.lock generated

@ -4,4 +4,4 @@ version = 3
[[package]] [[package]]
name = "fumosay" name = "fumosay"
version = "0.1.0" version = "0.1.1"

2
Cargo.toml

@ -1,6 +1,6 @@
[package] [package]
name = "fumosay" name = "fumosay"
version = "0.1.0" version = "0.1.1"
edition = "2018" edition = "2018"
authors = ["Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>"] authors = ["Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>"]
description = "Like cowsay, but with soft friends" description = "Like cowsay, but with soft friends"

38
README.md

@ -1,2 +1,40 @@
# fumosay # fumosay
## Like cowsay, but with soft friends (ᗜˬᗜ) ## Like cowsay, but with soft friends (ᗜˬᗜ)
---
## Compile
install Rust
- [installation instructions](https://www.rust-lang.org/tools/install)
clone this repository
- `git clone https://github.com/Unbewohnte/fumosay`
cd into cloned repo
- `cd fumosay/`
compile for your OS && Architecture
- `cargo build --release`
**or**
## Download a pre-compiled version
- [Download a version of your choice](https://github.com/Unbewohnte/fumosay/releases)
---
## Use
```
./fumosay [message]
```
---
## TODO list
- ❌ Add more fumos
- ❌ Make it available to use other fumos
- ❌ Improve message {box|bubble}
- ❌ Create a {deb|rpm} package
- ❌ Make an `install.sh` script

14
src/fumo.rs

@ -1,14 +0,0 @@
/// Indicator of where the message should be in fumofile
pub const MESSAGE_INDICATOR: &str = "!message";
/// Fumofile name of the default fumo
pub const FUMO_DEFAULT: &str = "fumo.fumo";
/// Returns a resulting string with `MESSAGE_INDICATOR` replaced with given
/// `message`. If `MESSAGE_INDICATOR` is not present in fumofile - the
/// `message` will be added on the new line at the end of the fumofile.
pub fn sayify(fumofile_contents: &mut String, message: &str) -> String {
if fumofile_contents.contains(MESSAGE_INDICATOR) {
return fumofile_contents.replace(MESSAGE_INDICATOR,message);
}
return format!("{}\n{}", fumofile_contents, message);
}

27
src/main.rs

@ -1,9 +1,22 @@
mod fumo;
use std::path::Path; use std::path::Path;
use std::fs; use std::fs;
use std::env; use std::env;
/// Indicator of where the message should be in fumofile
pub const MESSAGE_INDICATOR: &str = "!message";
/// Fumofile name of the default fumo
pub const FUMO_DEFAULT: &str = "fumo.fumo";
/// Returns a resulting string with `MESSAGE_INDICATOR` replaced with given
/// `message`. If `MESSAGE_INDICATOR` is not present in fumofile - the
/// `message` will be added on the new line at the end of the fumofile.
fn process_message(fumofile_contents: &mut String, message: &str) -> String {
if fumofile_contents.contains(MESSAGE_INDICATOR) {
return fumofile_contents.replace(MESSAGE_INDICATOR,message);
}
return format!("{}\n{}", fumofile_contents, message);
}
fn main() { fn main() {
// get command line arguments // get command line arguments
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
@ -14,17 +27,17 @@ fn main() {
std::process::exit(1); std::process::exit(1);
} }
let clarg_message = &args[1..].join(" "); let clarg_message: &String = &args[1..].join(" ");
// path to the fumofile // path to the fumofile
let fumofile_default_path = format!("./fumofiles/{}",fumo::FUMO_DEFAULT); let fumofile_default_path: String = format!("./fumofiles/{}",FUMO_DEFAULT);
let fumofile_path = Path::new(&fumofile_default_path); let fumofile_path: &Path = Path::new(&fumofile_default_path);
// read fumofile // read fumofile
let mut fumofile_contents = fs::read_to_string(fumofile_path).unwrap(); let mut fumofile_contents: String = fs::read_to_string(fumofile_path).unwrap();
// parse the file and get the resulting string // parse the file and get the resulting string
let message: String = fumo::sayify(&mut fumofile_contents, clarg_message); let message: String = process_message(&mut fumofile_contents, clarg_message);
println!("{}", message); println!("{}", message);
} }

Loading…
Cancel
Save