Compare commits
No commits in common. 'main' and '0.1.1' have entirely different histories.
11 changed files with 92 additions and 243 deletions
@ -0,0 +1,7 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
version = 3 |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "fumosay" |
||||||
|
version = "0.1.1" |
@ -0,0 +1,12 @@ |
|||||||
|
[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] |
@ -1,17 +0,0 @@ |
|||||||
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
|
|
@ -1,75 +1,41 @@ |
|||||||
# 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\ |
|
||||||
(_)-----(_) |
|
||||||
``` |
|
||||||
--- |
--- |
||||||
|
|
||||||
# Installation |
## Compile |
||||||
|
install Rust |
||||||
|
- [installation instructions](https://www.rust-lang.org/tools/install) |
||||||
|
|
||||||
## "Compile it yourself" way |
|
||||||
clone this repository |
clone this repository |
||||||
- `git clone http://unbewohnte.xyz:3000/Unbewohnte/fumosay` |
- `git clone https://github.com/Unbewohnte/fumosay` |
||||||
|
|
||||||
cd into cloned repo |
cd into cloned repo |
||||||
- `cd fumosay/` |
- `cd fumosay/` |
||||||
|
|
||||||
compile |
compile for your OS && Architecture |
||||||
- `make` or `g++ -static -O2 src/fumosay.cpp -o fumosay` |
- `cargo build --release` |
||||||
|
|
||||||
|
|
||||||
**or** |
**or** |
||||||
|
|
||||||
## "Download a pre-compiled version (Linux amd64 only)" way |
## Download a pre-compiled version |
||||||
- [Download a version of your choice](http://unbewohnte.xyz:3000/Unbewohnte/fumosay/releases) |
- [Download a version of your choice](https://github.com/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 -d path/to/your/fumofiles/ -f your_fumo.fumo fumofumo |
./fumosay [message] |
||||||
``` |
``` |
||||||
uses a non-default path to fumofiles and a custom fumofile |
|
||||||
|
|
||||||
--- |
--- |
||||||
|
|
||||||
# TODO list |
## TODO list |
||||||
|
|
||||||
- Add more fumos |
- ❌ Add more fumos |
||||||
- ~~Make it possible to use other fumos~~ |
- ❌ Make it available 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 |
||||||
- ~~Make an `install.sh` script~~ |
- ❌ Create a {deb|rpm} package |
||||||
|
- ❌ Make an `install.sh` script |
||||||
|
@ -1,11 +1,10 @@ |
|||||||
<!message> |
__ __ <!message> |
||||||
__ __ () |
|
||||||
| \ / | () |
| \ / | () |
||||||
| \____/ | () |
| \____/ | () |
||||||
|__// V \\__| |
|__// V \\__| |
||||||
/|| ᗜ ᗜ || \ |
/|| ᗜ ᗜ || \ |
||||||
\_\\_︶_//_/ |
\_\\_︶_//_/ |
||||||
jj⑨lll |
jjGlll |
||||||
()_/@V@V@V\_() |
()_/@V@V@V\_() |
||||||
/@V@V@V@V\ |
/@V@V@V@V\ |
||||||
(_)-----(_) |
(_)-----(_) |
@ -1,26 +0,0 @@ |
|||||||
#!/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 |
|
@ -1,136 +0,0 @@ |
|||||||
/*
|
|
||||||
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; |
|
||||||
} |
|
@ -0,0 +1,45 @@ |
|||||||
|
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…
Reference in new issue