ncurses most portable keys to use - c

I use ncurs for an application which dispays data to users in real-time.
the user can do string input of normal char type. e.g a-z, A-Z 0-9 etc. So I cannot use those keys to do other things like change windows or quit.
Now it seemed like a good idea to use the F-keys but some KEY_F(x) are not recognized on some terminal emulators.
What keys are the best to use and offer the best portability for a ncurses application?

Personally I favour using one of the modifier keys with letters, it is something of a defacto standard in ncurses apps to use the letter keys with control held down for special functions.
This approach instantly gives you 26 * 2 + 9 hotkey combos for special functions, plenty for most apps.
Please take a look at gnu nano for a great example of this. Remember these may be hard to remember for new users so try and provide some kind of tool-tips or a easy to remember help button like escape or ctrl-h.

Related

Get a list of dead keys in X11

Is there a way to check for dead keys in the current layout? I am currently capturing the users input for a project I am doing. I created a map of all keys on the keyboard, but there seems to be no flag or whatsoever defining a key as dead or not. I use libxkb in my current code.
The layout is retrieved using
KeySym * keysyms = XGetKeyboardMapping(display_, keycode_low, keycode_high - keycode_low + 1, &num_keysym);
I understand you need to know which key will not directly produce a character, maybe because you are writing a game and do not want to have it use keys as input that would require another key to be pressed to produce some output (if so, please mention in the question)
Not through standard Xlib calls, to my knowledge, and definitely not without actually pressing the respective key. Composing is entirely done within Xlib, and transparent to the front end. (For its original purpose, it should be as transparent as possible to work properly, after all)
You could, however, do the same thing that Xlib does and parse through the various Compose configuration files starting with $HOME/.Xcompose. But that could be a tedious process.
On second thought, I am definitely not proposing the following:
You could, for each key you are looking for information, create a synthetic keypress event and feed it into XLookupString. Hand in an emptied XComposeStatus structure as well. If the structure returns modified, this could be a strong hint you have found a compose key. But it could also mean the server modifies it without any need..... If I were very desparate, I'd probably try.

How to detect if a text is in a given language?

I have a kind of Q&A site (very approximately) where users enter questions to be answered by our Staff. I am quite concerned about users posting non-questions, which are an annoyance. The best I thought to far is a system to detect whether the text is in Italian (our users' language), and if it is, to check if it's not a copypasta against a list of common copypastas.
So, long story short: users will input some text, I have to make sure it's a proper question in Italian and not random characters.
Not sure what language you'll make
http://www.easywayserver.com/blog/java-string-contains-example/
How do I check if a string contains a specific word in PHP?
Checking if the input String (Question) contains any forbidden word would be one way to go at it.
Pseudo code
ListOfForbiddenWords;
if Language = Italian
if Input does not contain any of ListOfForbiddenwords
//It's fine
else
//Don't spam
else
//You're not Italian
Not quite sure on what's the best way to check if a string is written in a specific language
You can use Rosoka's language detection if you want a commercial option.
You can try it out at Rosoka Cloud for about $1/hour with all of the features. The language ID is available as a stand alone library. So you can feed it examples inputs that you are concerned with to see if it gives back what you want.
Random text like "jgujqkwfjpihoujlkfa" will be flagged as ROMANIZATION or a tag based on the underlying codeblocks that where used if it is non ascii. i.e. input that is not a language will not be tagged as a language.
There are many free language detection libraries. One popular example is libexttextcat from LibreOffice. There are many clones and ports and variants if you don't want a C library; see e.g. http://odur.let.rug.nl/vannoord/TextCat/competitors.html for an (incomplete, slightly dated) list of pointers.
A similar question was asked here a while ago and the answers listed a number of language detection API solutions. One of the answers points to detectlanguage.com which offers up a limited free language detection service.

Autocompletion in joe or jed editor

I want to use joe or jed to code in C language. Any way to have autocompletion?
joe and jed are two completely different programs, but the answer is "not really" for both:
jed: theoretically yes, but practically no. The home page claims that jed is "extensible in the C-like S-Lang language making the editor completely customizable". You might be able to hack in autocompletion this way, but it'd probably be more work than learning to use a better text editor.
joe's documentation claims that you can "complete word in edit buffer by hitting ESC Enter (uses other words in buffer for dictionary)". Which is something, but it's not full autocompletion.
Ok. In the last hours I have learned the following (Only for jed):
Checking at Guido Gonzato's excellent Quick Reference Guide. we found:
Completion is the automatic expansion of partially-typed words. If
your text contains the word frobnication', typingfro' followed by
M-/ (M-X dabbrev) will either expand the whole word, or cycle amongst
all possible completions.
It works for previously typed keywords.
A better autocompletion can be obtained through complete mode. you will need:
Installing modes from Jedmodes.

WPF InkCanvas - how to determine if it has been "signed"

I'm using a WPF InkCanvas control to capture signatures in a Tablet PC application.
One of my requirements is to validate whether or not the application has really been "signed". Right now I'm doing this by checking the Strokes collection of the InkCanvas - if there are 0 strokes, then I know the user has not "signed".
However, if the user enters a single slash, or even a single dot, this counts as a stroke and my validation test will pass, even though the signature isn't really valid.
Any ideas about how to build a better test for this? Granted, the use case for what is and is not a valid signature is pretty fuzzy, but I want to try to eliminate obviously bad signatures.
Or is this simply unsolvable in any straightforward way?
I know there are algorithms to test if a signature is a valid match for an existing signature, like the one outlined here. However, finding out if something is a signature in the first place seems to be much more complex.
From Wikipedia:
On legal documents, an illiterate signatory can make a "mark" (often an "X" but occasionally a personalized symbol)
...
Several cultures whose languages use writing systems other than alphabets do not share the Western notion of signatures per se: the "signing" of one's name results in a written product no different from the result of "writing" one's name in the standard way. For these languages, to write or to sign involves the same written characters. Three such examples are Chinese, Japanese, and Korean.
While this could be approached using Intelligent Character Recognition, I also know that my signature rarely looks like it has any characters in it. It's even worse if I am using one of those UPS or FedEx package singing pads. Next time a package arrives though I will try signing with just a dash and a dot and see if it allows it (Which I think it will allow since it's already close enough to that).
Because a signature may not match any recognizable words or characters, trying to 'validate' it any further then you currently are could actually be discarding some valid signatures. If for some reason you do still need to know if there is something more then a dot, take a look at validating instead that the signature fills a certain sized rectangle. That still may invalidate results that shouldn't be, so if you do attempt to add any validation to it make sure to document fully the expectations of a valid signature.

