feat: add spellcheck highlighting support

Introduce optional spellcheck highlighting in the input window using
the Enchant-2 library.

```
/spellcheck on
/spellcheck lang en_US
```

New theme color `input.misspelled`.

Fixes: https://github.com/profanity-im/profanity/issues/183
Signed-off-by: Michael Vetter <jubalh@iodoru.org>
This commit is contained in:
Michael Vetter
2026-03-26 22:37:06 +01:00
parent 88b80c33ef
commit 4922366366
17 changed files with 335 additions and 0 deletions

View File

@@ -43,6 +43,7 @@
static char* _sub_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _theme_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _spellcheck_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _autoaway_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _autoconnect_autocomplete(ProfWin* window, const char* const input, gboolean previous);
static char* _account_autocomplete(ProfWin* window, const char* const input, gboolean previous);
@@ -138,6 +139,7 @@ static Autocomplete autoconnect_ac;
static Autocomplete wintitle_ac;
static Autocomplete theme_ac;
static Autocomplete theme_load_ac;
static Autocomplete spellcheck_ac;
static Autocomplete account_ac;
static Autocomplete account_set_ac;
static Autocomplete account_clear_ac;
@@ -298,6 +300,7 @@ static Autocomplete* all_acs[] = {
&autoconnect_ac,
&wintitle_ac,
&theme_ac,
&spellcheck_ac,
&account_ac,
&account_set_ac,
&account_clear_ac,
@@ -563,6 +566,10 @@ cmd_ac_init(void)
autocomplete_add(theme_ac, "colours");
autocomplete_add(theme_ac, "properties");
autocomplete_add(spellcheck_ac, "on");
autocomplete_add(spellcheck_ac, "off");
autocomplete_add(spellcheck_ac, "lang");
autocomplete_add(disco_ac, "info");
autocomplete_add(disco_ac, "items");
@@ -1748,6 +1755,16 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
return autocomplete_param_with_ac(input, startstr, filepath_ac, TRUE, previous);
}
static char*
_spellcheck_autocomplete(ProfWin* window, const char* const input, gboolean previous)
{
char* result = NULL;
result = autocomplete_param_with_ac(input, "/spellcheck", spellcheck_ac, TRUE, previous);
return result;
}
static char*
_cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previous)
{
@@ -1767,6 +1784,11 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
}
}
result = _spellcheck_autocomplete(window, input, previous);
if (result) {
return result;
}
// autocomplete nickname in chat rooms
if (window->type == WIN_MUC) {
ProfMucWin* mucwin = (ProfMucWin*)window;

View File

@@ -1451,6 +1451,22 @@ static const struct cmd_t command_defs[] = {
{ "on|off", "Enable or disable splash logo." })
},
{ CMD_PREAMBLE("/spellcheck",
parse_args, 1, 2, &cons_spellcheck_setting)
CMD_MAINFUNC(cmd_spellcheck)
CMD_TAGS(
CMD_TAG_UI)
CMD_SYN(
"/spellcheck on|off",
"/spellcheck lang <locale>")
CMD_DESC(
"Enable or disable spellchecking, or set the language.")
CMD_ARGS(
{ "on|off", "Enable or disable spellchecking." },
{ "list", "List available dictionaries recognized by Enchant." },
{ "lang <locale>", "Set the spellcheck language (en_US)." })
},
{ CMD_PREAMBLE("/autoconnect",
parse_args, 1, 2, &cons_autoconnect_setting)
CMD_MAINFUNC(cmd_autoconnect)

View File

@@ -54,6 +54,7 @@
#include "tools/plugin_download.h"
#include "tools/bookmark_ignore.h"
#include "tools/editor.h"
#include "tools/spellcheck.h"
#include "plugins/plugins.h"
#include "ui/inputwin.h"
#include "ui/ui.h"
@@ -6560,6 +6561,37 @@ cmd_splash(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
gboolean
cmd_spellcheck(ProfWin* window, const char* const command, gchar** args)
{
#ifdef HAVE_SPELLCHECK
if (g_strcmp0(args[0], "on") == 0) {
prefs_set_boolean(PREF_SPELLCHECK_ENABLE, TRUE);
cons_show("Spellcheck enabled.");
} else if (g_strcmp0(args[0], "off") == 0) {
prefs_set_boolean(PREF_SPELLCHECK_ENABLE, FALSE);
cons_show("Spellcheck disabled.");
} else if (g_strcmp0(args[0], "lang") == 0) {
if (args[1] == NULL) {
cons_bad_cmd_usage(command);
} else {
if (spellcheck_set_lang(args[1])) {
prefs_set_string(PREF_SPELLCHECK_LANG, args[1]);
cons_show("Spellcheck language set to: %s", args[1]);
} else {
cons_show("Failed to set spellcheck language to: %s. Is the dictionary installed?", args[1]);
}
}
} else {
cons_bad_cmd_usage(command);
}
#else
cons_show("Profanity was built without spellcheck support.");
#endif
return TRUE;
}
gboolean
cmd_autoconnect(ProfWin* window, const char* const command, gchar** args)
{

View File

@@ -103,6 +103,7 @@ gboolean cmd_bookmark_ignore(ProfWin* window, const char* const command, gchar**
gboolean cmd_roster(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_software(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_splash(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_spellcheck(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_states(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_status_get(ProfWin* window, const char* const command, gchar** args);
gboolean cmd_status_set(ProfWin* window, const char* const command, gchar** args);