Compare commits

..

20 Commits
0.1.1 ... main

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

3
.gitignore vendored

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

7
Cargo.lock generated

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

12
Cargo.toml

@ -1,12 +0,0 @@
[package]
name = "fumosay"
version = "0.1.1"
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]

4
LICENSE

@ -1,6 +1,4 @@
The MIT License (MIT) Copyright © 2021 Kasyanov Nikolay Alexeevich (Unbewohnte (me@unbewohnte.xyz))
Copyright © 2021 Unbewohne | Nikolay Kasyanov
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: 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

70
README.md

@ -1,41 +1,75 @@
# fumosay # fumosay
## Like cowsay, but with soft friends (ᗜˬᗜ) ## Like cowsay, but with soft friends (ᗜˬᗜ)
```
__ __ <⑨ There are no buses in Gensokyo ⑨>
| \ / | ()
| \____/ | ()
|__// V \\__|
/|| ᗜ ᗜ || \
\_\\_︶_//_/
jj⑨lll
()_/@V@V@V\_()
/@V@V@V@V\
(_)-----(_)
```
--- ---
## Compile # Installation
install Rust
- [installation instructions](https://www.rust-lang.org/tools/install)
## "Compile it yourself" way
clone this repository clone this repository
- `git clone https://github.com/Unbewohnte/fumosay` - `git clone http://unbewohnte.xyz:3000/Unbewohnte/fumosay`
cd into cloned repo cd into cloned repo
- `cd fumosay/` - `cd fumosay/`
compile for your OS && Architecture compile
- `cargo build --release` - `make` or `g++ -static -O2 src/fumosay.cpp -o fumosay`
**or** **or**
## Download a pre-compiled version ## "Download a pre-compiled version (Linux amd64 only)" way
- [Download a version of your choice](https://github.com/Unbewohnte/fumosay/releases) - [Download a version of your choice](http://unbewohnte.xyz:3000/Unbewohnte/fumosay/releases)
unzip
- `unzip [zip_archive_name]`
cd into unzipped directory
- `cd fumosay/`
## After compilation|downloading
run installation script
- `chmod +x install.sh && sudo ./install.sh` or `sudo make install`
**Now you have fumosay installed !**
--- ---
## Use # 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
``` ```
./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 - Add more fumos
- ❌ Make it available to use other fumos - ~~Make it possible to use other fumos~~
- ❌ Improve message {box|bubble} - Improve message {box|bubble}
- ❌ Embed fumofiles or take care of ways of locating them - ~~Embed fumofiles or take care of ways of locating them~~
- ❌ Create a {deb|rpm} package - ~~Make an `install.sh` script~~
- ❌ Make an `install.sh` script

5
fumofiles/fumo.fumo → fumofiles/cirno.fumo

@ -1,10 +1,11 @@
__ __ <!message> <!message>
__ __ ()
| \ / | () | \ / | ()
| \____/ | () | \____/ | ()
|__// V \\__| |__// V \\__|
/|| ᗜ ᗜ || \ /|| ᗜ ᗜ || \
\_\\_︶_//_/ \_\\_︶_//_/
jjGlll jjlll
()_/@V@V@V\_() ()_/@V@V@V\_()
/@V@V@V@V\ /@V@V@V@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;
}

45
src/main.rs

@ -1,45 +0,0 @@
use std::path::Path;
use std::fs;
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() {
// get command line arguments
let args: Vec<String> = env::args().collect();
// try to retrieve a message from args
if args.len() <= 1 {
// no message was provided
std::process::exit(1);
}
let clarg_message: &String = &args[1..].join(" ");
// path to the fumofile
let fumofile_default_path: String = format!("./fumofiles/{}",FUMO_DEFAULT);
let fumofile_path: &Path = Path::new(&fumofile_default_path);
// read fumofile
let mut fumofile_contents: String = fs::read_to_string(fumofile_path).unwrap();
// parse the file and get the resulting string
let message: String = process_message(&mut fumofile_contents, clarg_message);
println!("{}", message);
}
Loading…
Cancel
Save