Compare commits

..

No commits in common. 'main' and '0.4.4' have entirely different histories.
main ... 0.4.4

  1. 75
      README.md
  2. 76
      src/fumosay.cpp

75
README.md

@ -1,75 +0,0 @@
# fumosay
## Like cowsay, but with soft friends (ᗜˬᗜ)
```
__ __ <⑨ There are no buses in Gensokyo ⑨>
| \ / | ()
| \____/ | ()
|__// V \\__|
/|| ᗜ ᗜ || \
\_\\_︶_//_/
jj⑨lll
()_/@V@V@V\_()
/@V@V@V@V\
(_)-----(_)
```
---
# Installation
## "Compile it yourself" way
clone this repository
- `git clone http://unbewohnte.xyz:3000/Unbewohnte/fumosay`
cd into cloned repo
- `cd fumosay/`
compile
- `make` or `g++ -static -O2 src/fumosay.cpp -o fumosay`
**or**
## "Download a pre-compiled version (Linux amd64 only)" way
- [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
```
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
```
uses a non-default path to fumofiles and a custom fumofile
---
# TODO list
- 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~~

76
src/fumosay.cpp

@ -1,5 +1,5 @@
/* /*
Copyright © 2021, 2022 Kasyanov Nikolay Alexeyevich (Unbewohntes) 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: 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:
@ -21,15 +21,24 @@ class Fumo {
std::string m_fumotext; std::string m_fumotext;
public: public:
// Opens specified fumofile // Opens specified fumofile if present and reads it
Fumo(std::string fumo_path) { Fumo(std::string fumofile, std::string fumofiles_path) {
std::string path = fumofiles_path + "/" + fumofile;
std::fstream m_fumofile; std::fstream m_fumofile;
m_fumofile.open(fumo_path, std::ios_base::in); m_fumofile.open(path, std::ios_base::in);
if (!m_fumofile) {
// could not open specified fumofile
// try to open the default one
path = fumofiles_path + "/" + m_default_fumofile;
m_fumofile.open(path, std::ios_base::in);
if (!m_fumofile) { if (!m_fumofile) {
// if THIS didn`t help - raise an error
throw "Could not open fumofile"; throw "Could not open fumofile";
}; };
};
// read whole fumofile // read the whole fumofile
std::string line; std::string line;
while (std::getline(m_fumofile, line)) { while (std::getline(m_fumofile, line)) {
m_fumotext += line + "\n"; m_fumotext += line + "\n";
@ -40,7 +49,7 @@ class Fumo {
~Fumo() {}; ~Fumo() {};
// Inserts given message and prints it to the standart output // parses already present fumotext and inserts given message. Prints fumosay
void say(std::string message) { void say(std::string message) {
if (m_fumotext.find(m_message_identificator) == std::string::npos) { if (m_fumotext.find(m_message_identificator) == std::string::npos) {
// no identificator found. Inserting message on the first line // no identificator found. Inserting message on the first line
@ -57,27 +66,12 @@ class Fumo {
}; };
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
const std::string VERSION = "0.4.5"; const std::string VERSION = "0.4.4";
const std::string ABOUT = "fumosay\ncowsay, but with soft friends\n\nWritten by Kasyanov Nikolay Alexeevich (Unbewohnte (me@unbewohnte.xyz))";
const std::string ABOUT = "\ const std::string HELP = "fumosay [OPTION(s)...] [MESSAGE]\n\nOptions:\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 another fumo to print\n-d --directory - temporarily change fumofiles directory to look fumofiles in\n";
fumosay\n\
cowsay, but with soft friends\n\n\
(c) Kasyanov Nikolay Alexeyevich (Unbewohnte)"; std::string fumofiles_dir = "/usr/local/share/fumosay/fumofiles";
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"; std::string fumoname = "cirno.fumo";
if (argc < 2) { if (argc < 2) {
@ -90,20 +84,21 @@ Options:\n\
// print version info // print version info
std::cout << VERSION << std::endl << std::endl << ABOUT << std::endl; std::cout << VERSION << std::endl << std::endl << ABOUT << std::endl;
return 0; return 0;
}
else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--list") == 0) { } else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--list") == 0) {
// print available fumos in the default fumofiles directory // print available fumos in the default fumofiles directory
for (const auto &entry : std::filesystem::directory_iterator(fumofiles_dir)) { for (const auto &entry : std::filesystem::directory_iterator(fumofiles_dir)) {
std::cout << entry.path().filename() << std::endl; std::cout << entry.path().filename() << std::endl;
}; };
return 0; return 0;
}
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
// print help infos // print help infos
std::cout << HELP << std::endl; std::cout << HELP << std::endl;
return 0; return 0;
}
else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--fumo") == 0) { } else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--fumo") == 0) {
// use another fumo // use another fumo
if (i+1 >= argc-1) { if (i+1 >= argc-1) {
return 1; return 1;
@ -111,8 +106,10 @@ Options:\n\
fumoname = argv[i+1]; fumoname = argv[i+1];
i++; i++;
}
else if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--directory") == 0) { continue;
} else if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--directory") == 0) {
// temporarily change fumofiles directory to look fumofiles in // temporarily change fumofiles directory to look fumofiles in
if (i+1 >= argc-1 || !std::filesystem::exists(std::filesystem::path(argv[i+1]))){ if (i+1 >= argc-1 || !std::filesystem::exists(std::filesystem::path(argv[i+1]))){
return 1; return 1;
@ -120,16 +117,17 @@ Options:\n\
fumofiles_dir = argv[i+1]; fumofiles_dir = argv[i+1];
i++; i++;
}
else { continue;
};
message += argv[i]; message += argv[i];
if (i != argc-1) { if (i != argc-1) {
message += " "; message += " ";
}; };
}
}; };
Fumo fumo(std::filesystem::path(fumofiles_dir) / fumoname); Fumo fumo(fumoname, fumofiles_dir);
fumo.say(message); fumo.say(message);
return 0; return 0;

Loading…
Cancel
Save