Keep It Simple, Stupid | |
PerlMonks |
Re^6: word auto-corrector in Curses::UIby shmem (Chancellor) |
on Jan 09, 2021 at 15:10 UTC ( [id://11126657]=note: print w/replies, xml ) | Need Help?? |
How I could create an auto-correcting text-editor application? You tried to integrate Term::Complete into your curses UI, but that's not about auto-correction. First thing you have to do is get the snippet of text which has to be examined as e.g. $candidate:
This will give you information to STDERR about the current word under the cursor at every keystroke. You can build a list of completion candidates based on that word, or check the spelling with e.g. the aspell library. Based on that word, you could decide wether adding a <Tab> to the text, or attempt completion. You could mark misspelled words in terms of Term::ANSIColor or such, do completion with either Term::Complete or Term::ReadLine::Gnu (with both you have to shoehorn the results into your $editor widget) - or just do your own completion routine with Curses::UI using Curses::UI::Listbox to display possible completions. Way to go yet...PS: why? are you trying to re-implement vi or emacs in perl? ;) PS2: "Find and Replace" comes first in functionality, then more sophisticated things like (auto-)completion and spellcheck.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|