Skip to content

Commit

Permalink
add es_do locale, add config action stub, make term format more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
Slackadays committed Dec 14, 2023
1 parent 744bb03 commit f69d3d7
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/cb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_executable(cb
src/externalclipboards.cpp
src/actions/add.cpp
src/actions/clear.cpp
src/actions/config.cpp
src/actions/copy.cpp
src/actions/edit.cpp
src/actions/export.cpp
Expand All @@ -26,6 +27,7 @@ add_executable(cb
src/actions/redo.cpp
src/locales/en_us.cpp
src/locales/es_co.cpp
src/locales/es_do.cpp
src/locales/pt_br.cpp
src/locales/tr_tr.cpp
src/locales/de_de.cpp
Expand Down
20 changes: 20 additions & 0 deletions src/cb/src/actions/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
#include "../clipboard.hpp"

namespace PerformAction {
void config() {}

} // namespace PerformAction
16 changes: 9 additions & 7 deletions src/cb/src/clipboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct IsTTY {
};
extern IsTTY is_tty;

enum class Action : unsigned int { Cut, Copy, Paste, Clear, Show, Edit, Add, Remove, Note, Swap, Status, Info, Load, Import, Export, History, Ignore, Search, Undo, Redo };
enum class Action : unsigned int { Cut, Copy, Paste, Clear, Show, Edit, Add, Remove, Note, Swap, Status, Info, Load, Import, Export, History, Ignore, Search, Undo, Redo, Config };

extern Action action;

Expand All @@ -232,11 +232,11 @@ class EnumArray : public std::array<T, N> {
T& original(const Action& index) { return internal_original.value()[static_cast<unsigned int>(index)]; }
};

extern EnumArray<std::string_view, 20> actions;
extern EnumArray<std::string_view, 20> action_shortcuts;
extern EnumArray<std::string_view, 20> doing_action;
extern EnumArray<std::string_view, 20> did_action;
extern EnumArray<std::string_view, 20> action_descriptions;
extern EnumArray<std::string_view, 21> actions;
extern EnumArray<std::string_view, 21> action_shortcuts;
extern EnumArray<std::string_view, 21> doing_action;
extern EnumArray<std::string_view, 21> did_action;
extern EnumArray<std::string_view, 21> action_descriptions;

extern std::array<std::pair<std::string_view, std::string_view>, 10> colors;

Expand Down Expand Up @@ -360,7 +360,8 @@ std::string makeControlCharactersVisible(const std::string_view& oldStr, size_t
unsigned long levenshteinDistance(const std::string_view& one, const std::string_view& two);
void setLanguagePT();
void setLanguageTR();
void setLanguageES();
void setLanguageES_CO();
void setLanguageES_DO();
void setLanguageDE();
void setLanguageFR();
void setupHandlers();
Expand Down Expand Up @@ -487,4 +488,5 @@ void history();
void historyJSON();
void search();
void searchJSON();
void config();
} // namespace PerformAction
23 changes: 13 additions & 10 deletions src/cb/src/locales/en_us.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
#include "../clipboard.hpp"

EnumArray<std::string_view, 20> actions = {"cut", "copy", "paste", "clear", "show", "edit", "add", "remove", "note", "swap",
"status", "info", "load", "import", "export", "history", "ignore", "search", "undo", "redo"};
EnumArray<std::string_view, 21> actions = {"cut", "copy", "paste", "clear", "show", "edit", "add", "remove", "note", "swap", "status",
"info", "load", "import", "export", "history", "ignore", "search", "undo", "redo", "config"};

EnumArray<std::string_view, 20> action_shortcuts = {"ct", "cp", "p", "clr", "sh", "ed", "ad", "rm", "nt", "sw", "st", "in", "ld", "imp", "ex", "hs", "ig", "sr", "u", "r"};
EnumArray<std::string_view, 21> action_shortcuts = {"ct", "cp", "p", "clr", "sh", "ed", "ad", "rm", "nt", "sw", "st", "in", "ld", "imp", "ex", "hs", "ig", "sr", "u", "r", "cfg"};

EnumArray<std::string_view, 20> doing_action = {"Cutting", "Copying", "Pasting", "Clearing", "Showing", "Editing", "Adding", "Removing", "Noting", "Swapping",
"Checking status", "Showing info", "Loading", "Importing", "Exporting", "Getting history", "Ignoring", "Searching", "Undoing", "Redoing"};
EnumArray<std::string_view, 21> doing_action = {"Cutting", "Copying", "Pasting", "Clearing", "Showing", "Editing", "Adding",
"Removing", "Noting", "Swapping", "Checking status", "Showing info", "Loading", "Importing",
"Exporting", "Getting history", "Ignoring", "Searching", "Undoing", "Redoing", "Checking Configuration"};

EnumArray<std::string_view, 20> did_action = {"Cut", "Copied", "Pasted", "Cleared", "Showed", "Edited", "Added", "Removed", "Noted", "Swapped", "Checked status",
"Showed info", "Loaded", "Imported", "Exported", "Got history", "Ignored", "Searched", "Undid", "Redid"};
EnumArray<std::string_view, 21> did_action = {"Cut", "Copied", "Pasted", "Cleared", "Showed", "Edited", "Added",
"Removed", "Noted", "Swapped", "Checked status", "Showed info", "Loaded", "Imported",
"Exported", "Got history", "Ignored", "Searched", "Undid", "Redid", "Checked Configuration"};

EnumArray<std::string_view, 20> action_descriptions = {
EnumArray<std::string_view, 21> action_descriptions = {
"Cut items into a clipboard.",
"Copy items into a clipboard.",
"Paste items from a clipboard.",
Expand All @@ -44,8 +46,9 @@ EnumArray<std::string_view, 20> action_descriptions = {
"Show the history of a clipboard.",
"Ignore types of content in a clipboard.",
"Search for items in a clipboard.",
"Placeholder: DO NOT USE",
"Placeholder: DO NOT USE"};
"Placeholder: Not implemented yet",
"Placeholder: Not implemented yet",
"Show the configuration of CB."};

Message help_message = "[info]โ”ƒ This is the Clipboard Project %s (commit %s), the cut, copy, and paste system for the command line.[blank]\n"
"[info][bold]โ”ƒ Examples[blank]\n"
Expand Down
2 changes: 1 addition & 1 deletion src/cb/src/locales/es_co.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

using enum Action;

void setLanguageES() {
void setLanguageES_CO() {
actions[Cut] = "cortar";
actions[Copy] = "copiar";
actions[Paste] = "pegar";
Expand Down
159 changes: 159 additions & 0 deletions src/cb/src/locales/es_do.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
#include "../clipboard.hpp"

using enum Action;

void setLanguageES_DO() {
actions[Cut] = "cortar";
actions[Copy] = "copiar";
actions[Paste] = "pegar";
actions[Clear] = "quitar";
actions[Show] = "mostrar";
actions[Edit] = "editar";
actions[Add] = "anadir";
actions[Remove] = "sacar";
actions[Note] = "notar";
actions[Swap] = "cambiar";
actions[Status] = "estado";
actions[Info] = "info";
actions[Load] = "cargar";
actions[Import] = "importar";
actions[Export] = "exportar";
actions[History] = "historia";
actions[Ignore] = "ignorar";
actions[Search] = "buscar";

action_shortcuts[Cut] = "ct";
action_shortcuts[Copy] = "cp";
action_shortcuts[Paste] = "p";
action_shortcuts[Clear] = "qt";
action_shortcuts[Show] = "ms";
action_shortcuts[Edit] = "ed";
action_shortcuts[Add] = "ad";
action_shortcuts[Remove] = "rm";
action_shortcuts[Note] = "nt";
action_shortcuts[Swap] = "cm";
action_shortcuts[Status] = "st";
action_shortcuts[Info] = "in";
action_shortcuts[Load] = "cg";
action_shortcuts[Import] = "im";
action_shortcuts[Export] = "ex";
action_shortcuts[History] = "hs";
action_shortcuts[Ignore] = "ig";
action_shortcuts[Search] = "bs";

doing_action[Cut] = "Cortando";
doing_action[Copy] = "Copiando";
doing_action[Paste] = "Pegando";
doing_action[Clear] = "Quitando";
doing_action[Show] = "Mostrando";
doing_action[Edit] = "Editando";
doing_action[Add] = "Aรฑadiendo";
doing_action[Remove] = "Sacando";
doing_action[Note] = "Notando";
doing_action[Swap] = "Cambiando";
doing_action[Status] = "Mostrando estado";
doing_action[Info] = "Mostrando informaciรณn";
doing_action[Load] = "Cargando";
doing_action[Import] = "Importando";
doing_action[Export] = "Exportando";
doing_action[History] = "Mostrando historia";
doing_action[Ignore] = "Ignorando";
doing_action[Search] = "Buscando";

did_action[Cut] = "Cortรณ";
did_action[Copy] = "Copiรณ";
did_action[Paste] = "Pegรณ";
did_action[Clear] = "Quitรณ";
did_action[Show] = "Mostrรณ";
did_action[Edit] = "Editรณ";
did_action[Add] = "Aรฑadiรณ";
did_action[Remove] = "Sacรณ";
did_action[Note] = "Notรณ";
did_action[Swap] = "Cambio";
did_action[Status] = "Mostrรณ estado";
did_action[Info] = "Mostrรณ informaciรณn";
did_action[Load] = "Cargรณ";
did_action[Import] = "Importรณ";
did_action[Export] = "Exportรณ";
did_action[History] = "Mostrรณ historia";
did_action[Ignore] = "Ignorรณ";
did_action[Search] = "Buscรณ";

action_descriptions[Cut] = "Corta un archivo o carpeta.";
action_descriptions[Copy] = "Copia un archivo o carpeta.";
action_descriptions[Paste] = "Pega un archivo o carpeta.";
action_descriptions[Clear] = "Quita un portapapeles.";
action_descriptions[Show] = "Muestra el contenido de un portapapeles.";
action_descriptions[Edit] = "Edita el contenido de un portapapeles.";
action_descriptions[Add] = "Aรฑade cosas a un portapapeles.";
action_descriptions[Remove] = "Saca cosas de un portapapeles.";
action_descriptions[Note] = "Aรฑade una nota a un portapapeles.";
action_descriptions[Swap] = "Cambia dos portapapeles.";
action_descriptions[Status] = "Muestra el estado de un portapapeles.";
action_descriptions[Info] = "Muestra informaciรณn sobre un portapapeles.";
action_descriptions[Load] = "Carga un portapapeles a otro.";
action_descriptions[Import] = "Importa un portapapeles a un archivo.";
action_descriptions[Export] = "Exporta un portapapeles a un archivo.";
action_descriptions[History] = "Muestra la historia de un portapapeles.";
action_descriptions[Ignore] = "Ignora contenido en un portapapeles.";
action_descriptions[Search] = "Busca contenido en un portapapeles.";

help_message = "[info]โ”ƒ Esto es Clipboard Project %s (commit %s), el sistema para cortar, copiar y pegar adentro del "
"terminal.[blank]\n"
"[info][bold]โ”ƒ Cรณmo usar[blank]\n"
"[progress]โ”ƒ cb cortar (cosa) [cosas][blank]\n"
"[progress]โ”ƒ cb copiar (cosa) [cosas][blank]\n"
"[progress]โ”ƒ cb pegar[blank]\n"
"[info][bold]โ”ƒ Ejemplos[blank]\n"
"[progress]โ”ƒ cb copiar cosas.conf[blank]\n"
"[progress]โ”ƒ cb cortar MisDocumentos.txt nuevacarpeta[blank]\n"
"[progress]โ”ƒ cb pegar[blank]\n"
"[info]โ”ƒ Muestra este mensaje de ayudar en cualquier tiempo que quieras con [bold]cb "
"-h[nobold], [bold]cb --help[nobold] o[bold] cb help[nobold].\n"
"[info][bold]โ”ƒ All Actions Available[blank]\n"
"%s"
"[info]โ”ƒ Copyright (C) 2023 Jackson Huff. Licensed under the GPLv3.[blank]\n"
"[info]โ”ƒ This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome "
"to redistribute it under certain conditions.[blank]\n";
no_valid_action_message = "[error][inverse] โœ˜ [noinverse] No especificaste ninguna acciรณn vรกlida o se te olvidรณ. [help]โฌค Intรฉnta usar o aรฑadir [bold]cortar, "
"copiar o pegar[nobold] en su lugar, como [bold]%s copiar.[blank]\n";
clipboard_item_many_contents_message = "[inverse][bold][info] Aquรญ estรกn las cosas primeras del "
"portapapeles [bold][help] %s[nobold] [noinverse]";
no_clipboard_contents_message = "[info]โ”ƒ No hay nada en CB en este momento.[blank]\n";
clipboard_action_prompt = "[help]Aรฑade [bold]cortar, copiar [nobold]o[bold] pegar[nobold] al final, como "
"[bold]%s copiar[nobold] para comenzar, o si necesitas ayuda, haz "
"[bold]%s -h[nobold] para mostrar el mensaje de ayudar.[blank]\n";
choose_action_items_message = "[error][inverse] โœ˜ [noinverse] Necesitas escoger una cosa para %s. [help]โฌค Intรฉnta aรฑadir las cosas que "
"quieres %s al final, como [bold]%s %s contactos.txt miprograma.cpp[blank]\n";
fix_redirection_action_message = "[error][inverse] โœ˜ [noinverse] No se puede usar la acciรณn [bold]%s[blank][error] con la redirecciรณn. [help]โฌค Intรฉnta sacar "
"[bold]%s[nobold] o usa [bold]%s[nobold] en su lugar, como [bold]%s %s[nobold].\n";
redirection_no_items_message = "[error][inverse] โœ˜ [noinverse] No se pueden especificar las cosas con redirecciรณn. [help]โฌค Intรฉnta sacar las "
"cosas que siguen [bold]%s [acciรณn].\n";
paste_success_message = "[success][inverse] โœ” [noinverse] Pegรณ con รฉxito[blank]\n";
clipboard_failed_many_message = "[error][inverse] โœ˜ [noinverse] CB no pudo %s estas cosas.[blank]\n";
and_more_fails_message = "[error][inverse] โœ˜ [noinverse] ...y [bold]%i[nobold] mรกs.[blank]\n";
and_more_items_message = "[info]โ”ƒ ...y [bold]%i[nobold] mรกs.[blank]\n";
fix_problem_message = "[help]โฌค Verรญfica si tengas los permisos necesarios, o\n"
"โ”ƒ vuelve a revisar el deletro de los archivos o la carpeta en que estรกs.[blank]\n";
not_enough_storage_message = "[error][inverse] โœ˜ [noinverse] No habrรก espacio suficiente para %s todas tus cosas (%gMB a pegar, %gMB "
"disponible). [help]โฌค Vuelve a revisar las cosas que especificaste o saca "
"algunas cosas para hacer mรกs espacio.[blank]\n";
many_files_success_message = "[success][inverse] โœ” [noinverse] %s %lu archivos[blank]\n";
many_directories_success_message = "[success][inverse] โœ” [noinverse] %s %lu carpetas[blank]\n";
many_files_many_directories_success_message = "[success][inverse] โœ” [noinverse] %s %lu archivos y %lu carpetas[blank]\n";
internal_error_message = "[error][inverse] โœ˜ [noinverse] Error internal: %s[blank]\n";
}
2 changes: 1 addition & 1 deletion src/cb/src/utils/formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ TerminalSize thisTerminalSize() {
ioctl(STDERR_FILENO, TIOCGWINSZ, &w);
temp = TerminalSize(w.ws_row, w.ws_col);
#endif
if (temp.rows >= 5 && temp.columns >= 10) return temp;
if (temp.rows >= 5 || temp.columns >= 5) return temp;
return TerminalSize(80, 24);
}

Expand Down
12 changes: 8 additions & 4 deletions src/cb/src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ void setLocale() {
locale = getenv("CLIPBOARD_LOCALE") ? getenv("CLIPBOARD_LOCALE") : std::locale("").name();
std::locale::global(std::locale(locale));
} catch (...) {}
if (locale.substr(0, 2) == "es")
setLanguageES();
if (locale.substr(0, 5) == "es_CO")
setLanguageES_CO();
else if (locale.substr(0, 2) == "es")
setLanguageES_DO();
else if (locale.substr(0, 2) == "pt")
setLanguagePT();
else if (locale.substr(0, 2) == "tr")
Expand Down Expand Up @@ -387,7 +389,7 @@ template <typename T>
Action getAction() {
using enum Action;
if (arguments.size() >= 1) {
for (const auto& entry : {Cut, Copy, Paste, Clear, Show, Edit, Add, Remove, Note, Swap, Status, Info, Load, Import, Export, History, Ignore, Search, Undo, Redo}) {
for (const auto& entry : {Cut, Copy, Paste, Clear, Show, Edit, Add, Remove, Note, Swap, Status, Info, Load, Import, Export, History, Ignore, Search, Undo, Redo, Config}) {
if (flagIsPresent<bool>(actions[entry], "--") || flagIsPresent<bool>(action_shortcuts[entry], "--") || flagIsPresent<bool>(actions.original(entry), "--")
|| flagIsPresent<bool>(action_shortcuts.original(entry), "--")) {
return entry;
Expand Down Expand Up @@ -424,7 +426,7 @@ IOType getIOType() {
if (action_is_one_of(Cut, Copy, Add)) {
if (copying.items.size() >= 1 && std::all_of(copying.items.begin(), copying.items.end(), [](const auto& item) { return !fs::exists(item); })) return Text;
if (!is_tty.in && copying.items.empty()) return Pipe;
} else if (action_is_one_of(Paste, Show, Clear, Edit, Status, Info, History, Search)) {
} else if (action_is_one_of(Paste, Show, Clear, Edit, Status, Info, History, Search, Config)) {
if (!is_tty.out) return Pipe;
return Text;
} else if (action_is_one_of(Remove, Note, Ignore, Swap, Load, Import, Export)) {
Expand Down Expand Up @@ -667,6 +669,8 @@ void performAction() {
history();
else if (action == Search)
search();
else if (action == Config)
config();
else
complainAboutMissingAction("text");
}
Expand Down

0 comments on commit f69d3d7

Please sign in to comment.