Internationalizing Desktop App within a couple years... What should we do now?

So we are sure that we will be taking our product internationally and will eventually need to internationalize it. How much internationalizing would you recommend we do as we go along?
I guess in other words, is there any internationalization that is easy now but can be much worse if we let the code base mature and that won't slow us down very much if we choose to start doing it now?
Tech used: C#, WPF, WinForms
Prepare it now, before you write all the strings in the codebase itself.
Everything after now will be too late. It's now or never!
It's true that it is a bit of extra effort to prepare well now, but not doing it will end up being a lot more expensive.
If you won't follow all the guidelines in the links below, at least heed points 1,2 and 7 of the summary which are very cheap to do now and which cause the most pain afterwards in my experience.
Check these guidelines and see for yourself why it's better to start now and get everything prepared.
Developing world ready applications
Best practices for developing world ready applications
Little extract:
Move all localizable resources to separate resource-only DLLs. Localizable resources include user interface elements such as strings, error messages, dialog boxes, menus, and embedded object resources. (Moving the resources to a DLL afterwards will be a pain)
Do not hardcode strings or user interface resources. (If you don't prepare, you know you will hardcode strings)
Do not put nonlocalizable resources into the resource-only DLLs. This causes confusion for translators.
Do not use composite strings that are built at run time from concatenated phrases. Composite strings are difficult to localize because they often assume an English grammatical order that does not apply to all languages. (After the interface design, changing phrases gets harder)
Avoid ambiguous constructs such as "Empty Folder" where the strings can be translated differently depending on the grammatical roles of the strings' components. For example, "empty" can be either a verb or an adjective, and this can lead to different translations in languages such as Italian or French. (Same issue)
Avoid using images and icons that contain text in your application. They are expensive to localize. (Use text rendered over the image)
Allow plenty of room for the length of strings to expand in the user interface. In some languages, phrases can require 50-75 percent more space. (Same issue, if you don't plan for it now, redesign is more expensive)
Use the System.Resources.ResourceManager class to retrieve resources based on culture.
Use Microsoft Visual Studio .NET to create Windows Forms dialog boxes, so they can be localized using the Windows Forms Resource Editor (Winres.exe). Do not code Windows Forms dialog boxes by hand.
IMHO, to claim something is going to happens "in a few years" literally translates to "we hope one day" which really means "never". Although I would still skim over various tutorials to make sure you don't make any horrendous mistakes. Doing correct internationalization support now will mean less work in the future, and once you get use to it, it won't have any real affect on today's productivity. But if you can measure the goal in years, maybe it's not worth doing at all right now.
I have worked on two projects that did internationalization: a C# ASP.NET (existed before I joined the project) app and a PHP app (homebrewed my own method using a free Internationalization control and my own management app).
You should store all the text (labels, button text, etc etc) as data inside a database. Reference these with keys (I prefer to use the first 4 words, made uppercase, spaces converted to underscores and non alpha-numerics stripped out) and when you have a duplicate, append a number to the end. The benefit of this key method is the programmer has a pretty strong understanding of the content of the text just by looking at the key.
Write a utility to extract the data and build .NET resource files that you add into your project for compile. Create a separate resource file for each language. In your code, use the key to point to the proper entry.
I would skim over the MS documents on the subject:
http://www.microsoft.com/globaldev/getwr/dotneti18n.mspx
Some basic things to avoid:
never ever ever use translation software, hire a pro or an intern taking that language at a local college
never try to create text by appending two existing entries, because grammar differs greately in each language, this will never work. So if you have a string that says "Click" and want one that says "Click Now", do not try to create a setup that merges two entries, or during translation, copy the word for click and translate the word now. Treat every string as a totally new translation from scratch
I will add to store and manipulate string data as Unicode (NVARCHAR in MS SQL).
Some questions to think about…
How match can you afford to delay the shipment of the English version of your application to save a bit of cost internationalize later?
Will you still be trading if you don’t get the cash flow from shipping the English version quickly?
How will you get the UI right, if you don’t get feedback quickly from some customers about it?
How often will you rewrite the UI before you have to internationalize it?
Do you English customers wish to be able to customize strings in the UI, e.g. not everyone calls a “shipping note” the same think.
As a large part of the pain of internationalize is making sure you don’t break the English version, is automated system testing of the UI a better investment?
The only thing I think I will always do is: “Do not use composite strings that are built at run time from concatenated phrases” and if you do so, don’t spread the code that builds up the a single string over lots of methods.
Having your UI automatically resize (and layout) to cope with length of labels etc will save you lots of time over the years if you can do it cheaply. There a lots of 3rd party control sets for Windows Forms that lets you label text boxes etc without having to put the labels on as separate controls.
I just starting to internationalize a WinForms application, we hope to mostly be able to use the “name” of each control as the lookup key, without having to move lots into resource files etc. It is not always as hard as you think at first….
You could use NGettext.Wpf (it can be installed from NuGet, and yes I am the author, but I made it out of the frustrations listed in the other answers).
It is hosted this github repository, and here is the getting started section at the time of writing:
NGettext.Wpf is intended to work with dependency injection. You need to call the following at the entry point of your application:
NGettext.Wpf.CompositionRoot.Compose("ExampleDomainName");
The "ExampleDomainName" string is the domain name. This means that when the current culture is set to "da-DK" translations will be loaded from "Locale\da-DK\LC_MESSAGES\ExampleDomainName.mo" relative to where your WPF app is running (You must include the .mo files in your application and make sure they are copied to the output directory).
Now you can do something like this in XAML:
<Button CommandParameter="en-US"
Command="{StaticResource ChangeCultureCommand}"
Content="{wpf:Gettext English}" />
Which demonstrates two features of this library. The most important is the Gettext markup extension which will make sure the Content is set to the translation of "English" with respect to the current culture, and update it when the current culture is changed. The other feature it demonstrates is the ChangeCultureCommand which changes the current culture to the given culture, in this case "en-US".
I also highly recommend reading Preparing Strings from the gettext utilities manual.
Internationalization will let your product be usable in other countries, it's easy and should be done from the start (this way English speaking people all over the world can use your software), those 3 rules will get you most of the way there:
Support international characters - use only Unicode data types in files and databases.
Support international date, time and number formats - use CultureInfo.InvariantCulture when storing data to file or computer readable storage, use CultureInfo.CurrentCulture when displaying data or parsing user input, never do your own parsing, never use any other culture objects.
textual data entered by the user should be considered a black box, don't try to break it up into words or letters, especially when displaying it to the user - different languages have diffract rules and the OS knows how to display left-to-right text, you don't.
Localization is translating the software into different languages, this is difficult and expensive, a good start is to never hard code strings and never build sentences out of smaller strings.
If you use test data, use non-English (e.g.: Russian, Polish, Norwegian etc) strings.
Encoding peeks it's little ugly head at every corner. If not in your own libraries, then in external ones.
I personally favor Russian because although I don't speak a word Russian (despite my name's origin) it has foreign chars in it and it takes way more space then English and therefor tests your spacing too.
Don't know if that is something language specific, or just because our Russian translator likes verbose strings.

Resources