Compare commits

...

18 Commits
0.2.0 ... main

  1. 3
      .gitignore
  2. 115
      Cargo.lock
  3. 13
      Cargo.toml
  4. 4
      LICENSE
  5. 17
      Makefile
  6. 57
      README.md
  7. 3
      fumofiles/cirno.fumo
  8. 4
      fumofiles/mini.fumo
  9. 26
      install.sh
  10. 136
      src/fumosay.cpp
  11. 65
      src/main.rs

3
.gitignore vendored

@ -1,3 +1,2 @@
/target
.cargo/
releasefiles/
fumosay

115
Cargo.lock generated

@ -1,115 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "clap"
version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "fumosay"
version = "0.2.0"
dependencies = [
"clap",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

13
Cargo.toml

@ -1,13 +0,0 @@
[package]
name = "fumosay"
version = "0.2.0"
edition = "2018"
authors = ["Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>"]
description = "Like cowsay, but with soft friends"
readme = "README.md"
license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "~2.33.3"

4
LICENSE

@ -1,6 +1,4 @@
The MIT License (MIT)
Copyright © 2021 Unbewohne | Nikolay Kasyanov
Copyright © 2021 Kasyanov Nikolay Alexeevich (Unbewohnte (me@unbewohnte.xyz))
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

17
Makefile

@ -0,0 +1,17 @@
SRC_DIR := src
FUMOSAY_BIN_NAME := fumosay
FUMOFILES := fumofiles
FUMOSAY_INSTALLATION_DIR := /usr/local/bin
FUMOFILES_DST_DIR := /usr/local/share/fumosay
all:
g++ -O2 -Wall -Werror -static src/fumosay.cpp -o fumosay
install: all
mkdir -p $(FUMOSAY_INSTALLATION_DIR) && \
mkdir -p $(FUMOSAY_INSTALLATION_DIR) && \
cp -r $(FUMOFILES) $(FUMOFILES_DST_DIR) && \
cp $(FUMOSAY_BIN_NAME) $(FUMOSAY_INSTALLATION_DIR)
clean:
rm fumosay

57
README.md

@ -16,53 +16,60 @@
# Installation
## Compile it yourself
install Rust
- [installation instructions](https://www.rust-lang.org/tools/install)
## "Compile it yourself" way
clone this repository
- `git clone https://github.com/Unbewohnte/fumosay`
- `git clone http://unbewohnte.xyz:3000/Unbewohnte/fumosay`
cd into cloned repo
- `cd fumosay/`
compile for your OS && Architecture
- `cargo build --release`
compile
- `make` or `g++ -static -O2 src/fumosay.cpp -o fumosay`
**or**
## Download a pre-compiled version (only amd64 Linux and Windows)
- [Download a version of your choice](https://github.com/Unbewohnte/fumosay/releases)
## "Download a pre-compiled version (Linux amd64 only)" way
- [Download a version of your choice](http://unbewohnte.xyz:3000/Unbewohnte/fumosay/releases)
## After compilation|downloading
unzip
- `unzip [zip_archive_name]`
create a directory where the program will 'sit'
- `mkdir $HOME/fumosay`
cd into unzipped directory
- `cd fumosay/`
retrieve the executable and fumofiles and move them there
- `mv fumosay/target/release/fumo $HOME/fumosay/ && mv fumofiles $HOME/fumosay`
## After compilation|downloading
run installation script
- `chmod +x install.sh && sudo ./install.sh` or `sudo make install`
**Now you have fumosay installed !**
The next possible step would probably be to add this directory to the $PATH environment variable.
---
# Use
```
fumosay message_here
```
prints a message with a default fumo.fumo template
---
```
fumosay -f mini.fumo message_here
```
prints a message with a mini.fumo template. You can add your own fumofiles
in /usr/local/share/fumosay/fumofiles/ and use them with -f flag
## Use
```
./fumosay [message]
fumosay -d path/to/your/fumofiles/ -f your_fumo.fumo fumofumo
```
uses a non-default path to fumofiles and a custom fumofile
---
## TODO list
# TODO list
- ❌ Add more fumos
- ❌ Make it possible to use other fumos
- ❌ Improve message {box|bubble}
- somewhat ✅ Embed fumofiles or take care of ways of locating them
- ❌ Create a {deb|rpm} package
- ❌ Make an `install.sh` script
- Add more fumos
- ~~Make it possible to use other fumos~~
- Improve message {box|bubble}
- ~~Embed fumofiles or take care of ways of locating them~~
- ~~Make an `install.sh` script~~

3
fumofiles/fumo.fumo → fumofiles/cirno.fumo

@ -1,4 +1,5 @@
__ __ <!message>
<!message>
__ __ ()
| \ / | ()
| \____/ | ()
|__// V \\__|

4
fumofiles/mini.fumo

@ -0,0 +1,4 @@
<!message>
\
\
(ᗜˬᗜ)

26
install.sh

@ -0,0 +1,26 @@
#!/bin/bash
# fumosay installation script
FUMOSAY_BIN_DIR_PATH=/usr/local/bin/
FUMOFILES_DIR_PATH=/usr/local/share/fumosay/fumofiles/
# create directories
mkdir -p $FUMOSAY_BIN_DIR_PATH && mkdir -p $FUMOFILES_DIR_PATH
# copy fumosay binary
if [ -e fumosay ]
then
cp fumosay $FUMOSAY_BIN_DIR_PATH
else
echo "Could not find fumosay in current directory"
exit 1
fi
# copy fumofiles
if [ -d fumofiles ]
then
cp -r fumofiles/* $FUMOFILES_DIR_PATH
else
echo "Could not find fumofiles directory"
exit 1
fi

136
src/fumosay.cpp

@ -0,0 +1,136 @@
/*
Copyright © 2021, 2022 Kasyanov Nikolay Alexeyevich (Unbewohntes)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string.h>
#include <iostream>
#include <fstream>
#include <filesystem>
class Fumo {
private:
const std::string m_message_identificator = "!message";
const std::string m_default_fumofile = "cirno.fumo";
std::string m_fumotext;
public:
// Opens specified fumofile
Fumo(std::string fumo_path) {
std::fstream m_fumofile;
m_fumofile.open(fumo_path, std::ios_base::in);
if (!m_fumofile) {
throw "Could not open fumofile";
};
// read whole fumofile
std::string line;
while (std::getline(m_fumofile, line)) {
m_fumotext += line + "\n";
};
m_fumofile.close();
};
~Fumo() {};
// Inserts given message and prints it to the standart output
void say(std::string message) {
if (m_fumotext.find(m_message_identificator) == std::string::npos) {
// no identificator found. Inserting message on the first line
m_fumotext.insert(0, message + "\n");
} else {
// identificator found. Inserting message in the appropriate place
const unsigned int message_index = m_fumotext.find(m_message_identificator);
m_fumotext.replace(message_index, m_message_identificator.length(), message);
};
// print fumosay
std::cout << m_fumotext << std::endl;
};
};
int main(int argc, char *argv[]) {
const std::string VERSION = "0.4.5";
const std::string ABOUT = "\
fumosay\n\
cowsay, but with soft friends\n\n\
(c) Kasyanov Nikolay Alexeyevich (Unbewohnte)";
const std::string HELP = "\
fumosay [OPTION(s)...] [MESSAGE]\n\n\
Options:\n\
-v --version - print version text and exit\n\
-l --list - list available fumos and exit\n\
-h --help - print this message and exit\n\
-f --fumo - specify path to another fumo to print\n";
std::string fumofiles_dir;
#ifdef _WIN32
fumofiles_dir = ".\\fumofiles";
#else
fumofiles_dir = "/usr/local/share/fumosay/fumofiles";
#endif
std::string fumoname = "cirno.fumo";
if (argc < 2) {
return 0;
};
std::string message;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
// print version info
std::cout << VERSION << std::endl << std::endl << ABOUT << std::endl;
return 0;
}
else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--list") == 0) {
// print available fumos in the default fumofiles directory
for (const auto &entry : std::filesystem::directory_iterator(fumofiles_dir)) {
std::cout << entry.path().filename() << std::endl;
};
return 0;
}
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
// print help infos
std::cout << HELP << std::endl;
return 0;
}
else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--fumo") == 0) {
// use another fumo
if (i+1 >= argc-1) {
return 1;
};
fumoname = argv[i+1];
i++;
}
else if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--directory") == 0) {
// temporarily change fumofiles directory to look fumofiles in
if (i+1 >= argc-1 || !std::filesystem::exists(std::filesystem::path(argv[i+1]))){
return 1;
};
fumofiles_dir = argv[i+1];
i++;
}
else {
message += argv[i];
if (i != argc-1) {
message += " ";
};
}
};
Fumo fumo(std::filesystem::path(fumofiles_dir) / fumoname);
fumo.say(message);
return 0;
}

65
src/main.rs

@ -1,65 +0,0 @@
use std::fs;
use std::env;
use clap::{Arg, App};
/// 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() {
// get command line arguments
let matches = App::new("fumosay")
.version("0.2.0")
.author("Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>")
.about("cowsay, but with soft friends")
.arg(
Arg::with_name("fumo")
.short("f")
.long("fumo")
.value_name("fumofile")
.help("choose another fumofumo to print")
.takes_value(true)
.required(false))
.arg(
Arg::with_name("message")
.short("m")
.long("message")
.help("set a message to print")
.takes_value(true)
.required(true)
.index(1)
.multiple(true)
).get_matches();
// default path to the fumofile
// grab path to exe
let executable_path = env::current_exe().expect("Could not get current exe`s path!");
// remove the last bit (exe filename)
let executable_dir = executable_path.parent().expect("Could not get exe`s parent directory !");
// local path to the default fumofile
let fumofile_default_path = std::path::Path::new("fumofiles").join(FUMO_DEFAULT);
// add them together
let fumofile_path = executable_dir.join(fumofile_default_path);
// read fumofile
let mut fumofile_contents: String = fs::read_to_string(fumofile_path).expect("Could not find a fumofile!");
// parse the file and get the resulting string
let message: String = process_message(&mut fumofile_contents, matches.value_of("message").unwrap());
println!("{}", message);
}
Loading…
Cancel
Save